OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <v8.h> | 28 #include <v8.h> |
29 #include "cctest.h" | 29 #include "cctest.h" |
30 #include "debug.h" | 30 #include "debug.h" |
31 | 31 |
32 | 32 |
33 CcTest* CcTest::last_ = NULL; | 33 CcTest* CcTest::last_ = NULL; |
34 | 34 CcTest::InitializationState CcTest::initialization_state_ = kUnset; |
35 | 35 |
36 CcTest::CcTest(TestFunction* callback, const char* file, const char* name, | 36 CcTest::CcTest(TestFunction* callback, const char* file, const char* name, |
37 const char* dependency, bool enabled) | 37 const char* dependency, bool enabled, bool initialize) |
38 : callback_(callback), name_(name), dependency_(dependency), prev_(last_) { | 38 : callback_(callback), name_(name), dependency_(dependency), |
| 39 enabled_(enabled), initialize_(initialize), prev_(last_) { |
39 // Find the base name of this test (const_cast required on Windows). | 40 // Find the base name of this test (const_cast required on Windows). |
40 char *basename = strrchr(const_cast<char *>(file), '/'); | 41 char *basename = strrchr(const_cast<char *>(file), '/'); |
41 if (!basename) { | 42 if (!basename) { |
42 basename = strrchr(const_cast<char *>(file), '\\'); | 43 basename = strrchr(const_cast<char *>(file), '\\'); |
43 } | 44 } |
44 if (!basename) { | 45 if (!basename) { |
45 basename = v8::internal::StrDup(file); | 46 basename = v8::internal::StrDup(file); |
46 } else { | 47 } else { |
47 basename = v8::internal::StrDup(basename + 1); | 48 basename = v8::internal::StrDup(basename + 1); |
48 } | 49 } |
49 // Drop the extension, if there is one. | 50 // Drop the extension, if there is one. |
50 char *extension = strrchr(basename, '.'); | 51 char *extension = strrchr(basename, '.'); |
51 if (extension) *extension = 0; | 52 if (extension) *extension = 0; |
52 // Install this test in the list of tests | 53 // Install this test in the list of tests |
53 file_ = basename; | 54 file_ = basename; |
54 enabled_ = enabled; | |
55 prev_ = last_; | 55 prev_ = last_; |
56 last_ = this; | 56 last_ = this; |
57 } | 57 } |
58 | 58 |
59 | 59 |
| 60 void CcTest::Run() { |
| 61 if (!initialize_) { |
| 62 CHECK(initialization_state_ != kInitialized); |
| 63 initialization_state_ = kUnintialized; |
| 64 // TODO(dcarney): Remove this when default isolate is gone. |
| 65 if (default_isolate_ == NULL) { |
| 66 default_isolate_ = v8::Isolate::GetCurrent(); |
| 67 } |
| 68 } else { |
| 69 CHECK(initialization_state_ != kUnintialized); |
| 70 initialization_state_ = kInitialized; |
| 71 i::Isolate::SetCrashIfDefaultIsolateInitialized(); |
| 72 if (default_isolate_ == NULL) { |
| 73 default_isolate_ = v8::Isolate::New(); |
| 74 } |
| 75 default_isolate_->Enter(); |
| 76 } |
| 77 callback_(); |
| 78 if (initialize_) { |
| 79 default_isolate_->Exit(); |
| 80 } |
| 81 } |
| 82 |
| 83 |
60 v8::Persistent<v8::Context> CcTest::context_; | 84 v8::Persistent<v8::Context> CcTest::context_; |
61 | 85 |
62 | 86 |
63 void CcTest::InitializeVM(CcTestExtensionFlags extensions) { | 87 void CcTest::InitializeVM(CcTestExtensionFlags extensions) { |
64 const char* extension_names[kMaxExtensions]; | 88 const char* extension_names[kMaxExtensions]; |
65 int extension_count = 0; | 89 int extension_count = 0; |
66 #define CHECK_EXTENSION_FLAG(Name, Id) \ | 90 #define CHECK_EXTENSION_FLAG(Name, Id) \ |
67 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; | 91 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; |
68 EXTENSION_LIST(CHECK_EXTENSION_FLAG) | 92 EXTENSION_LIST(CHECK_EXTENSION_FLAG) |
69 #undef CHECK_EXTENSION_FLAG | 93 #undef CHECK_EXTENSION_FLAG |
(...skipping 18 matching lines...) Expand all Loading... |
88 PrintTestList(current->prev()); | 112 PrintTestList(current->prev()); |
89 if (current->dependency() != NULL) { | 113 if (current->dependency() != NULL) { |
90 printf("%s/%s<%s\n", | 114 printf("%s/%s<%s\n", |
91 current->file(), current->name(), current->dependency()); | 115 current->file(), current->name(), current->dependency()); |
92 } else { | 116 } else { |
93 printf("%s/%s<\n", current->file(), current->name()); | 117 printf("%s/%s<\n", current->file(), current->name()); |
94 } | 118 } |
95 } | 119 } |
96 | 120 |
97 | 121 |
98 v8::Isolate* CcTest::default_isolate_; | 122 v8::Isolate* CcTest::default_isolate_ = NULL; |
99 | 123 |
100 | 124 |
101 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 125 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
102 virtual void* Allocate(size_t length) { return malloc(length); } | 126 virtual void* Allocate(size_t length) { return malloc(length); } |
103 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | 127 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
104 virtual void Free(void* data, size_t length) { free(data); } | 128 virtual void Free(void* data, size_t length) { free(data); } |
105 // TODO(dslomov): Remove when v8:2823 is fixed. | 129 // TODO(dslomov): Remove when v8:2823 is fixed. |
106 virtual void Free(void* data) { UNREACHABLE(); } | 130 virtual void Free(void* data) { UNREACHABLE(); } |
107 }; | 131 }; |
108 | 132 |
109 | 133 |
110 static void SuggestTestHarness(int tests) { | 134 static void SuggestTestHarness(int tests) { |
111 if (tests == 0) return; | 135 if (tests == 0) return; |
112 printf("Running multiple tests in sequence is deprecated and may cause " | 136 printf("Running multiple tests in sequence is deprecated and may cause " |
113 "bogus failure. Consider using tools/run-tests.py instead.\n"); | 137 "bogus failure. Consider using tools/run-tests.py instead.\n"); |
114 } | 138 } |
115 | 139 |
116 | 140 |
117 int main(int argc, char* argv[]) { | 141 int main(int argc, char* argv[]) { |
118 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 142 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
119 | 143 |
120 CcTestArrayBufferAllocator array_buffer_allocator; | 144 CcTestArrayBufferAllocator array_buffer_allocator; |
121 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); | 145 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); |
122 | 146 |
123 CcTest::set_default_isolate(v8::Isolate::GetCurrent()); | |
124 CHECK(CcTest::default_isolate() != NULL); | |
125 int tests_run = 0; | 147 int tests_run = 0; |
126 bool print_run_count = true; | 148 bool print_run_count = true; |
127 for (int i = 1; i < argc; i++) { | 149 for (int i = 1; i < argc; i++) { |
128 char* arg = argv[i]; | 150 char* arg = argv[i]; |
129 if (strcmp(arg, "--list") == 0) { | 151 if (strcmp(arg, "--list") == 0) { |
130 PrintTestList(CcTest::last()); | 152 PrintTestList(CcTest::last()); |
131 print_run_count = false; | 153 print_run_count = false; |
132 | 154 |
133 } else { | 155 } else { |
134 char* arg_copy = v8::internal::StrDup(arg); | 156 char* arg_copy = v8::internal::StrDup(arg); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 190 } |
169 } | 191 } |
170 if (print_run_count && tests_run != 1) | 192 if (print_run_count && tests_run != 1) |
171 printf("Ran %i tests.\n", tests_run); | 193 printf("Ran %i tests.\n", tests_run); |
172 v8::V8::Dispose(); | 194 v8::V8::Dispose(); |
173 return 0; | 195 return 0; |
174 } | 196 } |
175 | 197 |
176 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; | 198 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
177 int RegisterThreadedTest::count_ = 0; | 199 int RegisterThreadedTest::count_ = 0; |
OLD | NEW |