Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "gtest/gtest.h" |
michael@0 | 7 | #include "LulMain.h" |
michael@0 | 8 | #include "GeckoProfiler.h" // for TracingMetadata |
michael@0 | 9 | #include "UnwinderThread2.h" // for read_procmaps |
michael@0 | 10 | |
michael@0 | 11 | // Set this to 0 to make LUL be completely silent during tests. |
michael@0 | 12 | // Set it to 1 to get logging output from LUL, presumably for |
michael@0 | 13 | // the purpose of debugging it. |
michael@0 | 14 | #define DEBUG_LUL_TEST 0 |
michael@0 | 15 | |
michael@0 | 16 | // LUL needs a callback for its logging sink. |
michael@0 | 17 | static void |
michael@0 | 18 | logging_sink_for_LUL(const char* str) { |
michael@0 | 19 | if (DEBUG_LUL_TEST == 0) { |
michael@0 | 20 | return; |
michael@0 | 21 | } |
michael@0 | 22 | // Ignore any trailing \n, since LOG will add one anyway. |
michael@0 | 23 | size_t n = strlen(str); |
michael@0 | 24 | if (n > 0 && str[n-1] == '\n') { |
michael@0 | 25 | char* tmp = strdup(str); |
michael@0 | 26 | tmp[n-1] = 0; |
michael@0 | 27 | fprintf(stderr, "LUL-in-gtest: %s\n", tmp); |
michael@0 | 28 | free(tmp); |
michael@0 | 29 | } else { |
michael@0 | 30 | fprintf(stderr, "LUL-in-gtest: %s\n", str); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | TEST(LUL, unwind_consistency) { |
michael@0 | 35 | // Set up LUL and get it to read unwind info for libxul.so, which is |
michael@0 | 36 | // all we care about here, plus (incidentally) practically every |
michael@0 | 37 | // other object in the process too. |
michael@0 | 38 | lul::LUL* lul = new lul::LUL(logging_sink_for_LUL); |
michael@0 | 39 | lul->RegisterUnwinderThread(); |
michael@0 | 40 | read_procmaps(lul); |
michael@0 | 41 | |
michael@0 | 42 | // Run unwind tests and receive information about how many there |
michael@0 | 43 | // were and how many were successful. |
michael@0 | 44 | int nTests = 0, nTestsPassed = 0; |
michael@0 | 45 | RunLulUnitTests(&nTests, &nTestsPassed, lul); |
michael@0 | 46 | EXPECT_TRUE(nTests == 6) << "Unexpected number of tests"; |
michael@0 | 47 | EXPECT_TRUE(nTestsPassed == nTests) << "Not all tests passed"; |
michael@0 | 48 | |
michael@0 | 49 | delete lul; |
michael@0 | 50 | } |