v8  3.14.5(node0.10.28)
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 #include "debug.h"
31 
32 
33 CcTest* CcTest::last_ = NULL;
34 
35 
36 CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
37  const char* dependency, bool enabled)
38  : callback_(callback), name_(name), dependency_(dependency), prev_(last_) {
39  // Find the base name of this test (const_cast required on Windows).
40  char *basename = strrchr(const_cast<char *>(file), '/');
41  if (!basename) {
42  basename = strrchr(const_cast<char *>(file), '\\');
43  }
44  if (!basename) {
45  basename = v8::internal::StrDup(file);
46  } else {
47  basename = v8::internal::StrDup(basename + 1);
48  }
49  // Drop the extension, if there is one.
50  char *extension = strrchr(basename, '.');
51  if (extension) *extension = 0;
52  // Install this test in the list of tests
53  file_ = basename;
54  enabled_ = enabled;
55  prev_ = last_;
56  last_ = this;
57 }
58 
59 
60 static void PrintTestList(CcTest* current) {
61  if (current == NULL) return;
62  PrintTestList(current->prev());
63  if (current->dependency() != NULL) {
64  printf("%s/%s<%s\n",
65  current->file(), current->name(), current->dependency());
66  } else {
67  printf("%s/%s<\n", current->file(), current->name());
68  }
69 }
70 
71 
72 int main(int argc, char* argv[]) {
74  int tests_run = 0;
75  bool print_run_count = true;
76  for (int i = 1; i < argc; i++) {
77  char* arg = argv[i];
78  if (strcmp(arg, "--list") == 0) {
79  PrintTestList(CcTest::last());
80  print_run_count = false;
81 
82  } else {
83  char* arg_copy = v8::internal::StrDup(arg);
84  char* testname = strchr(arg_copy, '/');
85  if (testname) {
86  // Split the string in two by nulling the slash and then run
87  // exact matches.
88  *testname = 0;
89  char* file = arg_copy;
90  char* name = testname + 1;
91  CcTest* test = CcTest::last();
92  while (test != NULL) {
93  if (test->enabled()
94  && strcmp(test->file(), file) == 0
95  && strcmp(test->name(), name) == 0) {
96  test->Run();
97  tests_run++;
98  }
99  test = test->prev();
100  }
101 
102  } else {
103  // Run all tests with the specified file or test name.
104  char* file_or_name = arg_copy;
105  CcTest* test = CcTest::last();
106  while (test != NULL) {
107  if (test->enabled()
108  && (strcmp(test->file(), file_or_name) == 0
109  || strcmp(test->name(), file_or_name) == 0)) {
110  test->Run();
111  tests_run++;
112  }
113  test = test->prev();
114  }
115  }
116  v8::internal::DeleteArray<char>(arg_copy);
117  }
118  }
119  if (print_run_count && tests_run != 1)
120  printf("Ran %i tests.\n", tests_run);
121  v8::V8::Dispose();
122  return 0;
123 }
124 
125 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL;
126 int RegisterThreadedTest::count_ = 0;
const char * file()
Definition: cctest.h:63
const char * dependency()
Definition: cctest.h:65
static bool Dispose()
Definition: api.cc:4303
void Run()
Definition: cctest.h:59
bool enabled()
Definition: cctest.h:66
int main(int argc, char *argv[])
Definition: cctest.cc:72
const char * name()
Definition: cctest.h:64
static CcTest * last()
Definition: cctest.h:61
CcTest * prev()
Definition: cctest.h:62
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit 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 SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available 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 MIPS FPU instructions if NULL
char * StrDup(const char *str)
Definition: allocation.cc:85
static int SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Definition: flags.cc:343
Definition: cctest.h:54
CcTest(TestFunction *callback, const char *file, const char *name, const char *dependency, bool enabled)
Definition: cctest.cc:36