OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of logging utilities from log-utils.h | 3 // Tests of logging utilities from log-utils.h |
4 | 4 |
5 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "log-utils.h" | 9 #include "log-utils.h" |
10 #include "cctest.h" | 10 #include "cctest.h" |
11 | 11 |
12 using v8::internal::CStrVector; | |
12 using v8::internal::EmbeddedVector; | 13 using v8::internal::EmbeddedVector; |
13 using v8::internal::LogDynamicBuffer; | 14 using v8::internal::LogDynamicBuffer; |
15 using v8::internal::LogRecordCompressor; | |
16 using v8::internal::MutableCStrVector; | |
17 using v8::internal::ScopedVector; | |
14 using v8::internal::Vector; | 18 using v8::internal::Vector; |
15 | 19 |
16 // Fills 'ref_buffer' with test data: a sequence of two-digit | 20 // Fills 'ref_buffer' with test data: a sequence of two-digit |
17 // hex numbers: '0001020304...'. Then writes 'ref_buffer' contents to 'dynabuf'. | 21 // hex numbers: '0001020304...'. Then writes 'ref_buffer' contents to 'dynabuf'. |
18 static void WriteData(LogDynamicBuffer* dynabuf, Vector<char>* ref_buffer) { | 22 static void WriteData(LogDynamicBuffer* dynabuf, Vector<char>* ref_buffer) { |
19 static const char kHex[] = "0123456789ABCDEF"; | 23 static const char kHex[] = "0123456789ABCDEF"; |
20 CHECK_GT(ref_buffer->length(), 0); | 24 CHECK_GT(ref_buffer->length(), 0); |
21 CHECK_GT(513, ref_buffer->length()); | 25 CHECK_GT(513, ref_buffer->length()); |
22 for (int i = 0, half_len = ref_buffer->length() >> 1; i < half_len; ++i) { | 26 for (int i = 0, half_len = ref_buffer->length() >> 1; i < half_len; ++i) { |
23 (*ref_buffer)[i << 1] = kHex[i >> 4]; | 27 (*ref_buffer)[i << 1] = kHex[i >> 4]; |
(...skipping 16 matching lines...) Expand all Loading... | |
40 // Helper function used by CHECK_EQ to compare Vectors. Templatized to | 44 // Helper function used by CHECK_EQ to compare Vectors. Templatized to |
41 // accept both "char" and "const char" vector contents. | 45 // accept both "char" and "const char" vector contents. |
42 template <typename E, typename V> | 46 template <typename E, typename V> |
43 static inline void CheckEqualsHelper(const char* file, int line, | 47 static inline void CheckEqualsHelper(const char* file, int line, |
44 const char* expected_source, | 48 const char* expected_source, |
45 const Vector<E>& expected, | 49 const Vector<E>& expected, |
46 const char* value_source, | 50 const char* value_source, |
47 const Vector<V>& value) { | 51 const Vector<V>& value) { |
48 if (expected.length() != value.length()) { | 52 if (expected.length() != value.length()) { |
49 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" | 53 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" |
50 "# Vectors lengths differ: %d expected, %d found", | 54 "# Vectors lengths differ: %d expected, %d found\n" |
55 "# Expected: %.*s\n" | |
56 "# Found: %.*s", | |
51 expected_source, value_source, | 57 expected_source, value_source, |
52 expected.length(), value.length()); | 58 expected.length(), value.length(), |
59 expected.length(), expected.start(), | |
60 value.length(), value.start()); | |
53 } | 61 } |
54 if (strncmp(expected.start(), value.start(), expected.length()) != 0) { | 62 if (strncmp(expected.start(), value.start(), expected.length()) != 0) { |
55 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" | 63 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" |
56 "# Vectors contents differ:\n" | 64 "# Vectors contents differ:\n" |
57 "# Expected: %.*s\n" | 65 "# Expected: %.*s\n" |
58 "# Found: %.*s", | 66 "# Found: %.*s", |
59 expected_source, value_source, | 67 expected_source, value_source, |
60 expected.length(), expected.start(), | 68 expected.length(), expected.start(), |
61 value.length(), value.start()); | 69 value.length(), value.start()); |
62 } | 70 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 // Try to write data that will not fit in the buffer. | 125 // Try to write data that will not fit in the buffer. |
118 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), 128 - 100 - seal_size + 1)); | 126 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), 128 - 100 - seal_size + 1)); |
119 // Now the buffer is sealed, writing of any amount of data is forbidden. | 127 // Now the buffer is sealed, writing of any amount of data is forbidden. |
120 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), 1)); | 128 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), 1)); |
121 EmbeddedVector<char, 100> buf; | 129 EmbeddedVector<char, 100> buf; |
122 CHECK_EQ(100, ReadData(&dynabuf, 0, &buf)); | 130 CHECK_EQ(100, ReadData(&dynabuf, 0, &buf)); |
123 CHECK_EQ(ref_buf, buf); | 131 CHECK_EQ(ref_buf, buf); |
124 // Check the seal. | 132 // Check the seal. |
125 EmbeddedVector<char, 50> seal_buf; | 133 EmbeddedVector<char, 50> seal_buf; |
126 CHECK_EQ(seal_size, ReadData(&dynabuf, 100, &seal_buf)); | 134 CHECK_EQ(seal_size, ReadData(&dynabuf, 100, &seal_buf)); |
127 CHECK_EQ(v8::internal::CStrVector(seal), seal_buf.SubVector(0, seal_size)); | 135 CHECK_EQ(CStrVector(seal), seal_buf.SubVector(0, seal_size)); |
128 // Verify that there's no data beyond the seal. | 136 // Verify that there's no data beyond the seal. |
129 CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf)); | 137 CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf)); |
130 } | 138 } |
131 | 139 |
140 | |
141 TEST(CompressorStore) { | |
142 LogRecordCompressor comp(2); | |
143 const Vector<const char> empty = CStrVector(""); | |
144 CHECK(comp.Store(empty)); | |
145 CHECK(!comp.Store(empty)); | |
146 CHECK(!comp.Store(empty)); | |
147 const Vector<const char> aaa = CStrVector("aaa"); | |
148 CHECK(comp.Store(aaa)); | |
149 CHECK(!comp.Store(aaa)); | |
150 CHECK(!comp.Store(aaa)); | |
151 CHECK(comp.Store(empty)); | |
152 CHECK(!comp.Store(empty)); | |
153 CHECK(!comp.Store(empty)); | |
154 } | |
155 | |
156 | |
157 void CheckCompression(LogRecordCompressor* comp, | |
Søren Thygesen Gjesse
2009/06/11 11:13:56
Not that it's a big deal, but you could use a refe
Mikhail Naganov
2009/06/11 14:07:12
I'm modifying Compressor's state, to I'm treating
| |
158 const Vector<const char>& after) { | |
159 EmbeddedVector<char, 100> result; | |
160 CHECK(comp->RetrievePreviousCompressed(&result)); | |
161 CHECK_EQ(after, result); | |
162 } | |
163 | |
164 | |
165 void CheckCompression(LogRecordCompressor* comp, | |
Søren Thygesen Gjesse
2009/06/11 11:13:56
Ditto.
| |
166 const char* after) { | |
167 CheckCompression(comp, CStrVector(after)); | |
168 } | |
169 | |
170 | |
171 TEST(CompressorNonCompressed) { | |
172 LogRecordCompressor comp(2); | |
173 CHECK(!comp.RetrievePreviousCompressed(NULL)); | |
174 const Vector<const char> empty = CStrVector(""); | |
175 CHECK(comp.Store(empty)); | |
176 CHECK(!comp.RetrievePreviousCompressed(NULL)); | |
177 const Vector<const char> a_x_20 = CStrVector("aaaaaaaaaaaaaaaaaaaa"); | |
178 CHECK(comp.Store(a_x_20)); | |
179 CheckCompression(&comp, empty); | |
180 CheckCompression(&comp, empty); | |
181 CHECK(comp.Store(empty)); | |
182 CheckCompression(&comp, a_x_20); | |
183 CheckCompression(&comp, a_x_20); | |
184 } | |
185 | |
186 | |
187 TEST(CompressorSingleLine) { | |
188 LogRecordCompressor comp(3); | |
189 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); | |
190 CHECK(comp.Store(string_1)); | |
191 const Vector<const char> string_2 = CStrVector("fff,ddd,ccc,bbb,aaa"); | |
192 CHECK(comp.Store(string_2)); | |
193 // string_1 hasn't been compressed. | |
194 CheckCompression(&comp, string_1); | |
195 CheckCompression(&comp, string_1); | |
196 const Vector<const char> string_3 = CStrVector("hhh,ggg,ccc,bbb,aaa"); | |
197 CHECK(comp.Store(string_3)); | |
198 // string_2 compressed using string_1. | |
199 CheckCompression(&comp, "fff,#1:1"); | |
200 CheckCompression(&comp, "fff,#1:1"); | |
201 CHECK(!comp.Store(string_3)); | |
202 // Expecting no changes. | |
203 CheckCompression(&comp, "fff,#1:1"); | |
204 CHECK(!comp.Store(string_3)); | |
205 // Expecting no changes. | |
206 CheckCompression(&comp, "fff,#1:1"); | |
207 const Vector<const char> string_4 = CStrVector("iii,hhh,ggg,ccc,bbb,aaa"); | |
208 CHECK(comp.Store(string_4)); | |
209 // string_3 compressed using string_2. | |
210 CheckCompression(&comp, "hhh,ggg,#1:2"); | |
211 const Vector<const char> string_5 = CStrVector("nnn,mmm,lll,kkk,jjj"); | |
212 CHECK(comp.Store(string_5)); | |
213 // string_4 compressed using string_3. | |
214 CheckCompression(&comp, "iii,hhh,#1:1"); | |
215 const Vector<const char> string_6 = CStrVector("nnn,mmmmmm,lll,kkk,jjj"); | |
216 CHECK(comp.Store(string_6)); | |
217 // string_5 hasn't been compressed. | |
218 CheckCompression(&comp, string_5); | |
219 CHECK(comp.Store(string_5)); | |
220 // string_6 compressed using string_5. | |
221 CheckCompression(&comp, "nnn,mmmmmm,#1:2"); | |
222 const Vector<const char> string_7 = CStrVector("nnnnnn,mmm,lll,kkk,jjj"); | |
223 CHECK(comp.Store(string_7)); | |
224 // string_5 compressed using string_6. | |
225 CheckCompression(&comp, "nnn,mmm,#1:2"); | |
226 const Vector<const char> string_8 = CStrVector("xxn,mmm,lll,kkk,jjj"); | |
227 CHECK(comp.Store(string_8)); | |
228 // string_7 compressed using string_5. | |
229 CheckCompression(&comp, "nnnnnn,#1:1"); | |
230 const Vector<const char> string_9 = | |
231 CStrVector("aaaaaaaaaaaaa,bbbbbbbbbbbbbbbbb"); | |
232 CHECK(comp.Store(string_9)); | |
233 // string_8 compressed using string_7. | |
234 CheckCompression(&comp, "xxn,#1:1"); | |
235 const Vector<const char> string_10 = | |
236 CStrVector("aaaaaaaaaaaaa,cccccccbbbbbbbbbb"); | |
237 CHECK(comp.Store(string_10)); | |
238 // string_9 hasn't been compressed. | |
239 CheckCompression(&comp, string_9); | |
240 CHECK(comp.Store(string_1)); | |
241 // string_10 hasn't been compressed. | |
242 CheckCompression(&comp, string_10); | |
243 } | |
244 | |
245 | |
246 | |
247 TEST(CompressorMultiLines) { | |
248 LogRecordCompressor comp(5); | |
249 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); | |
250 CHECK(comp.Store(string_1)); | |
251 const Vector<const char> string_2 = CStrVector("iii,hhh,ggg,fff,aaa"); | |
252 CHECK(comp.Store(string_2)); | |
253 const Vector<const char> string_3 = CStrVector("mmm,lll,kkk,jjj,aaa"); | |
254 CHECK(comp.Store(string_3)); | |
255 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa"); | |
256 CHECK(comp.Store(string_4)); | |
257 const Vector<const char> string_5 = CStrVector("ooo,lll,kkk,jjj,aaa"); | |
258 CHECK(comp.Store(string_5)); | |
259 // string_4 compressed using string_2. | |
260 CheckCompression(&comp, "nnn,#2:1"); | |
261 CHECK(comp.Store(string_1)); | |
262 // string_5 compressed using string_3. | |
263 CheckCompression(&comp, "ooo,#2:1"); | |
264 CHECK(comp.Store(string_4)); | |
265 // string_1 is out of buffer by now, so it shouldn't be compressed. | |
Søren Thygesen Gjesse
2009/06/11 11:13:56
Add an assert for kRecordCompressorWindow to easil
Mikhail Naganov
2009/06/11 14:07:12
Actually, it doesn't depend on kRecordCompressorWi
| |
266 CheckCompression(&comp, string_1); | |
267 CHECK(comp.Store(string_2)); | |
268 // string_4 compressed using itself. | |
269 CheckCompression(&comp, "nnn,#3:1"); | |
270 } | |
271 | |
272 | |
273 TEST(CompressorBestSelection) { | |
274 LogRecordCompressor comp(5); | |
275 const Vector<const char> string_1 = CStrVector("eee,ddd,ccc,bbb,aaa"); | |
276 CHECK(comp.Store(string_1)); | |
277 const Vector<const char> string_2 = CStrVector("ddd,ccc,bbb,aaa"); | |
278 CHECK(comp.Store(string_2)); | |
279 const Vector<const char> string_3 = CStrVector("fff,eee,ddd,ccc,bbb,aaa"); | |
280 CHECK(comp.Store(string_3)); | |
281 // string_2 compressed using string_1. | |
282 CheckCompression(&comp, "ddd,#1:2"); | |
283 const Vector<const char> string_4 = CStrVector("nnn,hhh,ggg,fff,aaa"); | |
284 CHECK(comp.Store(string_4)); | |
285 // Compressing string_3 using string_1 gives a better compression than | |
286 // using string_2. | |
287 CheckCompression(&comp, "fff,eee,#2:1"); | |
288 } | |
289 | |
132 #endif // ENABLE_LOGGING_AND_PROFILING | 290 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |