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 |
| 70 | if (context_.IsEmpty()) { |
| 71 | v8::Isolate* isolate = default_isolate(); |
| 72 | v8::HandleScope scope(isolate); |
| 73 | v8::ExtensionConfiguration config(extension_count, extension_names); |
| 74 | v8::Local<v8::Context> context = v8::Context::New(isolate, &config); |
| 75 | context_ = v8::Persistent<v8::Context>::New(isolate, context); |
| 76 | } |
| 77 | context_->Enter(); |
| 78 | } |
| 79 | |
| 80 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 81 | static void PrintTestList(CcTest* current) { |
| 82 | if (current == NULL) return; |
| 83 | PrintTestList(current->prev()); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 84 | if (current->dependency() != NULL) { |
| 85 | printf("%s/%s<%s\n", |
| 86 | current->file(), current->name(), current->dependency()); |
| 87 | } else { |
| 88 | printf("%s/%s<\n", current->file(), current->name()); |
| 89 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 93 | v8::Isolate* CcTest::default_isolate_; |
| 94 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame^] | 95 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 96 | int main(int argc, char* argv[]) { |
| 97 | v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 98 | CcTest::set_default_isolate(v8::Isolate::GetCurrent()); |
| 99 | CHECK(CcTest::default_isolate() != NULL); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 100 | int tests_run = 0; |
| 101 | bool print_run_count = true; |
| 102 | for (int i = 1; i < argc; i++) { |
| 103 | char* arg = argv[i]; |
| 104 | if (strcmp(arg, "--list") == 0) { |
| 105 | PrintTestList(CcTest::last()); |
| 106 | print_run_count = false; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 107 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 108 | } else { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 109 | char* arg_copy = v8::internal::StrDup(arg); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 110 | char* testname = strchr(arg_copy, '/'); |
| 111 | if (testname) { |
| 112 | // Split the string in two by nulling the slash and then run |
| 113 | // exact matches. |
| 114 | *testname = 0; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 115 | char* file = arg_copy; |
| 116 | char* name = testname + 1; |
| 117 | CcTest* test = CcTest::last(); |
| 118 | while (test != NULL) { |
| 119 | if (test->enabled() |
| 120 | && strcmp(test->file(), file) == 0 |
| 121 | && strcmp(test->name(), name) == 0) { |
| 122 | test->Run(); |
| 123 | tests_run++; |
| 124 | } |
| 125 | test = test->prev(); |
| 126 | } |
| 127 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 128 | } else { |
| 129 | // Run all tests with the specified file or test name. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 130 | char* file_or_name = arg_copy; |
| 131 | CcTest* test = CcTest::last(); |
| 132 | while (test != NULL) { |
| 133 | if (test->enabled() |
| 134 | && (strcmp(test->file(), file_or_name) == 0 |
| 135 | || strcmp(test->name(), file_or_name) == 0)) { |
| 136 | test->Run(); |
| 137 | tests_run++; |
| 138 | } |
| 139 | test = test->prev(); |
| 140 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 141 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 142 | v8::internal::DeleteArray<char>(arg_copy); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | if (print_run_count && tests_run != 1) |
| 146 | printf("Ran %i tests.\n", tests_run); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 147 | v8::V8::Dispose(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 148 | return 0; |
| 149 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 150 | |
| 151 | RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
| 152 | int RegisterThreadedTest::count_ = 0; |