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

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

Issue 390004: Fix warnings on Win64. (Closed)
Patch Set: Created 11 years, 1 month 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
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 functions from log.h 3 // Tests of logging functions from log.h
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #ifdef __linux__ 7 #ifdef __linux__
8 #include <math.h> 8 #include <math.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <signal.h> 10 #include <signal.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 #endif // __linux__ 12 #endif // __linux__
13 13
14 #include "v8.h" 14 #include "v8.h"
15 #include "log.h" 15 #include "log.h"
16 #include "v8threads.h" 16 #include "v8threads.h"
17 #include "cctest.h" 17 #include "cctest.h"
18 18
19 using v8::internal::Address; 19 using v8::internal::Address;
20 using v8::internal::EmbeddedVector; 20 using v8::internal::EmbeddedVector;
21 using v8::internal::Logger; 21 using v8::internal::Logger;
22 using v8::internal::StrLength;
22 23
23 namespace i = v8::internal; 24 namespace i = v8::internal;
24 25
25 static void SetUp() { 26 static void SetUp() {
26 // Log to memory buffer. 27 // Log to memory buffer.
27 i::FLAG_logfile = "*"; 28 i::FLAG_logfile = "*";
28 i::FLAG_log = true; 29 i::FLAG_log = true;
29 Logger::Setup(); 30 Logger::Setup();
30 } 31 }
31 32
(...skipping 16 matching lines...) Expand all
48 SetUp(); 49 SetUp();
49 Logger::StringEvent("aaa", "bbb"); 50 Logger::StringEvent("aaa", "bbb");
50 Logger::StringEvent("cccc", "dddd"); 51 Logger::StringEvent("cccc", "dddd");
51 CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0)); 52 CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
52 char log_lines[100]; 53 char log_lines[100];
53 memset(log_lines, 0, sizeof(log_lines)); 54 memset(log_lines, 0, sizeof(log_lines));
54 // Requesting data size which is smaller than first log message length. 55 // Requesting data size which is smaller than first log message length.
55 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, 3)); 56 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, 3));
56 // See Logger::StringEvent. 57 // See Logger::StringEvent.
57 const char* line_1 = "aaa,\"bbb\"\n"; 58 const char* line_1 = "aaa,\"bbb\"\n";
58 const int line_1_len = strlen(line_1); 59 const int line_1_len = StrLength(line_1);
59 // Still smaller than log message length. 60 // Still smaller than log message length.
60 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, line_1_len - 1)); 61 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, line_1_len - 1));
61 // The exact size. 62 // The exact size.
62 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len)); 63 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len));
63 CHECK_EQ(line_1, log_lines); 64 CHECK_EQ(line_1, log_lines);
64 memset(log_lines, 0, sizeof(log_lines)); 65 memset(log_lines, 0, sizeof(log_lines));
65 // A bit more than the first line length. 66 // A bit more than the first line length.
66 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len + 3)); 67 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len + 3));
67 log_lines[line_1_len] = '\0'; 68 log_lines[line_1_len] = '\0';
68 CHECK_EQ(line_1, log_lines); 69 CHECK_EQ(line_1, log_lines);
69 memset(log_lines, 0, sizeof(log_lines)); 70 memset(log_lines, 0, sizeof(log_lines));
70 const char* line_2 = "cccc,\"dddd\"\n"; 71 const char* line_2 = "cccc,\"dddd\"\n";
71 const int line_2_len = strlen(line_2); 72 const int line_2_len = StrLength(line_2);
72 // Now start with line_2 beginning. 73 // Now start with line_2 beginning.
73 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0)); 74 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0));
74 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 3)); 75 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 3));
75 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, line_2_len - 1)); 76 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, line_2_len - 1));
76 CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len)); 77 CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len));
77 CHECK_EQ(line_2, log_lines); 78 CHECK_EQ(line_2, log_lines);
78 memset(log_lines, 0, sizeof(log_lines)); 79 memset(log_lines, 0, sizeof(log_lines));
79 CHECK_EQ(line_2_len, 80 CHECK_EQ(line_2_len,
80 Logger::GetLogLines(line_1_len, log_lines, line_2_len + 3)); 81 Logger::GetLogLines(line_1_len, log_lines, line_2_len + 3));
81 CHECK_EQ(line_2, log_lines); 82 CHECK_EQ(line_2, log_lines);
82 memset(log_lines, 0, sizeof(log_lines)); 83 memset(log_lines, 0, sizeof(log_lines));
83 // Now get entire buffer contents. 84 // Now get entire buffer contents.
84 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n"; 85 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
85 const int all_lines_len = strlen(all_lines); 86 const int all_lines_len = StrLength(all_lines);
86 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len)); 87 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len));
87 CHECK_EQ(all_lines, log_lines); 88 CHECK_EQ(all_lines, log_lines);
88 memset(log_lines, 0, sizeof(log_lines)); 89 memset(log_lines, 0, sizeof(log_lines));
89 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len + 3)); 90 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len + 3));
90 CHECK_EQ(all_lines, log_lines); 91 CHECK_EQ(all_lines, log_lines);
91 memset(log_lines, 0, sizeof(log_lines)); 92 memset(log_lines, 0, sizeof(log_lines));
92 TearDown(); 93 TearDown();
93 } 94 }
94 95
95 96
96 static int GetLogLines(int start_pos, i::Vector<char>* buffer) { 97 static int GetLogLines(int start_pos, i::Vector<char>* buffer) {
97 return Logger::GetLogLines(start_pos, buffer->start(), buffer->length()); 98 return Logger::GetLogLines(start_pos, buffer->start(), buffer->length());
98 } 99 }
99 100
100 101
101 TEST(BeyondWritePosition) { 102 TEST(BeyondWritePosition) {
102 SetUp(); 103 SetUp();
103 Logger::StringEvent("aaa", "bbb"); 104 Logger::StringEvent("aaa", "bbb");
104 Logger::StringEvent("cccc", "dddd"); 105 Logger::StringEvent("cccc", "dddd");
105 // See Logger::StringEvent. 106 // See Logger::StringEvent.
106 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n"; 107 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
107 const int all_lines_len = strlen(all_lines); 108 const int all_lines_len = StrLength(all_lines);
108 EmbeddedVector<char, 100> buffer; 109 EmbeddedVector<char, 100> buffer;
109 const int beyond_write_pos = all_lines_len; 110 const int beyond_write_pos = all_lines_len;
110 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos, buffer.start(), 1)); 111 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos, buffer.start(), 1));
111 CHECK_EQ(0, GetLogLines(beyond_write_pos, &buffer)); 112 CHECK_EQ(0, GetLogLines(beyond_write_pos, &buffer));
112 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 1, buffer.start(), 1)); 113 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 1, buffer.start(), 1));
113 CHECK_EQ(0, GetLogLines(beyond_write_pos + 1, &buffer)); 114 CHECK_EQ(0, GetLogLines(beyond_write_pos + 1, &buffer));
114 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 100, buffer.start(), 1)); 115 CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 100, buffer.start(), 1));
115 CHECK_EQ(0, GetLogLines(beyond_write_pos + 100, &buffer)); 116 CHECK_EQ(0, GetLogLines(beyond_write_pos + 100, &buffer));
116 CHECK_EQ(0, Logger::GetLogLines(10 * 1024 * 1024, buffer.start(), 1)); 117 CHECK_EQ(0, Logger::GetLogLines(10 * 1024 * 1024, buffer.start(), 1));
117 CHECK_EQ(0, GetLogLines(10 * 1024 * 1024, &buffer)); 118 CHECK_EQ(0, GetLogLines(10 * 1024 * 1024, &buffer));
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 431
431 432
432 // Test for issue http://crbug.com/23768 in Chromium. 433 // Test for issue http://crbug.com/23768 in Chromium.
433 // Heap can contain scripts with already disposed external sources. 434 // Heap can contain scripts with already disposed external sources.
434 // We need to verify that LogCompiledFunctions doesn't crash on them. 435 // We need to verify that LogCompiledFunctions doesn't crash on them.
435 namespace { 436 namespace {
436 437
437 class SimpleExternalString : public v8::String::ExternalStringResource { 438 class SimpleExternalString : public v8::String::ExternalStringResource {
438 public: 439 public:
439 explicit SimpleExternalString(const char* source) 440 explicit SimpleExternalString(const char* source)
440 : utf_source_(strlen(source)) { 441 : utf_source_(StrLength(source)) {
441 for (int i = 0; i < utf_source_.length(); ++i) 442 for (int i = 0; i < utf_source_.length(); ++i)
442 utf_source_[i] = source[i]; 443 utf_source_[i] = source[i];
443 } 444 }
444 virtual ~SimpleExternalString() {} 445 virtual ~SimpleExternalString() {}
445 virtual size_t length() const { return utf_source_.length(); } 446 virtual size_t length() const { return utf_source_.length(); }
446 virtual const uint16_t* data() const { return utf_source_.start(); } 447 virtual const uint16_t* data() const { return utf_source_.start(); }
447 private: 448 private:
448 i::ScopedVector<uint16_t> utf_source_; 449 i::ScopedVector<uint16_t> utf_source_;
449 }; 450 };
450 451
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // Make sure that the test doesn't operate on a bogus log. 586 // Make sure that the test doesn't operate on a bogus log.
586 CHECK_GT(max_entities, 0); 587 CHECK_GT(max_entities, 0);
587 CHECK_GT(bounds.GetMinAddr(), 0); 588 CHECK_GT(bounds.GetMinAddr(), 0);
588 CHECK_GT(bounds.GetMaxAddr(), bounds.GetMinAddr()); 589 CHECK_GT(bounds.GetMaxAddr(), bounds.GetMinAddr());
589 590
590 entities = i::NewArray<CodeEntityInfo>(max_entities); 591 entities = i::NewArray<CodeEntityInfo>(max_entities);
591 for (int i = 0; i < max_entities; ++i) { 592 for (int i = 0; i < max_entities; ++i) {
592 entities[i] = NULL; 593 entities[i] = NULL;
593 } 594 }
594 const size_t map_length = bounds.Length(); 595 const size_t map_length = bounds.Length();
595 entities_map = i::NewArray<int>(map_length); 596 entities_map = i::NewArray<int>(static_cast<int>(map_length));
596 for (size_t i = 0; i < map_length; ++i) { 597 for (size_t i = 0; i < map_length; ++i) {
597 entities_map[i] = -1; 598 entities_map[i] = -1;
598 } 599 }
599 } 600 }
600 601
601 bool HasIndexForAddress(Address addr) { 602 bool HasIndexForAddress(Address addr) {
602 return bounds.Contains(addr); 603 return bounds.Contains(addr);
603 } 604 }
604 605
605 size_t GetIndexForAddress(Address addr) { 606 size_t GetIndexForAddress(Address addr) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // Pass 2: Fill in code entries data. 762 // Pass 2: Fill in code entries data.
762 ParserCycle(start, end, result, 763 ParserCycle(start, end, result,
763 Pass2CodeCreation, Pass2CodeDelete, Pass2CodeMove); 764 Pass2CodeCreation, Pass2CodeDelete, Pass2CodeMove);
764 } 765 }
765 766
766 767
767 static inline void PrintCodeEntityInfo(CodeEntityInfo entity) { 768 static inline void PrintCodeEntityInfo(CodeEntityInfo entity) {
768 const int max_len = 50; 769 const int max_len = 50;
769 if (entity != NULL) { 770 if (entity != NULL) {
770 char* eol = strchr(entity, '\n'); 771 char* eol = strchr(entity, '\n');
771 int len = eol - entity; 772 int len = static_cast<int>(eol - entity);
772 len = len <= max_len ? len : max_len; 773 len = len <= max_len ? len : max_len;
773 printf("%-*.*s ", max_len, len, entity); 774 printf("%-*.*s ", max_len, len, entity);
774 } else { 775 } else {
775 printf("%*s", max_len + 1, ""); 776 printf("%*s", max_len + 1, "");
776 } 777 }
777 } 778 }
778 779
779 780
780 static void PrintCodeEntitiesInfo( 781 static void PrintCodeEntitiesInfo(
781 bool is_equal, Address addr, 782 bool is_equal, Address addr,
782 CodeEntityInfo l_entity, CodeEntityInfo r_entity) { 783 CodeEntityInfo l_entity, CodeEntityInfo r_entity) {
783 printf("%c %p ", is_equal ? ' ' : '*', addr); 784 printf("%c %p ", is_equal ? ' ' : '*', addr);
784 PrintCodeEntityInfo(l_entity); 785 PrintCodeEntityInfo(l_entity);
785 PrintCodeEntityInfo(r_entity); 786 PrintCodeEntityInfo(r_entity);
786 printf("\n"); 787 printf("\n");
787 } 788 }
788 789
789 790
790 static inline int StrChrLen(const char* s, char c) { 791 static inline int StrChrLen(const char* s, char c) {
791 return strchr(s, c) - s; 792 return static_cast<int>(strchr(s, c) - s);
792 } 793 }
793 794
794 795
795 static bool AreFuncSizesEqual(CodeEntityInfo ref_s, CodeEntityInfo new_s) { 796 static bool AreFuncSizesEqual(CodeEntityInfo ref_s, CodeEntityInfo new_s) {
796 int ref_len = StrChrLen(ref_s, ','); 797 int ref_len = StrChrLen(ref_s, ',');
797 int new_len = StrChrLen(new_s, ','); 798 int new_len = StrChrLen(new_s, ',');
798 return ref_len == new_len && strncmp(ref_s, new_s, ref_len) == 0; 799 return ref_len == new_len && strncmp(ref_s, new_s, ref_len) == 0;
799 } 800 }
800 801
801 802
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 // Make sure that all log data is written prior crash due to CHECK failure. 933 // Make sure that all log data is written prior crash due to CHECK failure.
933 fflush(stdout); 934 fflush(stdout);
934 CHECK(results_equal); 935 CHECK(results_equal);
935 936
936 env->Exit(); 937 env->Exit();
937 Logger::TearDown(); 938 Logger::TearDown();
938 i::FLAG_always_compact = saved_always_compact; 939 i::FLAG_always_compact = saved_always_compact;
939 } 940 }
940 941
941 #endif // ENABLE_LOGGING_AND_PROFILING 942 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698