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

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

Issue 146213004: A64: Synchronize with r16849. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-accessors.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 enum InitializationState {kUnset, kUnintialized, kInitialized};
33 static InitializationState initialization_state_ = kUnset;
32 34
33 CcTest* CcTest::last_ = NULL; 35 CcTest* CcTest::last_ = NULL;
36 bool CcTest::initialize_called_ = false;
37 bool CcTest::isolate_used_ = false;
38 v8::Isolate* CcTest::isolate_ = NULL;
34 39
35 40
36 CcTest::CcTest(TestFunction* callback, const char* file, const char* name, 41 CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
37 const char* dependency, bool enabled) 42 const char* dependency, bool enabled, bool initialize)
38 : callback_(callback), name_(name), dependency_(dependency), prev_(last_) { 43 : callback_(callback), name_(name), dependency_(dependency),
44 enabled_(enabled), initialize_(initialize), prev_(last_) {
39 // Find the base name of this test (const_cast required on Windows). 45 // Find the base name of this test (const_cast required on Windows).
40 char *basename = strrchr(const_cast<char *>(file), '/'); 46 char *basename = strrchr(const_cast<char *>(file), '/');
41 if (!basename) { 47 if (!basename) {
42 basename = strrchr(const_cast<char *>(file), '\\'); 48 basename = strrchr(const_cast<char *>(file), '\\');
43 } 49 }
44 if (!basename) { 50 if (!basename) {
45 basename = v8::internal::StrDup(file); 51 basename = v8::internal::StrDup(file);
46 } else { 52 } else {
47 basename = v8::internal::StrDup(basename + 1); 53 basename = v8::internal::StrDup(basename + 1);
48 } 54 }
49 // Drop the extension, if there is one. 55 // Drop the extension, if there is one.
50 char *extension = strrchr(basename, '.'); 56 char *extension = strrchr(basename, '.');
51 if (extension) *extension = 0; 57 if (extension) *extension = 0;
52 // Install this test in the list of tests 58 // Install this test in the list of tests
53 file_ = basename; 59 file_ = basename;
54 enabled_ = enabled;
55 prev_ = last_; 60 prev_ = last_;
56 last_ = this; 61 last_ = this;
57 } 62 }
58 63
59 64
60 v8::Persistent<v8::Context> CcTest::context_; 65 void CcTest::Run() {
61 66 if (!initialize_) {
62 67 CHECK(initialization_state_ != kInitialized);
63 void CcTest::InitializeVM(CcTestExtensionFlags extensions) { 68 initialization_state_ = kUnintialized;
64 const char* extension_names[kMaxExtensions]; 69 // TODO(dcarney): Remove this when default isolate is gone.
65 int extension_count = 0; 70 if (isolate_ == NULL) {
66 #define CHECK_EXTENSION_FLAG(Name, Id) \ 71 isolate_ = v8::Isolate::GetCurrent();
67 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; 72 }
68 EXTENSION_LIST(CHECK_EXTENSION_FLAG) 73 } else {
69 #undef CHECK_EXTENSION_FLAG 74 CHECK(initialization_state_ != kUnintialized);
70 v8::Isolate* isolate = default_isolate(); 75 initialization_state_ = kInitialized;
71 if (context_.IsEmpty()) { 76 i::Isolate::SetCrashIfDefaultIsolateInitialized();
72 v8::HandleScope scope(isolate); 77 if (isolate_ == NULL) {
73 v8::ExtensionConfiguration config(extension_count, extension_names); 78 isolate_ = v8::Isolate::New();
74 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); 79 }
75 context_.Reset(isolate, context); 80 isolate_->Enter();
76 } 81 }
77 { 82 callback_();
78 v8::HandleScope scope(isolate); 83 if (initialize_) {
79 v8::Local<v8::Context> context = 84 isolate_->Exit();
80 v8::Local<v8::Context>::New(isolate, context_);
81 context->Enter();
82 } 85 }
83 } 86 }
84 87
85 88
89 v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions,
90 v8::Isolate* isolate) {
91 const char* extension_names[kMaxExtensions];
92 int extension_count = 0;
93 #define CHECK_EXTENSION_FLAG(Name, Id) \
94 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
95 EXTENSION_LIST(CHECK_EXTENSION_FLAG)
96 #undef CHECK_EXTENSION_FLAG
97 v8::ExtensionConfiguration config(extension_count, extension_names);
98 v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
99 CHECK(!context.IsEmpty());
100 return context;
101 }
102
103
86 static void PrintTestList(CcTest* current) { 104 static void PrintTestList(CcTest* current) {
87 if (current == NULL) return; 105 if (current == NULL) return;
88 PrintTestList(current->prev()); 106 PrintTestList(current->prev());
89 if (current->dependency() != NULL) { 107 if (current->dependency() != NULL) {
90 printf("%s/%s<%s\n", 108 printf("%s/%s<%s\n",
91 current->file(), current->name(), current->dependency()); 109 current->file(), current->name(), current->dependency());
92 } else { 110 } else {
93 printf("%s/%s<\n", current->file(), current->name()); 111 printf("%s/%s<\n", current->file(), current->name());
94 } 112 }
95 } 113 }
96 114
97 115
98 v8::Isolate* CcTest::default_isolate_;
99
100
101 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 116 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
102 virtual void* Allocate(size_t length) { return malloc(length); } 117 virtual void* Allocate(size_t length) { return malloc(length); }
103 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } 118 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
104 virtual void Free(void* data, size_t length) { free(data); } 119 virtual void Free(void* data, size_t length) { free(data); }
105 // TODO(dslomov): Remove when v8:2823 is fixed. 120 // TODO(dslomov): Remove when v8:2823 is fixed.
106 virtual void Free(void* data) { UNREACHABLE(); } 121 virtual void Free(void* data) { UNREACHABLE(); }
107 }; 122 };
108 123
109 124
110 static void SuggestTestHarness(int tests) { 125 static void SuggestTestHarness(int tests) {
111 if (tests == 0) return; 126 if (tests == 0) return;
112 printf("Running multiple tests in sequence is deprecated and may cause " 127 printf("Running multiple tests in sequence is deprecated and may cause "
113 "bogus failure. Consider using tools/run-tests.py instead.\n"); 128 "bogus failure. Consider using tools/run-tests.py instead.\n");
114 } 129 }
115 130
116 131
117 int main(int argc, char* argv[]) { 132 int main(int argc, char* argv[]) {
133 v8::V8::InitializeICU();
134
118 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); 135 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
119 136
120 CcTestArrayBufferAllocator array_buffer_allocator; 137 CcTestArrayBufferAllocator array_buffer_allocator;
121 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); 138 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
122 139
123 CcTest::set_default_isolate(v8::Isolate::GetCurrent());
124 CHECK(CcTest::default_isolate() != NULL);
125 int tests_run = 0; 140 int tests_run = 0;
126 bool print_run_count = true; 141 bool print_run_count = true;
127 for (int i = 1; i < argc; i++) { 142 for (int i = 1; i < argc; i++) {
128 char* arg = argv[i]; 143 char* arg = argv[i];
129 if (strcmp(arg, "--list") == 0) { 144 if (strcmp(arg, "--list") == 0) {
130 PrintTestList(CcTest::last()); 145 PrintTestList(CcTest::last());
131 print_run_count = false; 146 print_run_count = false;
132 147
133 } else { 148 } else {
134 char* arg_copy = v8::internal::StrDup(arg); 149 char* arg_copy = v8::internal::StrDup(arg);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 183 }
169 } 184 }
170 if (print_run_count && tests_run != 1) 185 if (print_run_count && tests_run != 1)
171 printf("Ran %i tests.\n", tests_run); 186 printf("Ran %i tests.\n", tests_run);
172 v8::V8::Dispose(); 187 v8::V8::Dispose();
173 return 0; 188 return 0;
174 } 189 }
175 190
176 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; 191 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL;
177 int RegisterThreadedTest::count_ = 0; 192 int RegisterThreadedTest::count_ = 0;
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-accessors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698