Commit f215daa8 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

Reland "Reland "[test] Move tracing cctest to unittests""

This is a reland of commit 3b251deb

Annotates the perfetto proto include with nogncheck, because gn's header
checker doesn't understand preprocessor directives.

See
https://gn.googlesource.com/gn/+/main/docs/reference.md#advice-on-fixing-problems

Original change's description:
> Reland "[test] Move tracing cctest to unittests"
>
> This is a reland of a7d6bf96
>
> Added perfetto to unittests include_rules.
>
> Bug: v8:12781
> Change-Id: Iabf0e62abb1de879de21ba06fbd38f5432ee4f76
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3652295
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Leszek Swirski <leszeks@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#80847}

Bug: v8:12781
Change-Id: I886df9254d8fecd56f64110f04b1447937605b58
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3680299
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80866}
parent d5d3ecae
...@@ -159,7 +159,6 @@ v8_source_set("cctest_sources") { ...@@ -159,7 +159,6 @@ v8_source_set("cctest_sources") {
"interpreter/test-interpreter-intrinsics.cc", "interpreter/test-interpreter-intrinsics.cc",
"interpreter/test-interpreter.cc", "interpreter/test-interpreter.cc",
"interpreter/test-source-positions.cc", "interpreter/test-source-positions.cc",
"libplatform/test-tracing.cc",
"manually-externalized-buffer.h", "manually-externalized-buffer.h",
"parsing/test-preparser.cc", "parsing/test-preparser.cc",
"print-extension.cc", "print-extension.cc",
......
include_rules = [
"+protos/perfetto",
]
...@@ -389,6 +389,7 @@ v8_source_set("unittests_sources") { ...@@ -389,6 +389,7 @@ v8_source_set("unittests_sources") {
"libplatform/default-worker-threads-task-runner-unittest.cc", "libplatform/default-worker-threads-task-runner-unittest.cc",
"libplatform/single-threaded-default-platform-unittest.cc", "libplatform/single-threaded-default-platform-unittest.cc",
"libplatform/task-queue-unittest.cc", "libplatform/task-queue-unittest.cc",
"libplatform/tracing-unittest.cc",
"libplatform/worker-thread-unittest.cc", "libplatform/worker-thread-unittest.cc",
"libsampler/sampler-unittest.cc", "libsampler/sampler-unittest.cc",
"libsampler/signals-and-mutexes-unittest.cc", "libsampler/signals-and-mutexes-unittest.cc",
......
include_rules = [ include_rules = [
"+perfetto",
"+protos/perfetto",
"+src", "+src",
"+testing" "+testing"
] ]
specific_include_rules = {
"tracing-unittest\.cc": [
"+perfetto/tracing.h",
"+protos/perfetto"
],
}
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/libplatform/default-platform.h" #include "src/libplatform/default-platform.h"
#include "src/tracing/trace-event.h" #include "src/tracing/trace-event.h"
#include "test/cctest/cctest.h" #include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#ifdef V8_USE_PERFETTO #ifdef V8_USE_PERFETTO
#include "perfetto/tracing.h" #include "perfetto/tracing.h"
#include "protos/perfetto/trace/trace.pb.h" #include "protos/perfetto/trace/trace.pb.h" // nogncheck
#include "src/libplatform/tracing/trace-event-listener.h" #include "src/libplatform/tracing/trace-event-listener.h"
#include "src/tracing/traced-value.h" #include "src/tracing/traced-value.h"
#endif // V8_USE_PERFETTO #endif // V8_USE_PERFETTO
...@@ -20,8 +21,9 @@ namespace v8 { ...@@ -20,8 +21,9 @@ namespace v8 {
namespace platform { namespace platform {
namespace tracing { namespace tracing {
TEST(TestTraceConfig) { class PlatformTracingTest : public TestWithPlatform {};
LocalContext env;
TEST_F(PlatformTracingTest, TestTraceConfig) {
TraceConfig* trace_config = new TraceConfig(); TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8"); trace_config->AddIncludedCategory("v8");
trace_config->AddIncludedCategory(TRACE_DISABLED_BY_DEFAULT("v8.runtime")); trace_config->AddIncludedCategory(TRACE_DISABLED_BY_DEFAULT("v8.runtime"));
...@@ -44,7 +46,7 @@ TEST(TestTraceConfig) { ...@@ -44,7 +46,7 @@ TEST(TestTraceConfig) {
// Perfetto doesn't use TraceObject. // Perfetto doesn't use TraceObject.
#if !defined(V8_USE_PERFETTO) #if !defined(V8_USE_PERFETTO)
TEST(TestTraceObject) { TEST_F(PlatformTracingTest, TestTraceObject) {
TraceObject trace_object; TraceObject trace_object;
uint8_t category_enabled_flag = 41; uint8_t category_enabled_flag = 41;
trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", trace_object.Initialize('X', &category_enabled_flag, "Test.Trace",
...@@ -91,7 +93,7 @@ class MockTraceWriter : public TraceWriter { ...@@ -91,7 +93,7 @@ class MockTraceWriter : public TraceWriter {
// Perfetto doesn't use the ring buffer. // Perfetto doesn't use the ring buffer.
#if !defined(V8_USE_PERFETTO) #if !defined(V8_USE_PERFETTO)
TEST(TestTraceBufferRingBuffer) { TEST_F(PlatformTracingTest, TestTraceBufferRingBuffer) {
// We should be able to add kChunkSize * 2 + 1 trace events. // We should be able to add kChunkSize * 2 + 1 trace events.
const int HANDLES_COUNT = TraceBufferChunk::kChunkSize * 2 + 1; const int HANDLES_COUNT = TraceBufferChunk::kChunkSize * 2 + 1;
MockTraceWriter* writer = new MockTraceWriter(); MockTraceWriter* writer = new MockTraceWriter();
...@@ -177,7 +179,7 @@ void PopulateJSONWriter(TraceWriter* writer) { ...@@ -177,7 +179,7 @@ void PopulateJSONWriter(TraceWriter* writer) {
i::V8::SetPlatformForTesting(old_platform); i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestJSONTraceWriter) { TEST_F(PlatformTracingTest, TestJSONTraceWriter) {
std::ostringstream stream; std::ostringstream stream;
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream); TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
PopulateJSONWriter(writer); PopulateJSONWriter(writer);
...@@ -193,7 +195,7 @@ TEST(TestJSONTraceWriter) { ...@@ -193,7 +195,7 @@ TEST(TestJSONTraceWriter) {
CHECK_EQ(expected_trace_str, trace_str); CHECK_EQ(expected_trace_str, trace_str);
} }
TEST(TestJSONTraceWriterWithCustomtag) { TEST_F(PlatformTracingTest, TestJSONTraceWriterWithCustomtag) {
std::ostringstream stream; std::ostringstream stream;
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream, "customTag"); TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream, "customTag");
PopulateJSONWriter(writer); PopulateJSONWriter(writer);
...@@ -226,7 +228,7 @@ void GetJSONStrings(std::vector<std::string>* ret, const std::string& str, ...@@ -226,7 +228,7 @@ void GetJSONStrings(std::vector<std::string>* ret, const std::string& str,
// With Perfetto the tracing controller doesn't observe events. // With Perfetto the tracing controller doesn't observe events.
#if !defined(V8_USE_PERFETTO) #if !defined(V8_USE_PERFETTO)
TEST(TestTracingController) { TEST_F(PlatformTracingTest, TestTracingController) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform( std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform()); v8::platform::NewDefaultPlatform());
...@@ -258,7 +260,7 @@ TEST(TestTracingController) { ...@@ -258,7 +260,7 @@ TEST(TestTracingController) {
i::V8::SetPlatformForTesting(old_platform); i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestTracingControllerMultipleArgsAndCopy) { TEST_F(PlatformTracingTest, TestTracingControllerMultipleArgsAndCopy) {
std::ostringstream stream, perfetto_stream; std::ostringstream stream, perfetto_stream;
uint64_t aa = 11; uint64_t aa = 11;
unsigned int bb = 22; unsigned int bb = 22;
...@@ -400,7 +402,7 @@ class TraceStateObserverImpl : public TracingController::TraceStateObserver { ...@@ -400,7 +402,7 @@ class TraceStateObserverImpl : public TracingController::TraceStateObserver {
} // namespace } // namespace
TEST(TracingObservers) { TEST_F(PlatformTracingTest, TracingObservers) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform( std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform()); v8::platform::NewDefaultPlatform());
...@@ -495,7 +497,7 @@ class TraceWritingThread : public base::Thread { ...@@ -495,7 +497,7 @@ class TraceWritingThread : public base::Thread {
v8::platform::tracing::TracingController* tracing_controller_; v8::platform::tracing::TracingController* tracing_controller_;
}; };
TEST(AddTraceEventMultiThreaded) { TEST_F(PlatformTracingTest, AddTraceEventMultiThreaded) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform( std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform()); v8::platform::NewDefaultPlatform());
...@@ -677,7 +679,7 @@ class TracingTestHarness { ...@@ -677,7 +679,7 @@ class TracingTestHarness {
std::ostringstream perfetto_json_stream_; std::ostringstream perfetto_json_stream_;
}; };
TEST(Perfetto) { TEST_F(PlatformTracingTest, Perfetto) {
TracingTestHarness harness; TracingTestHarness harness;
harness.StartTracing(); harness.StartTracing();
...@@ -704,7 +706,7 @@ TEST(Perfetto) { ...@@ -704,7 +706,7 @@ TEST(Perfetto) {
} }
// Replacement for 'TestTracingController' // Replacement for 'TestTracingController'
TEST(Categories) { TEST_F(PlatformTracingTest, Categories) {
TracingTestHarness harness; TracingTestHarness harness;
harness.StartTracing(); harness.StartTracing();
...@@ -725,7 +727,7 @@ TEST(Categories) { ...@@ -725,7 +727,7 @@ TEST(Categories) {
} }
// Replacement for 'TestTracingControllerMultipleArgsAndCopy' // Replacement for 'TestTracingControllerMultipleArgsAndCopy'
TEST(MultipleArgsAndCopy) { TEST_F(PlatformTracingTest, MultipleArgsAndCopy) {
uint64_t aa = 11; uint64_t aa = 11;
unsigned int bb = 22; unsigned int bb = 22;
uint16_t cc = 33; uint16_t cc = 33;
...@@ -834,7 +836,7 @@ TEST(MultipleArgsAndCopy) { ...@@ -834,7 +836,7 @@ TEST(MultipleArgsAndCopy) {
for (size_t i = 0; i < 20; i++) CHECK_EQ("E:.", harness.get_event(24 + i)); for (size_t i = 0; i < 20; i++) CHECK_EQ("E:.", harness.get_event(24 + i));
} }
TEST(JsonIntegrationTest) { TEST_F(PlatformTracingTest, JsonIntegrationTest) {
// Check that tricky values are rendered correctly in the JSON output. // Check that tricky values are rendered correctly in the JSON output.
double big_num = 1e100; double big_num = 1e100;
double nan_num = std::numeric_limits<double>::quiet_NaN(); double nan_num = std::numeric_limits<double>::quiet_NaN();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment