v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cctest.cc
Go to the documentation of this file.
1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27 
28 #include <v8.h>
29 #include "cctest.h"
30 
31 #include "print-extension.h"
32 #include "profiler-extension.h"
33 #include "trace-extension.h"
34 #include "debug.h"
35 
37 static InitializationState initialization_state_ = kUnset;
38 static bool disable_automatic_dispose_ = false;
39 
40 CcTest* CcTest::last_ = NULL;
41 bool CcTest::initialize_called_ = false;
42 bool CcTest::isolate_used_ = false;
43 v8::Isolate* CcTest::isolate_ = NULL;
44 
45 
46 CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
47  const char* dependency, bool enabled, bool initialize)
48  : callback_(callback), name_(name), dependency_(dependency),
49  enabled_(enabled), initialize_(initialize), prev_(last_) {
50  // Find the base name of this test (const_cast required on Windows).
51  char *basename = strrchr(const_cast<char *>(file), '/');
52  if (!basename) {
53  basename = strrchr(const_cast<char *>(file), '\\');
54  }
55  if (!basename) {
56  basename = v8::internal::StrDup(file);
57  } else {
58  basename = v8::internal::StrDup(basename + 1);
59  }
60  // Drop the extension, if there is one.
61  char *extension = strrchr(basename, '.');
62  if (extension) *extension = 0;
63  // Install this test in the list of tests
64  file_ = basename;
65  prev_ = last_;
66  last_ = this;
67 }
68 
69 
70 void CcTest::Run() {
71  if (!initialize_) {
72  CHECK(initialization_state_ != kInitialized);
73  initialization_state_ = kUnintialized;
74  CHECK(CcTest::isolate_ == NULL);
75  } else {
76  CHECK(initialization_state_ != kUnintialized);
77  initialization_state_ = kInitialized;
78  if (isolate_ == NULL) {
79  isolate_ = v8::Isolate::New();
80  }
81  isolate_->Enter();
82  }
83  callback_();
84  if (initialize_) {
85  isolate_->Exit();
86  }
87 }
88 
89 
91  v8::Isolate* isolate) {
92  const char* extension_names[kMaxExtensions];
93  int extension_count = 0;
94  #define CHECK_EXTENSION_FLAG(Name, Id) \
95  if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
97  #undef CHECK_EXTENSION_FLAG
98  v8::ExtensionConfiguration config(extension_count, extension_names);
99  v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
100  CHECK(!context.IsEmpty());
101  return context;
102 }
103 
104 
106  CHECK_EQ(kUnintialized, initialization_state_);
107  disable_automatic_dispose_ = true;
108 }
109 
110 
111 static void PrintTestList(CcTest* current) {
112  if (current == NULL) return;
113  PrintTestList(current->prev());
114  if (current->dependency() != NULL) {
115  printf("%s/%s<%s\n",
116  current->file(), current->name(), current->dependency());
117  } else {
118  printf("%s/%s<\n", current->file(), current->name());
119  }
120 }
121 
122 
124  virtual void* Allocate(size_t length) { return malloc(length); }
125  virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
126  virtual void Free(void* data, size_t length) { free(data); }
127  // TODO(dslomov): Remove when v8:2823 is fixed.
128  virtual void Free(void* data) { UNREACHABLE(); }
129 };
130 
131 
132 static void SuggestTestHarness(int tests) {
133  if (tests == 0) return;
134  printf("Running multiple tests in sequence is deprecated and may cause "
135  "bogus failure. Consider using tools/run-tests.py instead.\n");
136 }
137 
138 
139 int main(int argc, char* argv[]) {
142 
143  v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
144 
145  CcTestArrayBufferAllocator array_buffer_allocator;
146  v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
147 
148  i::PrintExtension print_extension;
149  v8::RegisterExtension(&print_extension);
150  i::ProfilerExtension profiler_extension;
151  v8::RegisterExtension(&profiler_extension);
152  i::TraceExtension trace_extension;
153  v8::RegisterExtension(&trace_extension);
154 
155  int tests_run = 0;
156  bool print_run_count = true;
157  for (int i = 1; i < argc; i++) {
158  char* arg = argv[i];
159  if (strcmp(arg, "--list") == 0) {
160  PrintTestList(CcTest::last());
161  print_run_count = false;
162 
163  } else {
164  char* arg_copy = v8::internal::StrDup(arg);
165  char* testname = strchr(arg_copy, '/');
166  if (testname) {
167  // Split the string in two by nulling the slash and then run
168  // exact matches.
169  *testname = 0;
170  char* file = arg_copy;
171  char* name = testname + 1;
172  CcTest* test = CcTest::last();
173  while (test != NULL) {
174  if (test->enabled()
175  && strcmp(test->file(), file) == 0
176  && strcmp(test->name(), name) == 0) {
177  SuggestTestHarness(tests_run++);
178  test->Run();
179  }
180  test = test->prev();
181  }
182 
183  } else {
184  // Run all tests with the specified file or test name.
185  char* file_or_name = arg_copy;
186  CcTest* test = CcTest::last();
187  while (test != NULL) {
188  if (test->enabled()
189  && (strcmp(test->file(), file_or_name) == 0
190  || strcmp(test->name(), file_or_name) == 0)) {
191  SuggestTestHarness(tests_run++);
192  test->Run();
193  }
194  test = test->prev();
195  }
196  }
197  v8::internal::DeleteArray<char>(arg_copy);
198  }
199  }
200  if (print_run_count && tests_run != 1)
201  printf("Ran %i tests.\n", tests_run);
203  if (!disable_automatic_dispose_) v8::V8::Dispose();
204  return 0;
205 }
206 
207 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL;
208 int RegisterThreadedTest::count_ = 0;
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define CHECK_EQ(expected, value)
Definition: checks.h:252
void Exit()
Definition: api.cc:6609
CcTest(TestFunction *callback, const char *file, const char *name, const char *dependency, bool enabled, bool initialize)
Definition: cctest.cc:46
void V8_EXPORT RegisterExtension(Extension *extension)
Definition: api.cc:439
const char * file()
Definition: cctest.h:91
static void DisableAutomaticDispose()
Definition: cctest.cc:105
InitializationState
Definition: cctest.cc:36
const char * dependency()
Definition: cctest.h:93
#define CHECK(condition)
Definition: checks.h:75
static void SetCrashIfDefaultIsolateInitialized()
Definition: isolate.cc:182
static bool Dispose()
Definition: api.cc:5028
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
static v8::Local< v8::Context > NewContext(CcTestExtensionFlags extensions, v8::Isolate *isolate=CcTest::isolate())
Definition: cctest.cc:90
static void SetArrayBufferAllocator(ArrayBuffer::Allocator *allocator)
Definition: api.cc:5018
#define UNREACHABLE()
Definition: checks.h:52
void Run()
Definition: cctest.cc:70
static Isolate * New()
Definition: api.cc:6586
void Enter()
Definition: api.cc:6603
#define EXTENSION_LIST(V)
Definition: cctest.h:61
Definition: cctest.cc:36
bool enabled()
Definition: cctest.h:94
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
Definition: api.cc:5188
static void TearDown()
Definition: cctest.h:133
int main(int argc, char *argv[])
Definition: cctest.cc:139
V8_INLINE bool IsEmpty() const
Definition: v8.h:248
const char * name()
Definition: cctest.h:92
static CcTest * last()
Definition: cctest.h:89
CcTest * prev()
Definition: cctest.h:90
static bool InitializeICU(const char *icu_data_file=NULL)
Definition: api.cc:5115
#define CHECK_EXTENSION_FLAG(Name, Id)
char * StrDup(const char *str)
Definition: allocation.cc:89
Definition: v8.h:124
Definition: cctest.h:83