michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gtest/gtest.h" michael@0: #include "LulMain.h" michael@0: #include "GeckoProfiler.h" // for TracingMetadata michael@0: #include "UnwinderThread2.h" // for read_procmaps michael@0: michael@0: // Set this to 0 to make LUL be completely silent during tests. michael@0: // Set it to 1 to get logging output from LUL, presumably for michael@0: // the purpose of debugging it. michael@0: #define DEBUG_LUL_TEST 0 michael@0: michael@0: // LUL needs a callback for its logging sink. michael@0: static void michael@0: logging_sink_for_LUL(const char* str) { michael@0: if (DEBUG_LUL_TEST == 0) { michael@0: return; michael@0: } michael@0: // Ignore any trailing \n, since LOG will add one anyway. michael@0: size_t n = strlen(str); michael@0: if (n > 0 && str[n-1] == '\n') { michael@0: char* tmp = strdup(str); michael@0: tmp[n-1] = 0; michael@0: fprintf(stderr, "LUL-in-gtest: %s\n", tmp); michael@0: free(tmp); michael@0: } else { michael@0: fprintf(stderr, "LUL-in-gtest: %s\n", str); michael@0: } michael@0: } michael@0: michael@0: TEST(LUL, unwind_consistency) { michael@0: // Set up LUL and get it to read unwind info for libxul.so, which is michael@0: // all we care about here, plus (incidentally) practically every michael@0: // other object in the process too. michael@0: lul::LUL* lul = new lul::LUL(logging_sink_for_LUL); michael@0: lul->RegisterUnwinderThread(); michael@0: read_procmaps(lul); michael@0: michael@0: // Run unwind tests and receive information about how many there michael@0: // were and how many were successful. michael@0: int nTests = 0, nTestsPassed = 0; michael@0: RunLulUnitTests(&nTests, &nTestsPassed, lul); michael@0: EXPECT_TRUE(nTests == 6) << "Unexpected number of tests"; michael@0: EXPECT_TRUE(nTestsPassed == nTests) << "Not all tests passed"; michael@0: michael@0: delete lul; michael@0: }