Commit bad7b827 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Clean up trace event tests by removing macros

The macros take implicit local arguments and make the tests harder to
read. Remove the macros and add a helper to get size directly given
this is the only use of the helper that returns the whole list.

Remove the typedef of vector of trace events, because it is only used
in two places now and is also called 'list' not vector.

Use unique pointers for the ownership of MockTraceObject.

Change-Id: Iec495c436cf7326224137321a84035c817622eaa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1538131Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60443}
parent 19dcbec8
......@@ -6,14 +6,12 @@
#include "src/v8.h"
#include "src/base/template-utils.h"
#include "test/cctest/cctest.h"
#include "src/tracing/trace-event.h"
#define GET_TRACE_OBJECTS_LIST platform.GetMockTraceObjects()
#define GET_TRACE_OBJECT(Index) GET_TRACE_OBJECTS_LIST->at(Index)
namespace {
struct MockTraceObject {
char phase;
......@@ -34,17 +32,9 @@ struct MockTraceObject {
timestamp(timestamp) {}
};
typedef std::vector<MockTraceObject*> MockTraceObjectList;
class MockTracingController : public v8::TracingController {
public:
MockTracingController() = default;
~MockTracingController() override {
for (size_t i = 0; i < trace_object_list_.size(); ++i) {
delete trace_object_list_[i];
}
trace_object_list_.clear();
}
uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
......@@ -65,9 +55,10 @@ class MockTracingController : public v8::TracingController {
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags, int64_t timestamp) override {
MockTraceObject* to = new MockTraceObject(
phase, std::string(name), id, bind_id, num_args, flags, timestamp);
trace_object_list_.push_back(to);
std::unique_ptr<MockTraceObject> to =
v8::base::make_unique<MockTraceObject>(
phase, std::string(name), id, bind_id, num_args, flags, timestamp);
trace_objects_.push_back(std::move(to));
return 0;
}
......@@ -84,10 +75,13 @@ class MockTracingController : public v8::TracingController {
}
}
MockTraceObjectList* GetMockTraceObjects() { return &trace_object_list_; }
const std::vector<std::unique_ptr<MockTraceObject>>& GetMockTraceObjects()
const {
return trace_objects_;
}
private:
MockTraceObjectList trace_object_list_;
std::vector<std::unique_ptr<MockTraceObject>> trace_objects_;
DISALLOW_COPY_AND_ASSIGN(MockTracingController);
};
......@@ -104,14 +98,19 @@ class MockTracingPlatform : public TestPlatform {
return &tracing_controller_;
}
MockTraceObjectList* GetMockTraceObjects() {
return tracing_controller_.GetMockTraceObjects();
size_t NumberOfTraceObjects() {
return tracing_controller_.GetMockTraceObjects().size();
}
MockTraceObject* GetTraceObject(size_t index) {
return tracing_controller_.GetMockTraceObjects().at(index).get();
}
private:
MockTracingController tracing_controller_;
};
} // namespace
TEST(TraceEventDisabledCategory) {
MockTracingPlatform platform;
......@@ -119,10 +118,9 @@ TEST(TraceEventDisabledCategory) {
// Disabled category, will not add events.
TRACE_EVENT_BEGIN0("cat", "e1");
TRACE_EVENT_END0("cat", "e1");
CHECK(GET_TRACE_OBJECTS_LIST->empty());
CHECK_EQ(0, platform.NumberOfTraceObjects());
}
TEST(TraceEventNoArgs) {
MockTracingPlatform platform;
......@@ -130,17 +128,16 @@ TEST(TraceEventNoArgs) {
TRACE_EVENT_BEGIN0("v8-cat", "e1");
TRACE_EVENT_END0("v8-cat", "e1");
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ('B', GET_TRACE_OBJECT(0)->phase);
CHECK_EQ("e1", GET_TRACE_OBJECT(0)->name);
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(2, platform.NumberOfTraceObjects());
CHECK_EQ('B', platform.GetTraceObject(0)->phase);
CHECK_EQ("e1", platform.GetTraceObject(0)->name);
CHECK_EQ(0, platform.GetTraceObject(0)->num_args);
CHECK_EQ('E', GET_TRACE_OBJECT(1)->phase);
CHECK_EQ("e1", GET_TRACE_OBJECT(1)->name);
CHECK_EQ(0, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ('E', platform.GetTraceObject(1)->phase);
CHECK_EQ("e1", platform.GetTraceObject(1)->name);
CHECK_EQ(0, platform.GetTraceObject(1)->num_args);
}
TEST(TraceEventWithOneArg) {
MockTracingPlatform platform;
......@@ -149,15 +146,14 @@ TEST(TraceEventWithOneArg) {
TRACE_EVENT_BEGIN1("v8-cat", "e2", "arg1", "abc");
TRACE_EVENT_END1("v8-cat", "e2", "arg1", "abc");
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(4, platform.NumberOfTraceObjects());
CHECK_EQ(1, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(3)->num_args);
CHECK_EQ(1, platform.GetTraceObject(0)->num_args);
CHECK_EQ(1, platform.GetTraceObject(1)->num_args);
CHECK_EQ(1, platform.GetTraceObject(2)->num_args);
CHECK_EQ(1, platform.GetTraceObject(3)->num_args);
}
TEST(TraceEventWithTwoArgs) {
MockTracingPlatform platform;
......@@ -166,35 +162,33 @@ TEST(TraceEventWithTwoArgs) {
TRACE_EVENT_BEGIN2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
TRACE_EVENT_END2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(4, platform.NumberOfTraceObjects());
CHECK_EQ(2, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(3)->num_args);
CHECK_EQ(2, platform.GetTraceObject(0)->num_args);
CHECK_EQ(2, platform.GetTraceObject(1)->num_args);
CHECK_EQ(2, platform.GetTraceObject(2)->num_args);
CHECK_EQ(2, platform.GetTraceObject(3)->num_args);
}
TEST(ScopedTraceEvent) {
MockTracingPlatform platform;
{ TRACE_EVENT0("v8-cat", "e"); }
CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(1, platform.NumberOfTraceObjects());
CHECK_EQ(0, platform.GetTraceObject(0)->num_args);
{ TRACE_EVENT1("v8-cat", "e1", "arg1", "abc"); }
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(2, platform.NumberOfTraceObjects());
CHECK_EQ(1, platform.GetTraceObject(1)->num_args);
{ TRACE_EVENT2("v8-cat", "e1", "arg1", "abc", "arg2", 42); }
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(3, platform.NumberOfTraceObjects());
CHECK_EQ(2, platform.GetTraceObject(2)->num_args);
}
TEST(TestEventWithFlow) {
MockTracingPlatform platform;
......@@ -209,17 +203,16 @@ TEST(TestEventWithFlow) {
}
{ TRACE_EVENT_WITH_FLOW0("v8-cat", "f3", bind_id, TRACE_EVENT_FLAG_FLOW_IN); }
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(bind_id, GET_TRACE_OBJECT(0)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_OUT, GET_TRACE_OBJECT(0)->flags);
CHECK_EQ(bind_id, GET_TRACE_OBJECT(1)->bind_id);
CHECK_EQ(3, platform.NumberOfTraceObjects());
CHECK_EQ(bind_id, platform.GetTraceObject(0)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_OUT, platform.GetTraceObject(0)->flags);
CHECK_EQ(bind_id, platform.GetTraceObject(1)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
GET_TRACE_OBJECT(1)->flags);
CHECK_EQ(bind_id, GET_TRACE_OBJECT(2)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, GET_TRACE_OBJECT(2)->flags);
platform.GetTraceObject(1)->flags);
CHECK_EQ(bind_id, platform.GetTraceObject(2)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, platform.GetTraceObject(2)->flags);
}
TEST(TestEventWithId) {
MockTracingPlatform platform;
......@@ -227,11 +220,11 @@ TEST(TestEventWithId) {
TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id);
TRACE_EVENT_ASYNC_END0("v8-cat", "a1", event_id);
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_BEGIN, GET_TRACE_OBJECT(0)->phase);
CHECK_EQ(event_id, GET_TRACE_OBJECT(0)->id);
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, GET_TRACE_OBJECT(1)->phase);
CHECK_EQ(event_id, GET_TRACE_OBJECT(1)->id);
CHECK_EQ(2, platform.NumberOfTraceObjects());
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_BEGIN, platform.GetTraceObject(0)->phase);
CHECK_EQ(event_id, platform.GetTraceObject(0)->id);
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, platform.GetTraceObject(1)->phase);
CHECK_EQ(event_id, platform.GetTraceObject(1)->id);
}
TEST(TestEventWithTimestamp) {
......@@ -248,19 +241,19 @@ TEST(TestEventWithTimestamp) {
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0("v8-cat", "end", 5,
32832);
CHECK_EQ(5, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(5, platform.NumberOfTraceObjects());
CHECK_EQ(1729, GET_TRACE_OBJECT(0)->timestamp);
CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(1729, platform.GetTraceObject(0)->timestamp);
CHECK_EQ(0, platform.GetTraceObject(0)->num_args);
CHECK_EQ(4104, GET_TRACE_OBJECT(1)->timestamp);
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(4104, platform.GetTraceObject(1)->timestamp);
CHECK_EQ(1, platform.GetTraceObject(1)->num_args);
CHECK_EQ(13832, GET_TRACE_OBJECT(2)->timestamp);
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(13832, platform.GetTraceObject(2)->timestamp);
CHECK_EQ(2, platform.GetTraceObject(2)->num_args);
CHECK_EQ(20683, GET_TRACE_OBJECT(3)->timestamp);
CHECK_EQ(32832, GET_TRACE_OBJECT(4)->timestamp);
CHECK_EQ(20683, platform.GetTraceObject(3)->timestamp);
CHECK_EQ(32832, platform.GetTraceObject(4)->timestamp);
}
TEST(BuiltinsIsTraceCategoryEnabled) {
......@@ -342,7 +335,7 @@ TEST(BuiltinsTrace) {
.As<v8::Boolean>();
CHECK(!result->BooleanValue(isolate));
CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(0, platform.NumberOfTraceObjects());
}
// Test with enabled category
......@@ -361,12 +354,12 @@ TEST(BuiltinsTrace) {
.As<v8::Boolean>();
CHECK(result->BooleanValue(isolate));
CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(1, platform.NumberOfTraceObjects());
CHECK_EQ(123, GET_TRACE_OBJECT(0)->id);
CHECK_EQ('b', GET_TRACE_OBJECT(0)->phase);
CHECK_EQ("name", GET_TRACE_OBJECT(0)->name);
CHECK_EQ(1, GET_TRACE_OBJECT(0)->num_args);
CHECK_EQ(123, platform.GetTraceObject(0)->id);
CHECK_EQ('b', platform.GetTraceObject(0)->phase);
CHECK_EQ("name", platform.GetTraceObject(0)->name);
CHECK_EQ(1, platform.GetTraceObject(0)->num_args);
}
// Test with enabled utf8 category
......@@ -385,11 +378,11 @@ TEST(BuiltinsTrace) {
.As<v8::Boolean>();
CHECK(result->BooleanValue(isolate));
CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->size());
CHECK_EQ(2, platform.NumberOfTraceObjects());
CHECK_EQ(123, GET_TRACE_OBJECT(1)->id);
CHECK_EQ('b', GET_TRACE_OBJECT(1)->phase);
CHECK_EQ("name\u20ac", GET_TRACE_OBJECT(1)->name);
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(123, platform.GetTraceObject(1)->id);
CHECK_EQ('b', platform.GetTraceObject(1)->phase);
CHECK_EQ("name\u20ac", platform.GetTraceObject(1)->name);
CHECK_EQ(1, platform.GetTraceObject(1)->num_args);
}
}
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