Bug 1321617 - Add a test for profiler_stream_json_for_this_process. r?njn
MozReview-Commit-ID: A5Iu3dQFvHK
--- a/tools/profiler/tests/gtest/GeckoProfiler.cpp
+++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp
@@ -11,16 +11,17 @@
#include "gtest/gtest.h"
#include "GeckoProfiler.h"
#include "ProfilerMarkers.h"
#include "jsapi.h"
#include "js/Initialization.h"
#include "mozilla/UniquePtrExtensions.h"
+#include "ProfileJSONWriter.h"
#include <string.h>
// Note: profiler_init() has already been called in XRE_main(), so we can't
// test it here. Likewise for profiler_shutdown(), and GeckoProfilerInitRAII
// (which is just an RAII wrapper for profiler_init() and profiler_shutdown()).
using namespace mozilla;
@@ -348,16 +349,40 @@ TEST(GeckoProfiler, GetProfile)
UniquePtr<char[]> profile = profiler_get_profile();
ASSERT_TRUE(profile && profile[0] == '{');
profiler_stop();
ASSERT_TRUE(!profiler_get_profile());
}
+TEST(GeckoProfiler, StreamJSONForThisProcess)
+{
+ const char* features[] = { "stackwalk" };
+ const char* filters[] = { "GeckoMain" };
+
+ SpliceableChunkedJSONWriter w;
+ ASSERT_TRUE(!profiler_stream_json_for_this_process(w));
+
+ profiler_start(PROFILE_DEFAULT_ENTRIES, PROFILE_DEFAULT_INTERVAL,
+ features, MOZ_ARRAY_LENGTH(features),
+ filters, MOZ_ARRAY_LENGTH(filters));
+
+ w.Start(SpliceableJSONWriter::SingleLineStyle);
+ ASSERT_TRUE(profiler_stream_json_for_this_process(w));
+ w.End();
+
+ UniquePtr<char[]> profile = w.WriteFunc()->CopyData();
+ ASSERT_TRUE(profile && profile[0] == '{');
+
+ profiler_stop();
+
+ ASSERT_TRUE(!profiler_stream_json_for_this_process(w));
+}
+
TEST(GeckoProfiler, PseudoStack)
{
const char* features[] = { "stackwalk" };
const char* filters[] = { "GeckoMain" };
PROFILER_LABEL("A", "B", js::ProfileEntry::Category::OTHER);
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);