tools/profiler/tests/gtest/LulTest.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/tests/gtest/LulTest.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "gtest/gtest.h"
    1.10 +#include "LulMain.h"
    1.11 +#include "GeckoProfiler.h"     // for TracingMetadata
    1.12 +#include "UnwinderThread2.h"   // for read_procmaps
    1.13 +
    1.14 +// Set this to 0 to make LUL be completely silent during tests.
    1.15 +// Set it to 1 to get logging output from LUL, presumably for
    1.16 +// the purpose of debugging it.
    1.17 +#define DEBUG_LUL_TEST 0
    1.18 +
    1.19 +// LUL needs a callback for its logging sink.
    1.20 +static void
    1.21 +logging_sink_for_LUL(const char* str) {
    1.22 +  if (DEBUG_LUL_TEST == 0) {
    1.23 +    return;
    1.24 +  }
    1.25 +  // Ignore any trailing \n, since LOG will add one anyway.
    1.26 +  size_t n = strlen(str);
    1.27 +  if (n > 0 && str[n-1] == '\n') {
    1.28 +    char* tmp = strdup(str);
    1.29 +    tmp[n-1] = 0;
    1.30 +    fprintf(stderr, "LUL-in-gtest: %s\n", tmp);
    1.31 +    free(tmp);
    1.32 +  } else {
    1.33 +    fprintf(stderr, "LUL-in-gtest: %s\n", str);
    1.34 +  }
    1.35 +}
    1.36 +
    1.37 +TEST(LUL, unwind_consistency) {
    1.38 +  // Set up LUL and get it to read unwind info for libxul.so, which is
    1.39 +  // all we care about here, plus (incidentally) practically every
    1.40 +  // other object in the process too.
    1.41 +  lul::LUL* lul = new lul::LUL(logging_sink_for_LUL);
    1.42 +  lul->RegisterUnwinderThread();
    1.43 +  read_procmaps(lul);
    1.44 +
    1.45 +  // Run unwind tests and receive information about how many there
    1.46 +  // were and how many were successful.
    1.47 +  int nTests = 0, nTestsPassed = 0;
    1.48 +  RunLulUnitTests(&nTests, &nTestsPassed, lul);
    1.49 +  EXPECT_TRUE(nTests == 6) << "Unexpected number of tests";
    1.50 +  EXPECT_TRUE(nTestsPassed == nTests) << "Not all tests passed";
    1.51 +
    1.52 +  delete lul;
    1.53 +}

mercurial