Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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[]) { |
| 73 | v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
| 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 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame^] | 124 | |
| 125 | RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
| 126 | int RegisterThreadedTest::count_ = 0; |