OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
7 #include "vm/json_stream.h" | 7 #include "vm/json_stream.h" |
8 #include "vm/trace_buffer.h" | 8 #include "vm/trace_buffer.h" |
9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 | 13 TEST_CASE(TraceBufferEmpty) { |
14 UNIT_TEST_CASE(TraceBufferEmpty) { | 14 Isolate* isolate = Isolate::Current(); |
15 TraceBuffer* trace_buffer = new TraceBuffer(3); | 15 TraceBuffer::Init(isolate, 3); |
| 16 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
16 { | 17 { |
17 JSONStream js; | 18 JSONStream js; |
18 trace_buffer->PrintToJSONStream(&js); | 19 trace_buffer->PrintToJSONStream(&js); |
19 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | 20 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); |
20 } | 21 } |
21 delete trace_buffer; | 22 delete trace_buffer; |
22 } | 23 } |
23 | 24 |
24 | 25 |
25 UNIT_TEST_CASE(TraceBufferClear) { | 26 TEST_CASE(TraceBufferClear) { |
26 TraceBuffer* trace_buffer = new TraceBuffer(3); | 27 Isolate* isolate = Isolate::Current(); |
| 28 TraceBuffer::Init(isolate, 3); |
| 29 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
27 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | 30 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); |
28 trace_buffer->Clear(); | 31 trace_buffer->Clear(); |
29 { | 32 { |
30 JSONStream js; | 33 JSONStream js; |
31 trace_buffer->PrintToJSONStream(&js); | 34 trace_buffer->PrintToJSONStream(&js); |
32 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | 35 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); |
33 } | 36 } |
34 delete trace_buffer; | 37 delete trace_buffer; |
35 } | 38 } |
36 | 39 |
37 | 40 |
38 UNIT_TEST_CASE(TraceBufferTrace) { | 41 TEST_CASE(TraceBufferTrace) { |
39 TraceBuffer* trace_buffer = new TraceBuffer(3); | 42 Isolate* isolate = Isolate::Current(); |
| 43 TraceBuffer::Init(isolate, 3); |
| 44 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
40 | 45 |
41 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | 46 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); |
42 { | 47 { |
43 JSONStream js; | 48 JSONStream js; |
44 trace_buffer->PrintToJSONStream(&js); | 49 trace_buffer->PrintToJSONStream(&js); |
45 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | 50 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" |
46 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | 51 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," |
47 "\"message\":\"abc\"}]}", js.ToCString()); | 52 "\"message\":\"abc\"}]}", js.ToCString()); |
48 } | 53 } |
49 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def"); | 54 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def"); |
(...skipping 28 matching lines...) Expand all Loading... |
78 "\"message\":\"def\"}," | 83 "\"message\":\"def\"}," |
79 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," | 84 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," |
80 "\"message\":\"ghi\"}," | 85 "\"message\":\"ghi\"}," |
81 "{\"type\":\"TraceBufferEntry\",\"time\":4.000000," | 86 "{\"type\":\"TraceBufferEntry\",\"time\":4.000000," |
82 "\"message\":\"jkl\"}]}", js.ToCString()); | 87 "\"message\":\"jkl\"}]}", js.ToCString()); |
83 } | 88 } |
84 delete trace_buffer; | 89 delete trace_buffer; |
85 } | 90 } |
86 | 91 |
87 | 92 |
88 UNIT_TEST_CASE(TraceBufferTraceF) { | 93 TEST_CASE(TraceBufferTraceF) { |
89 TraceBuffer* trace_buffer = new TraceBuffer(3); | 94 Isolate* isolate = Isolate::Current(); |
| 95 TraceBuffer::Init(isolate, 3); |
| 96 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
90 trace_buffer->TraceF("foo %d %s", 99, "bar"); | 97 trace_buffer->TraceF("foo %d %s", 99, "bar"); |
91 { | 98 { |
92 JSONStream js; | 99 JSONStream js; |
93 trace_buffer->PrintToJSONStream(&js); | 100 trace_buffer->PrintToJSONStream(&js); |
94 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); | 101 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); |
95 } | 102 } |
96 delete trace_buffer; | 103 delete trace_buffer; |
97 } | 104 } |
98 | 105 |
99 | 106 |
100 } // namespace dart | 107 } // namespace dart |
OLD | NEW |