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 |
14 UNIT_TEST_CASE(TraceBufferEmpty) { | 14 UNIT_TEST_CASE(TraceBufferEmpty) { |
15 TraceBuffer* trace_buffer = new TraceBuffer(3); | 15 TraceBuffer* trace_buffer = new TraceBuffer(3, 3); |
16 { | 16 { |
17 JSONStream js; | 17 JSONStream js; |
18 trace_buffer->PrintToJSONStream(&js); | 18 trace_buffer->PrintToJSONStream(&js); |
19 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | 19 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[]}", |
| 20 js.ToCString()); |
20 } | 21 } |
21 delete trace_buffer; | 22 delete trace_buffer; |
22 } | 23 } |
23 | 24 |
24 | 25 |
25 UNIT_TEST_CASE(TraceBufferClear) { | 26 UNIT_TEST_CASE(TraceBufferClear) { |
26 TraceBuffer* trace_buffer = new TraceBuffer(3); | 27 TraceBuffer* trace_buffer = new TraceBuffer(3, 3); |
27 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | 28 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); |
28 trace_buffer->Clear(); | 29 trace_buffer->Clear(); |
29 { | 30 { |
30 JSONStream js; | 31 JSONStream js; |
31 trace_buffer->PrintToJSONStream(&js); | 32 trace_buffer->PrintToJSONStream(&js); |
32 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString()); | 33 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[]}", |
| 34 js.ToCString()); |
33 } | 35 } |
34 delete trace_buffer; | 36 delete trace_buffer; |
35 } | 37 } |
36 | 38 |
37 | 39 |
38 UNIT_TEST_CASE(TraceBufferTrace) { | 40 UNIT_TEST_CASE(TraceBufferTrace) { |
39 TraceBuffer* trace_buffer = new TraceBuffer(3); | 41 TraceBuffer* trace_buffer = new TraceBuffer(3, 3); |
40 | 42 |
41 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); | 43 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); |
42 { | 44 { |
43 JSONStream js; | 45 JSONStream js; |
44 trace_buffer->PrintToJSONStream(&js); | 46 trace_buffer->PrintToJSONStream(&js); |
45 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | 47 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[" |
46 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | 48 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":1000," |
47 "\"message\":\"abc\"}]}", js.ToCString()); | 49 "\"message\":\"abc\"}]}", js.ToCString()); |
48 } | 50 } |
49 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def"); | 51 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def"); |
50 { | 52 { |
51 JSONStream js; | 53 JSONStream js; |
52 trace_buffer->PrintToJSONStream(&js); | 54 trace_buffer->PrintToJSONStream(&js); |
53 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | 55 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[" |
54 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | 56 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":1000," |
55 "\"message\":\"abc\"}," | 57 "\"message\":\"abc\"}," |
56 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | 58 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":2000," |
57 "\"message\":\"def\"}]}", js.ToCString()); | 59 "\"message\":\"def\"}]}", js.ToCString()); |
58 } | 60 } |
59 trace_buffer->Trace(kMicrosecondsPerSecond * 3, "ghi"); | 61 trace_buffer->Trace(kMicrosecondsPerSecond * 3, "ghi"); |
60 { | 62 { |
61 JSONStream js; | 63 JSONStream js; |
62 trace_buffer->PrintToJSONStream(&js); | 64 trace_buffer->PrintToJSONStream(&js); |
63 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | 65 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[" |
64 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000," | 66 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":1000," |
65 "\"message\":\"abc\"}," | 67 "\"message\":\"abc\"}," |
66 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | 68 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":2000," |
67 "\"message\":\"def\"}," | 69 "\"message\":\"def\"}," |
68 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," | 70 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":3000," |
69 "\"message\":\"ghi\"}]}", js.ToCString()); | 71 "\"message\":\"ghi\"}]}", js.ToCString()); |
70 } | 72 } |
71 // This will overwrite the first Trace. | 73 // This will overwrite the first Trace. |
72 trace_buffer->Trace(kMicrosecondsPerSecond * 4, "jkl"); | 74 trace_buffer->Trace(kMicrosecondsPerSecond * 4, "jkl"); |
73 { | 75 { |
74 JSONStream js; | 76 JSONStream js; |
75 trace_buffer->PrintToJSONStream(&js); | 77 trace_buffer->PrintToJSONStream(&js); |
76 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[" | 78 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"id\":\"\",\"members\":[" |
77 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000," | 79 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":2000," |
78 "\"message\":\"def\"}," | 80 "\"message\":\"def\"}," |
79 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000," | 81 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":3000," |
80 "\"message\":\"ghi\"}," | 82 "\"message\":\"ghi\"}," |
81 "{\"type\":\"TraceBufferEntry\",\"time\":4.000000," | 83 "{\"type\":\"TraceBufferEntry\",\"id\":\"\",\"time\":4000," |
82 "\"message\":\"jkl\"}]}", js.ToCString()); | 84 "\"message\":\"jkl\"}]}", js.ToCString()); |
83 } | 85 } |
84 delete trace_buffer; | 86 delete trace_buffer; |
85 } | 87 } |
86 | 88 |
87 | 89 |
88 UNIT_TEST_CASE(TraceBufferTraceF) { | 90 UNIT_TEST_CASE(TraceBufferTraceF) { |
89 TraceBuffer* trace_buffer = new TraceBuffer(3); | 91 TraceBuffer* trace_buffer = new TraceBuffer(3, 3); |
90 trace_buffer->TraceF("foo %d %s", 99, "bar"); | 92 trace_buffer->TraceF("foo %d %s", 99, "bar"); |
91 { | 93 { |
92 JSONStream js; | 94 JSONStream js; |
93 trace_buffer->PrintToJSONStream(&js); | 95 trace_buffer->PrintToJSONStream(&js); |
94 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); | 96 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); |
95 } | 97 } |
96 delete trace_buffer; | 98 delete trace_buffer; |
97 } | 99 } |
98 | 100 |
99 | 101 |
| 102 UNIT_TEST_CASE(TraceBufferGrow) { |
| 103 TraceBuffer* trace_buffer = new TraceBuffer(1); |
| 104 EXPECT_EQ(1, trace_buffer->capacity()); |
| 105 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc"); |
| 106 EXPECT_EQ(2, trace_buffer->capacity()); |
| 107 } |
| 108 |
| 109 |
100 } // namespace dart | 110 } // namespace dart |
OLD | NEW |