Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc

Issue 1891543003: [tracing] Turn StackFrame into struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
index 05c60c722c317cca7bf6e52453a5faba1d7b1903..a39700e4fff4171d6701883d83d6a8ef98a85cdd 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc
@@ -33,7 +33,7 @@ void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) {
->GetContextSnapshot();
auto actual = std::begin(ctx.backtrace.frames);
- auto actual_bottom = std::end(ctx.backtrace.frames);
+ auto actual_bottom = actual + ctx.backtrace.frame_count;
Primiano Tucci (use gerrit) 2016/04/14 10:15:33 why do we need this change?
Dmitry Skiba 2016/04/15 07:01:40 Because we want to check only valid frames, within
auto expected = std::begin(expected_backtrace);
auto expected_bottom = std::end(expected_backtrace);
@@ -53,8 +53,7 @@ void AssertBacktraceEmpty() {
AllocationContextTracker::GetInstanceForCurrentThread()
->GetContextSnapshot();
- for (StackFrame frame : ctx.backtrace.frames)
- ASSERT_EQ(nullptr, frame);
+ ASSERT_EQ(0u, ctx.backtrace.frame_count);
}
class AllocationContextTrackerTest : public testing::Test {
@@ -72,24 +71,22 @@ class AllocationContextTrackerTest : public testing::Test {
};
// Check that |TRACE_EVENT| macros push and pop to the pseudo stack correctly.
-// Also check that |GetContextSnapshot| fills the backtrace with null pointers
-// when the pseudo stack height is less than the capacity.
TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) {
- StackFrame c = kCupcake;
- StackFrame d = kDonut;
- StackFrame e = kEclair;
- StackFrame f = kFroyo;
+ StackFrame c = StackFrame::FromTraceEventName(kCupcake);
+ StackFrame d = StackFrame::FromTraceEventName(kDonut);
+ StackFrame e = StackFrame::FromTraceEventName(kEclair);
+ StackFrame f = StackFrame::FromTraceEventName(kFroyo);
AssertBacktraceEmpty();
{
TRACE_EVENT0("Testing", kCupcake);
- StackFrame frame_c[] = {c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_c[] = {c};
AssertBacktraceEquals(frame_c);
{
TRACE_EVENT0("Testing", kDonut);
- StackFrame frame_cd[] = {c, d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_cd[] = {c, d};
AssertBacktraceEquals(frame_cd);
}
@@ -97,7 +94,7 @@ TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) {
{
TRACE_EVENT0("Testing", kEclair);
- StackFrame frame_ce[] = {c, e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_ce[] = {c, e};
AssertBacktraceEquals(frame_ce);
}
@@ -108,7 +105,7 @@ TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) {
{
TRACE_EVENT0("Testing", kFroyo);
- StackFrame frame_f[] = {f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_f[] = {f};
AssertBacktraceEquals(frame_f);
}
@@ -118,15 +115,15 @@ TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) {
// Same as |PseudoStackScopedTrace|, but now test the |TRACE_EVENT_BEGIN| and
// |TRACE_EVENT_END| macros.
TEST_F(AllocationContextTrackerTest, PseudoStackBeginEndTrace) {
- StackFrame c = kCupcake;
- StackFrame d = kDonut;
- StackFrame e = kEclair;
- StackFrame f = kFroyo;
+ StackFrame c = StackFrame::FromTraceEventName(kCupcake);
+ StackFrame d = StackFrame::FromTraceEventName(kDonut);
+ StackFrame e = StackFrame::FromTraceEventName(kEclair);
+ StackFrame f = StackFrame::FromTraceEventName(kFroyo);
- StackFrame frame_c[] = {c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_cd[] = {c, d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_ce[] = {c, e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_f[] = {f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_c[] = {c};
+ StackFrame frame_cd[] = {c, d};
+ StackFrame frame_ce[] = {c, e};
+ StackFrame frame_f[] = {f};
AssertBacktraceEmpty();
@@ -156,15 +153,15 @@ TEST_F(AllocationContextTrackerTest, PseudoStackBeginEndTrace) {
}
TEST_F(AllocationContextTrackerTest, PseudoStackMixedTrace) {
- StackFrame c = kCupcake;
- StackFrame d = kDonut;
- StackFrame e = kEclair;
- StackFrame f = kFroyo;
+ StackFrame c = StackFrame::FromTraceEventName(kCupcake);
+ StackFrame d = StackFrame::FromTraceEventName(kDonut);
+ StackFrame e = StackFrame::FromTraceEventName(kEclair);
+ StackFrame f = StackFrame::FromTraceEventName(kFroyo);
- StackFrame frame_c[] = {c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_cd[] = {c, d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_e[] = {e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- StackFrame frame_ef[] = {e, f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ StackFrame frame_c[] = {c};
+ StackFrame frame_cd[] = {c, d};
+ StackFrame frame_e[] = {e};
+ StackFrame frame_ef[] = {e, f};
AssertBacktraceEmpty();
@@ -194,6 +191,9 @@ TEST_F(AllocationContextTrackerTest, PseudoStackMixedTrace) {
}
TEST_F(AllocationContextTrackerTest, BacktraceTakesTop) {
+ StackFrame c = StackFrame::FromTraceEventName(kCupcake);
+ StackFrame f = StackFrame::FromTraceEventName(kFroyo);
+
// Push 12 events onto the pseudo stack.
TRACE_EVENT0("Testing", kCupcake);
TRACE_EVENT0("Testing", kCupcake);
@@ -217,16 +217,16 @@ TEST_F(AllocationContextTrackerTest, BacktraceTakesTop) {
->GetContextSnapshot();
// The pseudo stack relies on pointer equality, not deep string comparisons.
- ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]);
- ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]);
+ ASSERT_EQ(c, ctx.backtrace.frames[0]);
+ ASSERT_EQ(f, ctx.backtrace.frames[11]);
}
{
AllocationContext ctx =
AllocationContextTracker::GetInstanceForCurrentThread()
->GetContextSnapshot();
- ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]);
- ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]);
+ ASSERT_EQ(c, ctx.backtrace.frames[0]);
+ ASSERT_EQ(f, ctx.backtrace.frames[11]);
}
}
@@ -239,8 +239,8 @@ TEST_F(AllocationContextTrackerTest, SetCurrentThreadName) {
AllocationContext ctx1 =
AllocationContextTracker::GetInstanceForCurrentThread()
->GetContextSnapshot();
- ASSERT_EQ(kThread1, ctx1.backtrace.frames[0]);
- ASSERT_EQ(kCupcake, ctx1.backtrace.frames[1]);
+ ASSERT_EQ(StackFrame::FromThreadName(kThread1), ctx1.backtrace.frames[0]);
+ ASSERT_EQ(StackFrame::FromTraceEventName(kCupcake), ctx1.backtrace.frames[1]);
// Test if the thread name is reset.
const char kThread2[] = "thread2";
@@ -248,8 +248,8 @@ TEST_F(AllocationContextTrackerTest, SetCurrentThreadName) {
AllocationContext ctx2 =
AllocationContextTracker::GetInstanceForCurrentThread()
->GetContextSnapshot();
- ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]);
- ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]);
+ ASSERT_EQ(StackFrame::FromThreadName(kThread2), ctx2.backtrace.frames[0]);
+ ASSERT_EQ(StackFrame::FromTraceEventName(kCupcake), ctx2.backtrace.frames[1]);
}
TEST_F(AllocationContextTrackerTest, TrackTaskContext) {

Powered by Google App Engine
This is Rietveld 408576698