| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "vm/benchmark_test.h" |
| 7 #include "vm/dart.h" | 8 #include "vm/dart.h" |
| 8 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 9 | 10 |
| 10 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. | 11 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. |
| 11 namespace dart { | 12 namespace dart { |
| 12 | 13 |
| 13 // Only run tests that match the filter string. The default does not match any | 14 // Only run tests that match the filter string. The default does not match any |
| 14 // tests. | 15 // tests. |
| 15 static const char* const kNoTests = "No Test"; | 16 static const char* const kNone = "No Test or Benchmarks"; |
| 17 static const char* const kAll = "All"; |
| 18 static const char* const kList = "List all Tests and Benchmarks"; |
| 16 static const char* const kAllTests = "All Tests"; | 19 static const char* const kAllTests = "All Tests"; |
| 17 static const char* const kListTests = "List Tests"; | 20 static const char* const kAllBenchmarks = "All Benchmarks"; |
| 18 static const char* test_filter = kNoTests; | 21 static const char* run_filter = kNone; |
| 19 | 22 |
| 20 static int test_matches = 0; | 23 static int run_matches = 0; |
| 21 | 24 |
| 22 | 25 |
| 23 void TestCase::Run() { | 26 void TestCase::Run() { |
| 24 fprintf(stdout, "Running test: %s\n", name()); | 27 fprintf(stdout, "Running test: %s\n", name()); |
| 25 (*run_)(); | 28 (*run_)(); |
| 26 fprintf(stdout, "Done: %s\n", name()); | 29 fprintf(stdout, "Done: %s\n", name()); |
| 27 } | 30 } |
| 28 | 31 |
| 29 | 32 |
| 30 void TestCaseBase::RunTest() { | 33 void TestCaseBase::RunTest() { |
| 31 if ((test_filter == kAllTests) || (strcmp(test_filter, this->name()) == 0)) { | 34 if ((run_filter == kAll) || |
| 35 (run_filter == kAllTests) || |
| 36 (strcmp(run_filter, this->name()) == 0)) { |
| 32 this->Run(); | 37 this->Run(); |
| 33 test_matches++; | 38 run_matches++; |
| 34 } else if (test_filter == kListTests) { | 39 } else if (run_filter == kList) { |
| 35 fprintf(stdout, "%s\n", this->name()); | 40 fprintf(stdout, "%s\n", this->name()); |
| 36 test_matches++; | 41 run_matches++; |
| 42 } |
| 43 } |
| 44 |
| 45 |
| 46 void Benchmark::RunBenchmark() { |
| 47 if ((run_filter == kAll) || |
| 48 (run_filter == kAllBenchmarks) || |
| 49 (strcmp(run_filter, this->name()) == 0)) { |
| 50 this->Run(); |
| 51 OS::Print("%s : %ld\n", this->name(), this->score()); |
| 52 run_matches++; |
| 53 } else if (run_filter == kList) { |
| 54 fprintf(stdout, "%s\n", this->name()); |
| 55 run_matches++; |
| 37 } | 56 } |
| 38 } | 57 } |
| 39 | 58 |
| 40 | 59 |
| 41 static void PrintUsage() { | 60 static void PrintUsage() { |
| 42 fprintf(stderr, "run_vm_tests [--list | --all | <test name>]\n"); | 61 fprintf(stderr, "run_vm_tests [--list | --benchmarks | " |
| 62 "--tests | --all | <test name> | <benchmark name>]\n"); |
| 43 fprintf(stderr, "run_vm_tests <test name> [vm-flags ...]\n"); | 63 fprintf(stderr, "run_vm_tests <test name> [vm-flags ...]\n"); |
| 64 fprintf(stderr, "run_vm_tests <benchmark name> [flags ...]\n"); |
| 44 } | 65 } |
| 45 | 66 |
| 46 | 67 |
| 47 static int Main(int argc, const char** argv) { | 68 static int Main(int argc, const char** argv) { |
| 48 // Flags being passed to the Dart VM. | 69 // Flags being passed to the Dart VM. |
| 49 int dart_argc = 0; | 70 int dart_argc = 0; |
| 50 const char** dart_argv = NULL; | 71 const char** dart_argv = NULL; |
| 51 | 72 |
| 52 if (argc < 2) { | 73 if (argc < 2) { |
| 53 // Bad parameter count. | 74 // Bad parameter count. |
| 54 PrintUsage(); | 75 PrintUsage(); |
| 55 return 1; | 76 return 1; |
| 56 } else if (argc == 2) { | 77 } else if (argc == 2) { |
| 57 if (strcmp(argv[1], "--list") == 0) { | 78 if (strcmp(argv[1], "--list") == 0) { |
| 58 test_filter = kListTests; | 79 run_filter = kList; |
| 59 // List all the tests and exit without initializing the VM at all. | 80 // List all tests and benchmarks and exit without initializing the VM. |
| 60 TestCaseBase::RunAll(); | 81 TestCaseBase::RunAll(); |
| 82 Benchmark::RunAll(); |
| 61 return 0; | 83 return 0; |
| 62 } else if (strcmp(argv[1], "--all") == 0) { | 84 } else if (strcmp(argv[1], "--all") == 0) { |
| 63 test_filter = kAllTests; | 85 run_filter = kAll; |
| 86 } else if (strcmp(argv[1], "--tests") == 0) { |
| 87 run_filter = kAllTests; |
| 88 } else if (strcmp(argv[1], "--benchmarks") == 0) { |
| 89 run_filter = kAllBenchmarks; |
| 64 } else { | 90 } else { |
| 65 test_filter = argv[1]; | 91 run_filter = argv[1]; |
| 66 } | 92 } |
| 67 } else { | 93 } else { |
| 68 // First argument is the test name, the rest are vm flags. | 94 // First argument is the test name, the rest are vm flags. |
| 69 test_filter = argv[1]; | 95 run_filter = argv[1]; |
| 70 // Remove the first two values from the arguments. | 96 // Remove the first two values from the arguments. |
| 71 dart_argc = argc - 2; | 97 dart_argc = argc - 2; |
| 72 dart_argv = &argv[2]; | 98 dart_argv = &argv[2]; |
| 73 } | 99 } |
| 74 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, | 100 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, |
| 75 dart_argv); | 101 dart_argv); |
| 76 ASSERT(set_vm_flags_success); | 102 ASSERT(set_vm_flags_success); |
| 77 bool init_success = Dart::InitOnce(NULL, NULL); | 103 bool init_success = Dart::InitOnce(NULL, NULL); |
| 78 ASSERT(init_success); | 104 ASSERT(init_success); |
| 79 // Apply the test filter to all registered tests. | 105 // Apply the filter to all registered tests. |
| 80 TestCaseBase::RunAll(); | 106 TestCaseBase::RunAll(); |
| 81 // Print a warning message if no tests were matched. | 107 // Apply the filter to all registered benchmarks. |
| 82 if (test_matches == 0) { | 108 Benchmark::RunAll(); |
| 83 fprintf(stderr, "No tests matched: %s\n", test_filter); | 109 // Print a warning message if no tests or benchmarks were matched. |
| 110 if (run_matches == 0) { |
| 111 fprintf(stderr, "No tests matched: %s\n", run_filter); |
| 84 return 1; | 112 return 1; |
| 85 } | 113 } |
| 86 return 0; | 114 return 0; |
| 87 } | 115 } |
| 88 | 116 |
| 89 } // namespace dart | 117 } // namespace dart |
| 90 | 118 |
| 91 | 119 |
| 92 int main(int argc, const char** argv) { | 120 int main(int argc, const char** argv) { |
| 93 return dart::Main(argc, argv); | 121 return dart::Main(argc, argv); |
| 94 } | 122 } |
| OLD | NEW |