blob: b241f32a01ac000cccc9a32ded1e5bf83eccc2b0 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2008 the V8 project authors. All rights reserved.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002// 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>
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000029#include "cctest.h"
ager@chromium.org41826e72009-03-30 13:30:57 +000030#include "debug.h"
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000031
32
33CcTest* CcTest::last_ = NULL;
34
35
iposva@chromium.org245aa852009-02-10 00:49:54 +000036CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
37 const char* dependency, bool enabled)
38 : callback_(callback), name_(name), dependency_(dependency), prev_(last_) {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000039 // 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) {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000045 basename = v8::internal::StrDup(file);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000046 } else {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000047 basename = v8::internal::StrDup(basename + 1);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000048 }
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;
ager@chromium.org9258b6b2008-09-11 09:11:10 +000054 enabled_ = enabled;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000055 prev_ = last_;
56 last_ = this;
57}
58
59
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000060v8::Persistent<v8::Context> CcTest::context_;
61
62
63void CcTest::InitializeVM(CcTestExtensionFlags extensions) {
64 const char* extension_names[kMaxExtensions];
65 int extension_count = 0;
66#define CHECK_EXTENSION_FLAG(Name, Id) \
67 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
68 EXTENSION_LIST(CHECK_EXTENSION_FLAG)
69#undef CHECK_EXTENSION_FLAG
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +000070 v8::Isolate* isolate = default_isolate();
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000071 if (context_.IsEmpty()) {
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000072 v8::HandleScope scope(isolate);
73 v8::ExtensionConfiguration config(extension_count, extension_names);
74 v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +000075 context_.Reset(isolate, context);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000076 }
jkummerow@chromium.orgc1184022013-05-28 16:58:15 +000077 {
78 v8::HandleScope scope(isolate);
79 v8::Local<v8::Context> context =
80 v8::Local<v8::Context>::New(isolate, context_);
81 context->Enter();
82 }
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000083}
84
85
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000086static void PrintTestList(CcTest* current) {
87 if (current == NULL) return;
88 PrintTestList(current->prev());
iposva@chromium.org245aa852009-02-10 00:49:54 +000089 if (current->dependency() != NULL) {
90 printf("%s/%s<%s\n",
91 current->file(), current->name(), current->dependency());
92 } else {
93 printf("%s/%s<\n", current->file(), current->name());
94 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000095}
96
97
yangguo@chromium.org46a2a512013-01-18 16:29:40 +000098v8::Isolate* CcTest::default_isolate_;
99
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000100
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000101int main(int argc, char* argv[]) {
102 v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
ulan@chromium.org906e2fb2013-05-14 08:14:38 +0000103 v8::internal::FLAG_harmony_array_buffer = true;
104 v8::internal::FLAG_harmony_typed_arrays = true;
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000105 CcTest::set_default_isolate(v8::Isolate::GetCurrent());
106 CHECK(CcTest::default_isolate() != NULL);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000107 int tests_run = 0;
108 bool print_run_count = true;
109 for (int i = 1; i < argc; i++) {
110 char* arg = argv[i];
111 if (strcmp(arg, "--list") == 0) {
112 PrintTestList(CcTest::last());
113 print_run_count = false;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000114
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000115 } else {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000116 char* arg_copy = v8::internal::StrDup(arg);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000117 char* testname = strchr(arg_copy, '/');
118 if (testname) {
119 // Split the string in two by nulling the slash and then run
120 // exact matches.
121 *testname = 0;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000122 char* file = arg_copy;
123 char* name = testname + 1;
124 CcTest* test = CcTest::last();
125 while (test != NULL) {
126 if (test->enabled()
127 && strcmp(test->file(), file) == 0
128 && strcmp(test->name(), name) == 0) {
129 test->Run();
130 tests_run++;
131 }
132 test = test->prev();
133 }
134
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000135 } else {
136 // Run all tests with the specified file or test name.
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000137 char* file_or_name = arg_copy;
138 CcTest* test = CcTest::last();
139 while (test != NULL) {
140 if (test->enabled()
141 && (strcmp(test->file(), file_or_name) == 0
142 || strcmp(test->name(), file_or_name) == 0)) {
143 test->Run();
144 tests_run++;
145 }
146 test = test->prev();
147 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000148 }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000149 v8::internal::DeleteArray<char>(arg_copy);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000150 }
151 }
152 if (print_run_count && tests_run != 1)
153 printf("Ran %i tests.\n", tests_run);
ager@chromium.org41826e72009-03-30 13:30:57 +0000154 v8::V8::Dispose();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000155 return 0;
156}
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000157
158RegisterThreadedTest *RegisterThreadedTest::first_ = NULL;
159int RegisterThreadedTest::count_ = 0;