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

Side by Side Diff: test/cctest/test-log-utils.cc

Issue 115859: Handle filling up of memory buffer to make log processing in DevTools Profiler easier. (Closed)
Patch Set: Created 11 years, 7 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
« src/log-utils.cc ('K') | « src/log-utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 19 matching lines...) Expand all
30 dynabuf->Write(ref_buffer->start(), ref_buffer->length())); 30 dynabuf->Write(ref_buffer->start(), ref_buffer->length()));
31 } 31 }
32 32
33 33
34 static int ReadData( 34 static int ReadData(
35 LogDynamicBuffer* dynabuf, int start_pos, i::Vector<char>* buffer) { 35 LogDynamicBuffer* dynabuf, int start_pos, i::Vector<char>* buffer) {
36 return dynabuf->Read(start_pos, buffer->start(), buffer->length()); 36 return dynabuf->Read(start_pos, buffer->start(), buffer->length());
37 } 37 }
38 38
39 39
40 // Helper function used by CHECK_EQ to compare Vectors. 40 // Helper function used by CHECK_EQ to compare Vectors. Templatized to
41 // accept both "char" and "const char" vector contents.
42 template <typename E, typename V>
41 static inline void CheckEqualsHelper(const char* file, int line, 43 static inline void CheckEqualsHelper(const char* file, int line,
42 const char* expected_source, 44 const char* expected_source,
43 const Vector<char>& expected, 45 const Vector<E>& expected,
44 const char* value_source, 46 const char* value_source,
45 const Vector<char>& value) { 47 const Vector<V>& value) {
46 if (expected.length() != value.length()) { 48 if (expected.length() != value.length()) {
47 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" 49 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n"
48 "# Vectors lengths differ: %d expected, %d found", 50 "# Vectors lengths differ: %d expected, %d found",
49 expected_source, value_source, 51 expected_source, value_source,
50 expected.length(), value.length()); 52 expected.length(), value.length());
51 } 53 }
52 if (strncmp(expected.start(), value.start(), expected.length()) != 0) { 54 if (strncmp(expected.start(), value.start(), expected.length()) != 0) {
53 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n" 55 V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n"
54 "# Vectors contents differ:\n" 56 "# Vectors contents differ:\n"
55 "# Expected: %.*s\n" 57 "# Expected: %.*s\n"
56 "# Found: %.*s", 58 "# Found: %.*s",
57 expected_source, value_source, 59 expected_source, value_source,
58 expected.length(), expected.start(), 60 expected.length(), expected.start(),
59 value.length(), value.start()); 61 value.length(), value.start());
60 } 62 }
61 } 63 }
62 64
63 65
64 TEST(DynaBufSingleBlock) { 66 TEST(DynaBufSingleBlock) {
65 LogDynamicBuffer dynabuf(32, 32); 67 LogDynamicBuffer dynabuf(32, 32, "", 0);
66 EmbeddedVector<char, 32> ref_buf; 68 EmbeddedVector<char, 32> ref_buf;
67 WriteData(&dynabuf, &ref_buf); 69 WriteData(&dynabuf, &ref_buf);
68 EmbeddedVector<char, 32> buf; 70 EmbeddedVector<char, 32> buf;
69 CHECK_EQ(32, dynabuf.Read(0, buf.start(), buf.length())); 71 CHECK_EQ(32, dynabuf.Read(0, buf.start(), buf.length()));
70 CHECK_EQ(32, ReadData(&dynabuf, 0, &buf)); 72 CHECK_EQ(32, ReadData(&dynabuf, 0, &buf));
71 CHECK_EQ(ref_buf, buf); 73 CHECK_EQ(ref_buf, buf);
72 74
73 // Verify that we can't read and write past the end. 75 // Verify that we can't read and write past the end.
74 CHECK_EQ(0, dynabuf.Read(32, buf.start(), buf.length())); 76 CHECK_EQ(0, dynabuf.Read(32, buf.start(), buf.length()));
75 CHECK_EQ(0, dynabuf.Write(buf.start(), buf.length())); 77 CHECK_EQ(0, dynabuf.Write(buf.start(), buf.length()));
76 } 78 }
77 79
78 80
79 TEST(DynaBufCrossBlocks) { 81 TEST(DynaBufCrossBlocks) {
80 LogDynamicBuffer dynabuf(32, 128); 82 LogDynamicBuffer dynabuf(32, 128, "", 0);
81 EmbeddedVector<char, 48> ref_buf; 83 EmbeddedVector<char, 48> ref_buf;
82 WriteData(&dynabuf, &ref_buf); 84 WriteData(&dynabuf, &ref_buf);
83 CHECK_EQ(48, dynabuf.Write(ref_buf.start(), ref_buf.length())); 85 CHECK_EQ(48, dynabuf.Write(ref_buf.start(), ref_buf.length()));
84 // Verify that we can't write data when remaining buffer space isn't enough. 86 // Verify that we can't write data when remaining buffer space isn't enough.
85 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), ref_buf.length())); 87 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), ref_buf.length()));
86 EmbeddedVector<char, 48> buf; 88 EmbeddedVector<char, 48> buf;
87 CHECK_EQ(48, ReadData(&dynabuf, 0, &buf)); 89 CHECK_EQ(48, ReadData(&dynabuf, 0, &buf));
88 CHECK_EQ(ref_buf, buf); 90 CHECK_EQ(ref_buf, buf);
89 CHECK_EQ(48, ReadData(&dynabuf, 48, &buf)); 91 CHECK_EQ(48, ReadData(&dynabuf, 48, &buf));
90 CHECK_EQ(ref_buf, buf); 92 CHECK_EQ(ref_buf, buf);
91 CHECK_EQ(0, ReadData(&dynabuf, 48 * 2, &buf)); 93 CHECK_EQ(0, ReadData(&dynabuf, 48 * 2, &buf));
92 } 94 }
93 95
94 96
95 TEST(DynaBufReadTruncation) { 97 TEST(DynaBufReadTruncation) {
96 LogDynamicBuffer dynabuf(32, 128); 98 LogDynamicBuffer dynabuf(32, 128, "", 0);
97 EmbeddedVector<char, 128> ref_buf; 99 EmbeddedVector<char, 128> ref_buf;
98 WriteData(&dynabuf, &ref_buf); 100 WriteData(&dynabuf, &ref_buf);
99 EmbeddedVector<char, 128> buf; 101 EmbeddedVector<char, 128> buf;
100 CHECK_EQ(128, ReadData(&dynabuf, 0, &buf)); 102 CHECK_EQ(128, ReadData(&dynabuf, 0, &buf));
101 CHECK_EQ(ref_buf, buf); 103 CHECK_EQ(ref_buf, buf);
102 // Try to read near the end with a buffer larger than remaining data size. 104 // Try to read near the end with a buffer larger than remaining data size.
103 EmbeddedVector<char, 48> tail_buf; 105 EmbeddedVector<char, 48> tail_buf;
104 CHECK_EQ(32, ReadData(&dynabuf, 128 - 32, &tail_buf)); 106 CHECK_EQ(32, ReadData(&dynabuf, 128 - 32, &tail_buf));
105 CHECK_EQ(ref_buf.SubVector(128 - 32, 128), tail_buf.SubVector(0, 32)); 107 CHECK_EQ(ref_buf.SubVector(128 - 32, 128), tail_buf.SubVector(0, 32));
106 } 108 }
107 109
110
111 TEST(DynaBufSealing) {
112 const char* seal = "Sealed";
113 const int seal_size = strlen(seal);
114 LogDynamicBuffer dynabuf(32, 128, seal, seal_size);
115 EmbeddedVector<char, 100> ref_buf;
116 WriteData(&dynabuf, &ref_buf);
117 // 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));
119 // Now the buffer is sealed, writing of any amount of data is forbidden.
120 CHECK_EQ(0, dynabuf.Write(ref_buf.start(), 1));
121 EmbeddedVector<char, 100> buf;
122 CHECK_EQ(100, ReadData(&dynabuf, 0, &buf));
123 CHECK_EQ(ref_buf, buf);
124 // Check the seal.
125 EmbeddedVector<char, 50> seal_buf;
126 CHECK_EQ(seal_size, ReadData(&dynabuf, 100, &seal_buf));
127 CHECK_EQ(v8::internal::CStrVector(seal), seal_buf.SubVector(0, seal_size));
128 // Verify that there's no data beyond the seal.
129 CHECK_EQ(0, ReadData(&dynabuf, 100 + seal_size, &buf));
130 }
131
108 #endif // ENABLE_LOGGING_AND_PROFILING 132 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« src/log-utils.cc ('K') | « src/log-utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698