ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2008 the V8 project authors. All rights reserved. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 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> |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 29 | #include "cctest.h" |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 30 | #include "debug.h" |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | CcTest* CcTest::last_ = NULL; |
| 34 | |
| 35 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 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_) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 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) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 45 | basename = v8::internal::StrDup(file); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 46 | } else { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 47 | basename = v8::internal::StrDup(basename + 1); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 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; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 54 | enabled_ = enabled; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 55 | prev_ = last_; |
| 56 | last_ = this; |
| 57 | } |
| 58 | |
| 59 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 60 | v8::Persistent<v8::Context> CcTest::context_; |
| 61 | |
| 62 | |
| 63 | void 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.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 70 | v8::Isolate* isolate = default_isolate(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 71 | if (context_.IsEmpty()) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 72 | 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.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 75 | context_.Reset(isolate, context); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 76 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 77 | { |
| 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.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 86 | static void PrintTestList(CcTest* current) { |
| 87 | if (current == NULL) return; |
| 88 | PrintTestList(current->prev()); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 89 | 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.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 98 | v8::Isolate* CcTest::default_isolate_; |
| 99 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 100 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 101 | int main(int argc, char* argv[]) { |
| 102 | v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 103 | v8::internal::FLAG_harmony_array_buffer = true; |
| 104 | v8::internal::FLAG_harmony_typed_arrays = true; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 105 | CcTest::set_default_isolate(v8::Isolate::GetCurrent()); |
| 106 | CHECK(CcTest::default_isolate() != NULL); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 107 | 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.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 114 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 115 | } else { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 116 | char* arg_copy = v8::internal::StrDup(arg); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 117 | 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.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 122 | 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.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 135 | } else { |
| 136 | // Run all tests with the specified file or test name. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 137 | 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.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 148 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 149 | v8::internal::DeleteArray<char>(arg_copy); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | if (print_run_count && tests_run != 1) |
| 153 | printf("Ran %i tests.\n", tests_run); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 154 | v8::V8::Dispose(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 155 | return 0; |
| 156 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 157 | |
| 158 | RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
| 159 | int RegisterThreadedTest::count_ = 0; |