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