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