Commit e5740a51 authored by Gerald Squelart's avatar Gerald Squelart
Browse files

Bug 1721569 - Also compile Gecko Profiler gtest files in non-MOZ_GECKO_PROFILER builds - r=florian

parent 2e518a78
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -113,9 +113,6 @@ if CONFIG["MOZ_GECKO_PROFILER"]:
            "/toolkit/crashreporter/google-breakpad/src/common/android/include",
        ]

    if CONFIG["ENABLE_TESTS"]:
        DIRS += ["tests/gtest"]

    if CONFIG["MOZ_VTUNE"]:
        DEFINES["MOZ_VTUNE_INSTRUMENTATION"] = True
        UNIFIED_SOURCES += [
@@ -172,6 +169,9 @@ CONFIGURE_SUBST_FILES += [

FINAL_LIBRARY = "xul"

if CONFIG["ENABLE_TESTS"]:
    DIRS += ["tests/gtest"]

if CONFIG["CC_TYPE"] in ("clang", "gcc"):
    CXXFLAGS += [
        "-Wno-error=shadow",
+149 −134
Original line number Diff line number Diff line
@@ -9,6 +9,14 @@
// happens when calling these functions. They don't do much inspection of
// profiler internals.

#include "mozilla/ProfilerUtils.h"

#include "gtest/gtest.h"

#include <thread>

#ifdef MOZ_GECKO_PROFILER

#  include "GeckoProfiler.h"
#  include "mozilla/ProfilerMarkerTypes.h"
#  include "mozilla/ProfilerMarkers.h"
@@ -32,11 +40,10 @@
#  include "nsIThread.h"
#  include "nsThreadUtils.h"

#include "gtest/gtest.h"

#  include <cstring>
#  include <set>
#include <thread>

#endif  // MOZ_GECKO_PROFILER

// Note: profiler_init() has already been called in XRE_main(), so we can't
// test it here. Likewise for profiler_shutdown(), and AutoProfilerInit
@@ -88,6 +95,8 @@ TEST(GeckoProfiler, ProfilerUtils)
#endif
}

#ifdef MOZ_GECKO_PROFILER

TEST(BaseProfiler, BlocksRingBuffer)
{
  constexpr uint32_t MBSize = 256;
@@ -137,7 +146,8 @@ TEST(BaseProfiler, BlocksRingBuffer)
#  define EXPECT_HAS_JSON(GETTER, TYPE)              \
    do {                                             \
      if ((GETTER).isNull()) {                       \
      EXPECT_FALSE((GETTER).isNull()) << #GETTER " doesn't exist or is null"; \
        EXPECT_FALSE((GETTER).isNull())              \
            << #GETTER " doesn't exist or is null";  \
      } else if (!(GETTER).is##TYPE()) {             \
        EXPECT_TRUE((GETTER).is##TYPE())             \
            << #GETTER " didn't return type " #TYPE; \
@@ -162,7 +172,8 @@ TEST(BaseProfiler, BlocksRingBuffer)
#  define EXPECT_EQ_JSON(GETTER, TYPE, VALUE)        \
    do {                                             \
      if ((GETTER).isNull()) {                       \
      EXPECT_FALSE((GETTER).isNull()) << #GETTER " doesn't exist or is null"; \
        EXPECT_FALSE((GETTER).isNull())              \
            << #GETTER " doesn't exist or is null";  \
      } else if (!(GETTER).is##TYPE()) {             \
        EXPECT_TRUE((GETTER).is##TYPE())             \
            << #GETTER " didn't return type " #TYPE; \
@@ -176,7 +187,8 @@ TEST(BaseProfiler, BlocksRingBuffer)
#  define EXPECT_EQ_STRINGTABLE(GETTER, STRINGTABLE, STRING)                 \
    do {                                                                     \
      if ((GETTER).isNull()) {                                               \
      EXPECT_FALSE((GETTER).isNull()) << #GETTER " doesn't exist or is null"; \
        EXPECT_FALSE((GETTER).isNull())                                      \
            << #GETTER " doesn't exist or is null";                          \
      } else if (!(GETTER).isUInt()) {                                       \
        EXPECT_TRUE((GETTER).isUInt()) << #GETTER " didn't return an index"; \
      } else {                                                               \
@@ -188,7 +200,8 @@ TEST(BaseProfiler, BlocksRingBuffer)
#  define EXPECT_JSON_ARRAY_CONTAINS(GETTER, TYPE, VALUE)                     \
    do {                                                                      \
      if ((GETTER).isNull()) {                                                \
      EXPECT_FALSE((GETTER).isNull()) << #GETTER " doesn't exist or is null"; \
        EXPECT_FALSE((GETTER).isNull())                                       \
            << #GETTER " doesn't exist or is null";                           \
      } else if (!(GETTER).isArray()) {                                       \
        EXPECT_TRUE((GETTER).is##TYPE()) << #GETTER " is not an array";       \
      } else if (const Json::ArrayIndex size = (GETTER).size(); size == 0u) { \
@@ -2542,8 +2555,8 @@ TEST(GeckoProfiler, CPUUsage)
        {
          EXPECT_EQ_JSON(sampleUnits["time"], String, "ms");
          EXPECT_EQ_JSON(sampleUnits["eventDelay"], String, "ms");
#if defined(GP_OS_windows) || defined(GP_OS_darwin) || defined(GP_OS_linux) || \
    defined(GP_OS_android) || defined(GP_OS_freebsd)
#  if defined(GP_OS_windows) || defined(GP_OS_darwin) || \
      defined(GP_OS_linux) || defined(GP_OS_android) || defined(GP_OS_freebsd)
          // Note: The exact string is not important here.
          EXPECT_TRUE(sampleUnits["threadCPUDelta"].isString())
              << "There should be a sampleUnits.threadCPUDelta on this "
@@ -2608,8 +2621,8 @@ TEST(GeckoProfiler, CPUUsage)
              EXPECT_GE(stackLeaves.size(), scSampleLabelCount);
            }

#if defined(GP_OS_windows) || defined(GP_OS_darwin) || defined(GP_OS_linux) || \
    defined(GP_OS_android) || defined(GP_OS_freebsd)
#  if defined(GP_OS_windows) || defined(GP_OS_darwin) || \
      defined(GP_OS_linux) || defined(GP_OS_android) || defined(GP_OS_freebsd)
            EXPECT_GE(threadCPUDeltaCount, data.size() - 1u)
                << "There should be 'threadCPUDelta' values in all but 1 "
                   "samples";
@@ -2634,3 +2647,5 @@ TEST(GeckoProfiler, CPUUsage)
        [&](SamplingState) { ASSERT_TRUE(false); }));
  }
}

#endif  // MOZ_GECKO_PROFILER
+10 −6
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifdef MOZ_GECKO_PROFILER

#  include "ProfileBuffer.h"
#  include "ThreadInfo.h"

@@ -55,3 +57,5 @@ TEST(ThreadProfile, InsertEntriesNoWrap)
  }
  ASSERT_EQ(test_size, times);
}

#endif  // MOZ_GECKO_PROFILER
+10 −5
Original line number Diff line number Diff line
@@ -4,11 +4,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at http://mozilla.org/MPL/2.0/.

if CONFIG["OS_TARGET"] in ("Android", "Linux") and CONFIG["CPU_ARCH"] in (
if (
    CONFIG["MOZ_GECKO_PROFILER"]
    and CONFIG["OS_TARGET"] in ("Android", "Linux")
    and CONFIG["CPU_ARCH"]
    in (
        "arm",
        "aarch64",
        "x86",
        "x86_64",
    )
):
    UNIFIED_SOURCES += [
        "LulTest.cpp",