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

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

Issue 23519010: cleanup cctest generally and remove ctest::context (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: arm fix Created 7 years, 3 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-assembler-arm.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;
34 CcTest::InitializationState CcTest::initialization_state_ = kUnset; 36 bool CcTest::initialize_called_ = false;
37 bool CcTest::isolate_used_ = false;
38 v8::Isolate* CcTest::isolate_ = NULL;
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, bool initialize) 42 const char* dependency, bool enabled, bool initialize)
38 : callback_(callback), name_(name), dependency_(dependency), 43 : callback_(callback), name_(name), dependency_(dependency),
39 enabled_(enabled), initialize_(initialize), prev_(last_) { 44 enabled_(enabled), initialize_(initialize), prev_(last_) {
40 // 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).
41 char *basename = strrchr(const_cast<char *>(file), '/'); 46 char *basename = strrchr(const_cast<char *>(file), '/');
42 if (!basename) { 47 if (!basename) {
43 basename = strrchr(const_cast<char *>(file), '\\'); 48 basename = strrchr(const_cast<char *>(file), '\\');
44 } 49 }
(...skipping 10 matching lines...) Expand all
55 prev_ = last_; 60 prev_ = last_;
56 last_ = this; 61 last_ = this;
57 } 62 }
58 63
59 64
60 void CcTest::Run() { 65 void CcTest::Run() {
61 if (!initialize_) { 66 if (!initialize_) {
62 CHECK(initialization_state_ != kInitialized); 67 CHECK(initialization_state_ != kInitialized);
63 initialization_state_ = kUnintialized; 68 initialization_state_ = kUnintialized;
64 // TODO(dcarney): Remove this when default isolate is gone. 69 // TODO(dcarney): Remove this when default isolate is gone.
65 if (default_isolate_ == NULL) { 70 if (isolate_ == NULL) {
66 default_isolate_ = v8::Isolate::GetCurrent(); 71 isolate_ = v8::Isolate::GetCurrent();
67 } 72 }
68 } else { 73 } else {
69 CHECK(initialization_state_ != kUnintialized); 74 CHECK(initialization_state_ != kUnintialized);
70 initialization_state_ = kInitialized; 75 initialization_state_ = kInitialized;
71 i::Isolate::SetCrashIfDefaultIsolateInitialized(); 76 i::Isolate::SetCrashIfDefaultIsolateInitialized();
72 if (default_isolate_ == NULL) { 77 if (isolate_ == NULL) {
73 default_isolate_ = v8::Isolate::New(); 78 isolate_ = v8::Isolate::New();
74 } 79 }
75 default_isolate_->Enter(); 80 isolate_->Enter();
76 } 81 }
77 callback_(); 82 callback_();
78 if (initialize_) { 83 if (initialize_) {
79 default_isolate_->Exit(); 84 isolate_->Exit();
80 } 85 }
81 } 86 }
82 87
83 88
84 v8::Persistent<v8::Context> CcTest::context_; 89 v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions,
85 90 v8::Isolate* isolate) {
86 91 const char* extension_names[kMaxExtensions];
87 void CcTest::InitializeVM(CcTestExtensionFlags extensions) { 92 int extension_count = 0;
88 const char* extension_names[kMaxExtensions]; 93 #define CHECK_EXTENSION_FLAG(Name, Id) \
89 int extension_count = 0; 94 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
90 #define CHECK_EXTENSION_FLAG(Name, Id) \ 95 EXTENSION_LIST(CHECK_EXTENSION_FLAG)
91 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; 96 #undef CHECK_EXTENSION_FLAG
92 EXTENSION_LIST(CHECK_EXTENSION_FLAG)
93 #undef CHECK_EXTENSION_FLAG
94 v8::Isolate* isolate = CcTest::isolate();
95 if (context_.IsEmpty()) {
96 v8::HandleScope scope(isolate);
97 v8::ExtensionConfiguration config(extension_count, extension_names); 97 v8::ExtensionConfiguration config(extension_count, extension_names);
98 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); 98 v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
99 context_.Reset(isolate, context); 99 CHECK(!context.IsEmpty());
100 } 100 return context;
101 {
102 v8::HandleScope scope(isolate);
103 v8::Local<v8::Context> context =
104 v8::Local<v8::Context>::New(isolate, context_);
105 context->Enter();
106 }
107 } 101 }
108 102
109 103
110 static void PrintTestList(CcTest* current) { 104 static void PrintTestList(CcTest* current) {
111 if (current == NULL) return; 105 if (current == NULL) return;
112 PrintTestList(current->prev()); 106 PrintTestList(current->prev());
113 if (current->dependency() != NULL) { 107 if (current->dependency() != NULL) {
114 printf("%s/%s<%s\n", 108 printf("%s/%s<%s\n",
115 current->file(), current->name(), current->dependency()); 109 current->file(), current->name(), current->dependency());
116 } else { 110 } else {
117 printf("%s/%s<\n", current->file(), current->name()); 111 printf("%s/%s<\n", current->file(), current->name());
118 } 112 }
119 } 113 }
120 114
121 115
122 v8::Isolate* CcTest::default_isolate_ = NULL;
123
124
125 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 116 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
126 virtual void* Allocate(size_t length) { return malloc(length); } 117 virtual void* Allocate(size_t length) { return malloc(length); }
127 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } 118 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
128 virtual void Free(void* data, size_t length) { free(data); } 119 virtual void Free(void* data, size_t length) { free(data); }
129 // TODO(dslomov): Remove when v8:2823 is fixed. 120 // TODO(dslomov): Remove when v8:2823 is fixed.
130 virtual void Free(void* data) { UNREACHABLE(); } 121 virtual void Free(void* data) { UNREACHABLE(); }
131 }; 122 };
132 123
133 124
134 static void SuggestTestHarness(int tests) { 125 static void SuggestTestHarness(int tests) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 181 }
191 } 182 }
192 if (print_run_count && tests_run != 1) 183 if (print_run_count && tests_run != 1)
193 printf("Ran %i tests.\n", tests_run); 184 printf("Ran %i tests.\n", tests_run);
194 v8::V8::Dispose(); 185 v8::V8::Dispose();
195 return 0; 186 return 0;
196 } 187 }
197 188
198 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; 189 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL;
199 int RegisterThreadedTest::count_ = 0; 190 int RegisterThreadedTest::count_ = 0;
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698