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

Side by Side Diff: runtime/vm/timeline_test.cc

Issue 2620413002: Fix various memory leaks in unit tests detected by a new version of ASAN. (Closed)
Patch Set: . Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/snapshot_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <cstring> 5 #include <cstring>
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 int64_t end) { 84 int64_t end) {
85 ASSERT(recorder != NULL); 85 ASSERT(recorder != NULL);
86 ASSERT(label != NULL); 86 ASSERT(label != NULL);
87 ASSERT(end >= 0); 87 ASSERT(end >= 0);
88 TimelineEvent* event = recorder->StartEvent(); 88 TimelineEvent* event = recorder->StartEvent();
89 ASSERT(event != NULL); 89 ASSERT(event != NULL);
90 event->End(label, end); 90 event->End(label, end);
91 event->Complete(); 91 event->Complete();
92 } 92 }
93 93
94 static void Clear(TimelineEventEndlessRecorder* recorder) { 94 static void Clear(TimelineEventRecorder* recorder) {
95 ASSERT(recorder != NULL); 95 ASSERT(recorder != NULL);
96 recorder->Clear(); 96 recorder->Clear();
97 } 97 }
98 98
99 static void FinishBlock(TimelineEventBlock* block) { block->Finish(); } 99 static void FinishBlock(TimelineEventBlock* block) { block->Finish(); }
100 }; 100 };
101 101
102 102
103 TEST_CASE(TimelineEventIsValid) { 103 TEST_CASE(TimelineEventIsValid) {
104 // Create a test stream. 104 // Create a test stream.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncInstant)); 336 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncInstant));
337 event->Complete(); 337 event->Complete();
338 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncInstant)); 338 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncInstant));
339 339
340 event = stream.StartEvent(); 340 event = stream.StartEvent();
341 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 341 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
342 event->AsyncEnd("asyncEndCabbage", async_id); 342 event->AsyncEnd("asyncEndCabbage", async_id);
343 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd)); 343 EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
344 event->Complete(); 344 event->Complete();
345 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd)); 345 EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd));
346
347 delete recorder;
346 } 348 }
347 349
348 350
349 static bool LabelMatch(TimelineEvent* event, const char* label) { 351 static bool LabelMatch(TimelineEvent* event, const char* label) {
350 ASSERT(event != NULL); 352 ASSERT(event != NULL);
351 return strcmp(event->label(), label) == 0; 353 return strcmp(event->label(), label) == 0;
352 } 354 }
353 355
354 356
355 TEST_CASE(TimelineAnalysis_ThreadBlockCount) { 357 TEST_CASE(TimelineAnalysis_ThreadBlockCount) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 EXPECT(it.HasNext()); 461 EXPECT(it.HasNext());
460 EXPECT(LabelMatch(it.Next(), "C")); 462 EXPECT(LabelMatch(it.Next(), "C"));
461 EXPECT(it.HasNext()); 463 EXPECT(it.HasNext());
462 EXPECT(LabelMatch(it.Next(), "D")); 464 EXPECT(LabelMatch(it.Next(), "D"));
463 EXPECT(it.HasNext()); 465 EXPECT(it.HasNext());
464 EXPECT(LabelMatch(it.Next(), "E")); 466 EXPECT(LabelMatch(it.Next(), "E"));
465 EXPECT(it.HasNext()); 467 EXPECT(it.HasNext());
466 EXPECT(LabelMatch(it.Next(), "F")); 468 EXPECT(LabelMatch(it.Next(), "F"));
467 EXPECT(!it.HasNext()); 469 EXPECT(!it.HasNext());
468 } 470 }
471
472 TimelineTestHelper::Clear(recorder);
473 delete recorder;
469 } 474 }
470 475
471 476
472 TEST_CASE(TimelineRingRecorderJSONOrder) { 477 TEST_CASE(TimelineRingRecorderJSONOrder) {
473 TimelineStream stream; 478 TimelineStream stream;
474 stream.Init("testStream", true); 479 stream.Init("testStream", true);
475 480
476 TimelineEventRingRecorder* recorder = 481 TimelineEventRingRecorder* recorder =
477 new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2); 482 new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2);
478 483
(...skipping 16 matching lines...) Expand all
495 JSONStream js; 500 JSONStream js;
496 TimelineEventFilter filter; 501 TimelineEventFilter filter;
497 recorder->PrintJSON(&js, &filter); 502 recorder->PrintJSON(&js, &filter);
498 // trace-event has a requirement that events for a thread must have 503 // trace-event has a requirement that events for a thread must have
499 // monotonically increasing timestamps. 504 // monotonically increasing timestamps.
500 // Verify that "Alpha" comes before "Beta" even though "Beta" is in the first 505 // Verify that "Alpha" comes before "Beta" even though "Beta" is in the first
501 // block. 506 // block.
502 const char* alpha = strstr(js.ToCString(), "Alpha"); 507 const char* alpha = strstr(js.ToCString(), "Alpha");
503 const char* beta = strstr(js.ToCString(), "Beta"); 508 const char* beta = strstr(js.ToCString(), "Beta");
504 EXPECT(alpha < beta); 509 EXPECT(alpha < beta);
510
511 TimelineTestHelper::Clear(recorder);
512 delete recorder;
505 } 513 }
506 514
507 515
508 TEST_CASE(TimelinePauses_Basic) { 516 TEST_CASE(TimelinePauses_Basic) {
509 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); 517 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder();
510 ASSERT(recorder != NULL); 518 ASSERT(recorder != NULL);
511 Zone* zone = thread->zone(); 519 Zone* zone = thread->zone();
512 Isolate* isolate = thread->isolate(); 520 Isolate* isolate = thread->isolate();
513 OSThread* os_thread = thread->os_thread(); 521 OSThread* os_thread = thread->os_thread();
514 ASSERT(os_thread != NULL); 522 ASSERT(os_thread != NULL);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 TimelinePauses pauses(zone, isolate, recorder); 675 TimelinePauses pauses(zone, isolate, recorder);
668 pauses.Setup(); 676 pauses.Setup();
669 pauses.CalculatePauseTimesForThread(tid); 677 pauses.CalculatePauseTimesForThread(tid);
670 EXPECT(!pauses.has_error()); 678 EXPECT(!pauses.has_error());
671 EXPECT_EQ(10, pauses.InclusiveTime("a")); 679 EXPECT_EQ(10, pauses.InclusiveTime("a"));
672 EXPECT_EQ(10, pauses.ExclusiveTime("a")); 680 EXPECT_EQ(10, pauses.ExclusiveTime("a"));
673 EXPECT_EQ(10, pauses.MaxInclusiveTime("a")); 681 EXPECT_EQ(10, pauses.MaxInclusiveTime("a"));
674 EXPECT_EQ(8, pauses.MaxExclusiveTime("a")); 682 EXPECT_EQ(8, pauses.MaxExclusiveTime("a"));
675 } 683 }
676 TimelineTestHelper::Clear(recorder); 684 TimelineTestHelper::Clear(recorder);
685
686 delete recorder;
677 } 687 }
678 688
679 689
680 TEST_CASE(TimelinePauses_BeginEnd) { 690 TEST_CASE(TimelinePauses_BeginEnd) {
681 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder(); 691 TimelineEventEndlessRecorder* recorder = new TimelineEventEndlessRecorder();
682 ASSERT(recorder != NULL); 692 ASSERT(recorder != NULL);
683 Zone* zone = thread->zone(); 693 Zone* zone = thread->zone();
684 Isolate* isolate = thread->isolate(); 694 Isolate* isolate = thread->isolate();
685 OSThread* os_thread = thread->os_thread(); 695 OSThread* os_thread = thread->os_thread();
686 ASSERT(os_thread != NULL); 696 ASSERT(os_thread != NULL);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 // Pop "a" without popping "b" first. 887 // Pop "a" without popping "b" first.
878 TimelineTestHelper::FakeEnd(recorder, "a", 10); 888 TimelineTestHelper::FakeEnd(recorder, "a", 10);
879 889
880 { 890 {
881 TimelinePauses pauses(zone, isolate, recorder); 891 TimelinePauses pauses(zone, isolate, recorder);
882 pauses.Setup(); 892 pauses.Setup();
883 pauses.CalculatePauseTimesForThread(tid); 893 pauses.CalculatePauseTimesForThread(tid);
884 EXPECT(pauses.has_error()); 894 EXPECT(pauses.has_error());
885 } 895 }
886 TimelineTestHelper::Clear(recorder); 896 TimelineTestHelper::Clear(recorder);
897
898 delete recorder;
887 } 899 }
888 900
889 #endif // !PRODUCT 901 #endif // !PRODUCT
890 902
891 } // namespace dart 903 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698