OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #include "platform/assert.h" | |
6 #include "vm/globals.h" | |
7 #include "vm/json_stream.h" | |
8 #include "vm/trace_buffer.h" | |
9 #include "vm/unit_test.h" | |
10 | |
11 namespace dart { | |
12 | |
13 #ifndef PRODUCT | |
14 | |
15 TEST_CASE(TraceBufferEmpty) { | |
16 Isolate* isolate = Isolate::Current(); | |
17 TraceBuffer::Init(isolate, 3); | |
18 TraceBuffer* trace_buffer = isolate->trace_buffer(); | |
19 { | |
20 JSONStream js; | |
21 trace_buffer->PrintToJSONStream(&js); | |
22 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | |
23 } | |
24 delete trace_buffer; | |
25 } | |
26 | |
27 | |
28 TEST_CASE(TraceBufferClear) { | |
29 Isolate* isolate = Isolate::Current(); | |
30 TraceBuffer::Init(isolate, 3); | |
31 TraceBuffer* trace_buffer = isolate->trace_buffer(); | |
32 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | |
33 trace_buffer->Clear(); | |
34 { | |
35 JSONStream js; | |
36 trace_buffer->PrintToJSONStream(&js); | |
37 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | |
38 } | |
39 delete trace_buffer; | |
40 } | |
41 | |
42 | |
43 TEST_CASE(TraceBufferTrace) { | |
44 Isolate* isolate = Isolate::Current(); | |
45 TraceBuffer::Init(isolate, 3); | |
46 TraceBuffer* trace_buffer = isolate->trace_buffer(); | |
47 | |
48 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | |
49 { | |
50 JSONStream js; | |
51 trace_buffer->PrintToJSONStream(&js); | |
52 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | |
53 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | |
54 "\"message\":\"abc\"}]}", js.ToCString()); | |
55 } | |
56 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def"); | |
57 { | |
58 JSONStream js; | |
59 trace_buffer->PrintToJSONStream(&js); | |
60 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | |
61 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | |
62 "\"message\":\"abc\"}," | |
63 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | |
64 "\"message\":\"def\"}]}", js.ToCString()); | |
65 } | |
66 trace_buffer->Trace(kMicrosecondsPerSecond * 3, "ghi"); | |
67 { | |
68 JSONStream js; | |
69 trace_buffer->PrintToJSONStream(&js); | |
70 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | |
71 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | |
72 "\"message\":\"abc\"}," | |
73 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | |
74 "\"message\":\"def\"}," | |
75 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," | |
76 "\"message\":\"ghi\"}]}", js.ToCString()); | |
77 } | |
78 // This will overwrite the first Trace. | |
79 trace_buffer->Trace(kMicrosecondsPerSecond * 4, "jkl"); | |
80 { | |
81 JSONStream js; | |
82 trace_buffer->PrintToJSONStream(&js); | |
83 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | |
84 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | |
85 "\"message\":\"def\"}," | |
86 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," | |
87 "\"message\":\"ghi\"}," | |
88 "{\"type\":\"TraceBufferEntry\",\"time\":4.000000," | |
89 "\"message\":\"jkl\"}]}", js.ToCString()); | |
90 } | |
91 delete trace_buffer; | |
92 } | |
93 | |
94 | |
95 TEST_CASE(TraceBufferTraceF) { | |
96 Isolate* isolate = Isolate::Current(); | |
97 TraceBuffer::Init(isolate, 3); | |
98 TraceBuffer* trace_buffer = isolate->trace_buffer(); | |
99 trace_buffer->TraceF("foo %d %s", 99, "bar"); | |
100 { | |
101 JSONStream js; | |
102 trace_buffer->PrintToJSONStream(&js); | |
103 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); | |
104 } | |
105 delete trace_buffer; | |
106 } | |
107 | |
108 #endif // !PRODUCT | |
109 | |
110 } // namespace dart | |
OLD | NEW |