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

Unified Diff: test/cctest/test-log-utils.cc

Issue 115814: Implement a dynamically growing memory log buffer with an upper limit. (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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/test-log-utils.cc
diff --git a/test/cctest/test-log-utils.cc b/test/cctest/test-log-utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a46a7672d035a899b1662366a01d2325a477d4fb
--- /dev/null
+++ b/test/cctest/test-log-utils.cc
@@ -0,0 +1,108 @@
+// Copyright 2006-2009 the V8 project authors. All rights reserved.
+//
+// Tests of logging utilities from log-utils.h
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+
+#include "v8.h"
+
+#include "log-utils.h"
+#include "cctest.h"
+
+using v8::internal::EmbeddedVector;
+using v8::internal::LogDynamicBuffer;
+using v8::internal::Vector;
+
+// Writes ref_buffer.length chars into dynabuf.
Søren Thygesen Gjesse 2009/05/27 12:00:40 Please add to comment that this also actually fill
Mikhail Naganov 2009/05/28 07:05:35 Done.
+// The data written is a sequence of two-digit hex numbers: '0001020304...'.
+static void WriteData(LogDynamicBuffer* dynabuf, Vector<char>* ref_buffer) {
+ static const char kHex[] = "0123456789ABCDEF";
+ CHECK_GT(ref_buffer->length(), 0);
+ CHECK_GT(513, ref_buffer->length());
+ for (int i = 0, half_len = ref_buffer->length() >> 1; i < half_len; ++i) {
+ (*ref_buffer)[i << 1] = kHex[i >> 4];
+ (*ref_buffer)[(i << 1) + 1] = kHex[i & 15];
+ }
+ if (ref_buffer->length() & 1) {
+ ref_buffer->last() = kHex[ref_buffer->length() >> 5];
+ }
+ CHECK_EQ(ref_buffer->length(),
+ dynabuf->Write(ref_buffer->start(), ref_buffer->length()));
+}
+
+
+static int ReadData(
+ LogDynamicBuffer* dynabuf, int start_pos, i::Vector<char>* buffer) {
+ return dynabuf->Read(start_pos, buffer->start(), buffer->length());
+}
+
+
+// Helper function used by CHECK_EQ to compare Vectors.
+static inline void CheckEqualsHelper(const char* file, int line,
+ const char* expected_source,
+ const Vector<char>& expected,
+ const char* value_source,
+ const Vector<char>& value) {
+ if (expected.length() != value.length()) {
+ V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n"
+ "# Vectors lengths differ: %d expected, %d found",
+ expected_source, value_source,
+ expected.length(), value.length());
+ }
+ if (strncmp(expected.start(), value.start(), expected.length()) != 0) {
+ V8_Fatal(file, line, "CHECK_EQ(%s, %s) failed\n"
+ "# Vectors contents differ:\n"
+ "# Expected: %.*s\n"
+ "# Found: %.*s",
+ expected_source, value_source,
+ expected.length(), expected.start(),
+ value.length(), value.start());
+ }
+}
+
+
+TEST(DynaBufSingleBlock) {
+ LogDynamicBuffer dynabuf(32, 32);
+ EmbeddedVector<char, 32> ref_buf;
+ WriteData(&dynabuf, &ref_buf);
+ EmbeddedVector<char, 32> buf;
+ CHECK_EQ(32, dynabuf.Read(0, buf.start(), buf.length()));
+ CHECK_EQ(32, ReadData(&dynabuf, 0, &buf));
+ CHECK_EQ(ref_buf, buf);
+
+ // Verify that we can't read and write past the end.
+ CHECK_EQ(0, dynabuf.Read(32, buf.start(), buf.length()));
+ CHECK_EQ(0, dynabuf.Write(buf.start(), buf.length()));
+}
+
+
+TEST(DynaBufCrossBlocks) {
+ LogDynamicBuffer dynabuf(32, 128);
+ EmbeddedVector<char, 48> ref_buf;
+ WriteData(&dynabuf, &ref_buf);
+ CHECK_EQ(48, dynabuf.Write(ref_buf.start(), ref_buf.length()));
+ // Verify that we can't write data when remaining buffer space isn't enough.
+ CHECK_EQ(0, dynabuf.Write(ref_buf.start(), ref_buf.length()));
+ EmbeddedVector<char, 48> buf;
+ CHECK_EQ(48, ReadData(&dynabuf, 0, &buf));
+ CHECK_EQ(ref_buf, buf);
+ CHECK_EQ(48, ReadData(&dynabuf, 48, &buf));
+ CHECK_EQ(ref_buf, buf);
+ CHECK_EQ(0, ReadData(&dynabuf, 48 * 2, &buf));
+}
+
+
+TEST(DynaBufReadTruncation) {
+ LogDynamicBuffer dynabuf(32, 128);
+ EmbeddedVector<char, 128> ref_buf;
+ WriteData(&dynabuf, &ref_buf);
+ EmbeddedVector<char, 128> buf;
+ CHECK_EQ(128, ReadData(&dynabuf, 0, &buf));
+ CHECK_EQ(ref_buf, buf);
+ // Try to read near the end with a buffer larger than remaining data size.
+ EmbeddedVector<char, 48> tail_buf;
+ CHECK_EQ(32, ReadData(&dynabuf, 128 - 32, &tail_buf));
+ CHECK_EQ(ref_buf.SubVector(128 - 32, 128), tail_buf.SubVector(0, 32));
+}
+
+#endif // ENABLE_LOGGING_AND_PROFILING
« src/log-utils.cc ('K') | « test/cctest/test-log.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698