/src/mozilla-central/tools/profiler/tests/gtest/LulTest.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "gtest/gtest.h" |
7 | | #include "mozilla/Atomics.h" |
8 | | #include "LulMain.h" |
9 | | #include "GeckoProfiler.h" // for TracingKind |
10 | | #include "platform-linux-lul.h" // for read_procmaps |
11 | | |
12 | | // Set this to 0 to make LUL be completely silent during tests. |
13 | | // Set it to 1 to get logging output from LUL, presumably for |
14 | | // the purpose of debugging it. |
15 | 0 | #define DEBUG_LUL_TEST 0 |
16 | | |
17 | | // LUL needs a callback for its logging sink. |
18 | | static void |
19 | 0 | gtest_logging_sink_for_LulIntegration(const char* str) { |
20 | 0 | if (DEBUG_LUL_TEST == 0) { |
21 | 0 | return; |
22 | 0 | } |
23 | 0 | // Ignore any trailing \n, since LOG will add one anyway. |
24 | 0 | size_t n = strlen(str); |
25 | 0 | if (n > 0 && str[n-1] == '\n') { |
26 | 0 | char* tmp = strdup(str); |
27 | 0 | tmp[n-1] = 0; |
28 | 0 | fprintf(stderr, "LUL-in-gtest: %s\n", tmp); |
29 | 0 | free(tmp); |
30 | 0 | } else { |
31 | 0 | fprintf(stderr, "LUL-in-gtest: %s\n", str); |
32 | 0 | } |
33 | 0 | } |
34 | | |
35 | 0 | TEST(LulIntegration, unwind_consistency) { |
36 | 0 | // Set up LUL and get it to read unwind info for libxul.so, which is |
37 | 0 | // all we care about here, plus (incidentally) practically every |
38 | 0 | // other object in the process too. |
39 | 0 | lul::LUL* lul = new lul::LUL(gtest_logging_sink_for_LulIntegration); |
40 | 0 | read_procmaps(lul); |
41 | 0 |
|
42 | 0 | // Run unwind tests and receive information about how many there |
43 | 0 | // were and how many were successful. |
44 | 0 | lul->EnableUnwinding(); |
45 | 0 | int nTests = 0, nTestsPassed = 0; |
46 | 0 | RunLulUnitTests(&nTests, &nTestsPassed, lul); |
47 | 0 | EXPECT_TRUE(nTests == 6) << "Unexpected number of tests"; |
48 | 0 | EXPECT_TRUE(nTestsPassed == nTests) << "Not all tests passed"; |
49 | 0 |
|
50 | 0 | delete lul; |
51 | 0 | } |