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

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

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 | « src/x64/stub-cache-x64.cc ('k') | test/cctest/cctest.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 13 matching lines...) Expand all
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 #ifndef CCTEST_H_ 28 #ifndef CCTEST_H_
29 #define CCTEST_H_ 29 #define CCTEST_H_
30 30
31 #include "v8.h" 31 #include "v8.h"
32 32
33 #ifndef TEST 33 #ifndef TEST
34 #define TEST(Name) \ 34 #define TEST(Name) \
35 static void Test##Name(); \ 35 static void Test##Name(); \
36 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true); \ 36 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, true); \
37 static void Test##Name()
38 #endif
39
40 #ifndef UNINITIALIZED_TEST
41 #define UNINITIALIZED_TEST(Name) \
42 static void Test##Name(); \
43 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, false); \
37 static void Test##Name() 44 static void Test##Name()
38 #endif 45 #endif
39 46
40 #ifndef DEPENDENT_TEST 47 #ifndef DEPENDENT_TEST
41 #define DEPENDENT_TEST(Name, Dep) \ 48 #define DEPENDENT_TEST(Name, Dep) \
42 static void Test##Name(); \ 49 static void Test##Name(); \
43 CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true); \ 50 CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true, true); \
44 static void Test##Name() 51 static void Test##Name()
45 #endif 52 #endif
46 53
47 #ifndef DISABLED_TEST 54 #ifndef DISABLED_TEST
48 #define DISABLED_TEST(Name) \ 55 #define DISABLED_TEST(Name) \
49 static void Test##Name(); \ 56 static void Test##Name(); \
50 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false); \ 57 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false, true); \
51 static void Test##Name() 58 static void Test##Name()
52 #endif 59 #endif
53 60
54 #define EXTENSION_LIST(V) \ 61 #define EXTENSION_LIST(V) \
55 V(GC_EXTENSION, "v8/gc") \ 62 V(GC_EXTENSION, "v8/gc") \
56 V(PRINT_EXTENSION, "v8/print") \ 63 V(PRINT_EXTENSION, "v8/print") \
57 V(TRACE_EXTENSION, "v8/trace") 64 V(TRACE_EXTENSION, "v8/trace")
58 65
59 #define DEFINE_EXTENSION_ID(Name, Ident) Name##_ID, 66 #define DEFINE_EXTENSION_ID(Name, Ident) Name##_ID,
60 enum CcTestExtensionIds { 67 enum CcTestExtensionIds {
61 EXTENSION_LIST(DEFINE_EXTENSION_ID) 68 EXTENSION_LIST(DEFINE_EXTENSION_ID)
62 kMaxExtensions 69 kMaxExtensions
63 }; 70 };
64 #undef DEFINE_EXTENSION_ID 71 #undef DEFINE_EXTENSION_ID
65 72
66 typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags; 73 typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
67 #define DEFINE_EXTENSION_FLAG(Name, Ident) \ 74 #define DEFINE_EXTENSION_FLAG(Name, Ident) \
68 static const CcTestExtensionFlags Name(1 << Name##_ID); 75 static const CcTestExtensionFlags Name(1 << Name##_ID);
69 static const CcTestExtensionFlags NO_EXTENSIONS(0); 76 static const CcTestExtensionFlags NO_EXTENSIONS(0);
70 static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1); 77 static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1);
71 EXTENSION_LIST(DEFINE_EXTENSION_FLAG) 78 EXTENSION_LIST(DEFINE_EXTENSION_FLAG)
72 #undef DEFINE_EXTENSION_FLAG 79 #undef DEFINE_EXTENSION_FLAG
73 80
74 // Temporary macros for accessing current isolate and its subobjects.
75 // They provide better readability, especially when used a lot in the code.
76 #define HEAP (v8::internal::Isolate::Current()->heap())
77 81
78 class CcTest { 82 class CcTest {
79 public: 83 public:
80 typedef void (TestFunction)(); 84 typedef void (TestFunction)();
81 CcTest(TestFunction* callback, const char* file, const char* name, 85 CcTest(TestFunction* callback, const char* file, const char* name,
82 const char* dependency, bool enabled); 86 const char* dependency, bool enabled, bool initialize);
83 void Run() { callback_(); } 87 void Run();
84 static CcTest* last() { return last_; } 88 static CcTest* last() { return last_; }
85 CcTest* prev() { return prev_; } 89 CcTest* prev() { return prev_; }
86 const char* file() { return file_; } 90 const char* file() { return file_; }
87 const char* name() { return name_; } 91 const char* name() { return name_; }
88 const char* dependency() { return dependency_; } 92 const char* dependency() { return dependency_; }
89 bool enabled() { return enabled_; } 93 bool enabled() { return enabled_; }
90 static v8::Isolate* default_isolate() { return default_isolate_; }
91 94
92 static v8::Handle<v8::Context> env() { 95 static v8::Isolate* isolate() {
93 return v8::Local<v8::Context>::New(default_isolate_, context_); 96 isolate_used_ = true;
97 return isolate_;
94 } 98 }
95 99
96 static v8::Isolate* isolate() { return default_isolate_; }
97
98 static i::Isolate* i_isolate() { 100 static i::Isolate* i_isolate() {
99 return reinterpret_cast<i::Isolate*>(default_isolate_); 101 return reinterpret_cast<i::Isolate*>(isolate());
100 } 102 }
101 103
102 // Helper function to initialize the VM. 104 static i::Heap* heap() {
103 static void InitializeVM(CcTestExtensionFlags extensions = NO_EXTENSIONS); 105 return i_isolate()->heap();
106 }
107
108 // TODO(dcarney): Remove.
109 // This must be called first in a test.
110 static void InitializeVM() {
111 CHECK(!isolate_used_);
112 CHECK(!initialize_called_);
113 initialize_called_ = true;
114 v8::HandleScope handle_scope(CcTest::isolate());
115 v8::Context::New(CcTest::isolate())->Enter();
116 }
117
118 // Helper function to configure a context.
119 // Must be in a HandleScope.
120 static v8::Local<v8::Context> NewContext(
121 CcTestExtensionFlags extensions,
122 v8::Isolate* isolate = CcTest::isolate());
104 123
105 private: 124 private:
106 friend int main(int argc, char** argv); 125 friend int main(int argc, char** argv);
107 static void set_default_isolate(v8::Isolate* default_isolate) {
108 default_isolate_ = default_isolate;
109 }
110 TestFunction* callback_; 126 TestFunction* callback_;
111 const char* file_; 127 const char* file_;
112 const char* name_; 128 const char* name_;
113 const char* dependency_; 129 const char* dependency_;
114 bool enabled_; 130 bool enabled_;
131 bool initialize_;
115 CcTest* prev_; 132 CcTest* prev_;
116 static CcTest* last_; 133 static CcTest* last_;
117 static v8::Isolate* default_isolate_; 134 static v8::Isolate* isolate_;
118 static v8::Persistent<v8::Context> context_; 135 static bool initialize_called_;
136 static bool isolate_used_;
119 }; 137 };
120 138
121 // Switches between all the Api tests using the threading support. 139 // Switches between all the Api tests using the threading support.
122 // In order to get a surprising but repeatable pattern of thread 140 // In order to get a surprising but repeatable pattern of thread
123 // switching it has extra semaphores to control the order in which 141 // switching it has extra semaphores to control the order in which
124 // the tests alternate, not relying solely on the big V8 lock. 142 // the tests alternate, not relying solely on the big V8 lock.
125 // 143 //
126 // A test is augmented with calls to ApiTestFuzzer::Fuzz() in its 144 // A test is augmented with calls to ApiTestFuzzer::Fuzz() in its
127 // callbacks. This will have no effect when we are not running the 145 // callbacks. This will have no effect when we are not running the
128 // thread fuzzing test. In the thread fuzzing test it will 146 // thread fuzzing test. In the thread fuzzing test it will
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 static RegisterThreadedTest* first_; 222 static RegisterThreadedTest* first_;
205 static int count_; 223 static int count_;
206 CcTest::TestFunction* callback_; 224 CcTest::TestFunction* callback_;
207 RegisterThreadedTest* prev_; 225 RegisterThreadedTest* prev_;
208 const char* name_; 226 const char* name_;
209 }; 227 };
210 228
211 // A LocalContext holds a reference to a v8::Context. 229 // A LocalContext holds a reference to a v8::Context.
212 class LocalContext { 230 class LocalContext {
213 public: 231 public:
232 LocalContext(v8::Isolate* isolate,
233 v8::ExtensionConfiguration* extensions = 0,
234 v8::Handle<v8::ObjectTemplate> global_template =
235 v8::Handle<v8::ObjectTemplate>(),
236 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
237 Initialize(isolate, extensions, global_template, global_object);
238 }
239
214 LocalContext(v8::ExtensionConfiguration* extensions = 0, 240 LocalContext(v8::ExtensionConfiguration* extensions = 0,
215 v8::Handle<v8::ObjectTemplate> global_template = 241 v8::Handle<v8::ObjectTemplate> global_template =
216 v8::Handle<v8::ObjectTemplate>(), 242 v8::Handle<v8::ObjectTemplate>(),
217 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { 243 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
218 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 244 Initialize(CcTest::isolate(), extensions, global_template, global_object);
219 v8::HandleScope scope(isolate);
220 v8::Local<v8::Context> context = v8::Context::New(isolate,
221 extensions,
222 global_template,
223 global_object);
224 context_.Reset(isolate, context);
225 context->Enter();
226 // We can't do this later perhaps because of a fatal error.
227 isolate_ = context->GetIsolate();
228 } 245 }
229 246
230 virtual ~LocalContext() { 247 virtual ~LocalContext() {
231 v8::HandleScope scope(isolate_); 248 v8::HandleScope scope(isolate_);
232 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); 249 v8::Local<v8::Context>::New(isolate_, context_)->Exit();
233 context_.Dispose(); 250 context_.Dispose();
234 } 251 }
235 252
236 v8::Context* operator->() { 253 v8::Context* operator->() {
237 return *reinterpret_cast<v8::Context**>(&context_); 254 return *reinterpret_cast<v8::Context**>(&context_);
238 } 255 }
239 v8::Context* operator*() { return operator->(); } 256 v8::Context* operator*() { return operator->(); }
240 bool IsReady() { return !context_.IsEmpty(); } 257 bool IsReady() { return !context_.IsEmpty(); }
241 258
242 v8::Local<v8::Context> local() { 259 v8::Local<v8::Context> local() {
243 return v8::Local<v8::Context>::New(isolate_, context_); 260 return v8::Local<v8::Context>::New(isolate_, context_);
244 } 261 }
245 262
246 private: 263 private:
264 void Initialize(v8::Isolate* isolate,
265 v8::ExtensionConfiguration* extensions,
266 v8::Handle<v8::ObjectTemplate> global_template,
267 v8::Handle<v8::Value> global_object) {
268 v8::HandleScope scope(isolate);
269 v8::Local<v8::Context> context = v8::Context::New(isolate,
270 extensions,
271 global_template,
272 global_object);
273 context_.Reset(isolate, context);
274 context->Enter();
275 // We can't do this later perhaps because of a fatal error.
276 isolate_ = isolate;
277 }
278
247 v8::Persistent<v8::Context> context_; 279 v8::Persistent<v8::Context> context_;
248 v8::Isolate* isolate_; 280 v8::Isolate* isolate_;
249 }; 281 };
250 282
251 static inline v8::Local<v8::Value> v8_num(double x) { 283 static inline v8::Local<v8::Value> v8_num(double x) {
252 return v8::Number::New(x); 284 return v8::Number::New(x);
253 } 285 }
254 286
255 287
256 static inline v8::Local<v8::String> v8_str(const char* x) { 288 static inline v8::Local<v8::String> v8_str(const char* x) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { 334 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) {
303 int old_linear_size = static_cast<int>(space->limit() - space->top()); 335 int old_linear_size = static_cast<int>(space->limit() - space->top());
304 space->Free(space->top(), old_linear_size); 336 space->Free(space->top(), old_linear_size);
305 space->SetTop(space->limit(), space->limit()); 337 space->SetTop(space->limit(), space->limit());
306 space->ResetFreeList(); 338 space->ResetFreeList();
307 space->ClearStats(); 339 space->ClearStats();
308 } 340 }
309 341
310 342
311 #endif // ifndef CCTEST_H_ 343 #endif // ifndef CCTEST_H_
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/cctest/cctest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698