| OLD | NEW |
| 1 // Copyright (c) 2012, 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 "bin/file.h" |
| 8 |
| 7 #include "vm/benchmark_test.h" | 9 #include "vm/benchmark_test.h" |
| 8 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| 9 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 10 | 12 |
| 11 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. | 13 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. |
| 12 namespace dart { | 14 namespace dart { |
| 13 | 15 |
| 14 // Only run tests that match the filter string. The default does not match any | 16 // Only run tests that match the filter string. The default does not match any |
| 15 // tests. | 17 // tests. |
| 16 static const char* const kNone = "No Test or Benchmarks"; | 18 static const char* const kNone = "No Test or Benchmarks"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 this->Run(); | 52 this->Run(); |
| 51 OS::Print("%s(RunTime): %ld\n", this->name(), this->score()); | 53 OS::Print("%s(RunTime): %ld\n", this->name(), this->score()); |
| 52 run_matches++; | 54 run_matches++; |
| 53 } else if (run_filter == kList) { | 55 } else if (run_filter == kList) { |
| 54 fprintf(stdout, "%s\n", this->name()); | 56 fprintf(stdout, "%s\n", this->name()); |
| 55 run_matches++; | 57 run_matches++; |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| 59 | 61 |
| 62 static void DumpPprofSymbolInfo(const char* pprof_filename) { |
| 63 if (pprof_filename != NULL) { |
| 64 char* err = NULL; |
| 65 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &err); |
| 66 EXPECT(isolate != NULL); |
| 67 Dart_EnterScope(); |
| 68 File* pprof_file = |
| 69 File::Open(pprof_filename, File::kWriteTruncate); |
| 70 ASSERT(pprof_file != NULL); |
| 71 void* buffer; |
| 72 int buffer_size; |
| 73 Dart_GetPprofSymbolInfo(&buffer, &buffer_size); |
| 74 if (buffer_size > 0) { |
| 75 ASSERT(buffer != NULL); |
| 76 pprof_file->WriteFully(buffer, buffer_size); |
| 77 } |
| 78 delete pprof_file; // Closes the file. |
| 79 Dart_ExitScope(); |
| 80 Dart_ShutdownIsolate(); |
| 81 } |
| 82 } |
| 83 |
| 84 |
| 60 static void PrintUsage() { | 85 static void PrintUsage() { |
| 61 fprintf(stderr, "run_vm_tests [--list | --benchmarks | " | 86 fprintf(stderr, "run_vm_tests [--list | --benchmarks | " |
| 62 "--tests | --all | <test name> | <benchmark name>]\n"); | 87 "--tests | --all | <test name> | <benchmark name>]\n"); |
| 63 fprintf(stderr, "run_vm_tests <test name> [vm-flags ...]\n"); | 88 fprintf(stderr, "run_vm_tests <test name> [vm-flags ...]\n"); |
| 64 fprintf(stderr, "run_vm_tests <benchmark name> [flags ...]\n"); | 89 fprintf(stderr, "run_vm_tests <benchmark name> [flags ...]\n"); |
| 65 } | 90 } |
| 66 | 91 |
| 67 | 92 |
| 68 static int Main(int argc, const char** argv) { | 93 static int Main(int argc, const char** argv) { |
| 69 // Flags being passed to the Dart VM. | 94 // Flags being passed to the Dart VM. |
| 70 int dart_argc = 0; | 95 int dart_argc = 0; |
| 71 const char** dart_argv = NULL; | 96 const char** dart_argv = NULL; |
| 97 const char* pprof_filename = NULL; |
| 72 | 98 |
| 73 if (argc < 2) { | 99 if (argc < 2) { |
| 74 // Bad parameter count. | 100 // Bad parameter count. |
| 75 PrintUsage(); | 101 PrintUsage(); |
| 76 return 1; | 102 return 1; |
| 77 } else if (argc == 2) { | 103 } else if (argc == 2) { |
| 78 if (strcmp(argv[1], "--list") == 0) { | 104 if (strcmp(argv[1], "--list") == 0) { |
| 79 run_filter = kList; | 105 run_filter = kList; |
| 80 // List all tests and benchmarks and exit without initializing the VM. | 106 // List all tests and benchmarks and exit without initializing the VM. |
| 81 TestCaseBase::RunAll(); | 107 TestCaseBase::RunAll(); |
| 82 Benchmark::RunAll(argv[0]); | 108 Benchmark::RunAll(argv[0]); |
| 83 return 0; | 109 return 0; |
| 84 } else if (strcmp(argv[1], "--all") == 0) { | 110 } else if (strcmp(argv[1], "--all") == 0) { |
| 85 run_filter = kAll; | 111 run_filter = kAll; |
| 86 } else if (strcmp(argv[1], "--tests") == 0) { | 112 } else if (strcmp(argv[1], "--tests") == 0) { |
| 87 run_filter = kAllTests; | 113 run_filter = kAllTests; |
| 88 } else if (strcmp(argv[1], "--benchmarks") == 0) { | 114 } else if (strcmp(argv[1], "--benchmarks") == 0) { |
| 89 run_filter = kAllBenchmarks; | 115 run_filter = kAllBenchmarks; |
| 90 } else { | 116 } else { |
| 91 run_filter = argv[1]; | 117 run_filter = argv[1]; |
| 92 } | 118 } |
| 93 } else { | 119 } else { |
| 94 // First argument is the test name, the rest are vm flags. | 120 // First argument is the test name, the rest are vm flags. |
| 95 run_filter = argv[1]; | 121 run_filter = argv[1]; |
| 96 // Remove the first two values from the arguments. | 122 const char* pprof_option = "--generate_pprof_symbols="; |
| 97 dart_argc = argc - 2; | 123 int length = strlen(pprof_option); |
| 98 dart_argv = &argv[2]; | 124 if (strncmp(pprof_option, argv[2], length) == 0) { |
| 125 pprof_filename = (argv[2] + length); |
| 126 Dart_InitPprofSupport(); |
| 127 // Remove the first three values from the arguments. |
| 128 dart_argc = argc - 3; |
| 129 dart_argv = &argv[3]; |
| 130 } else { |
| 131 // Remove the first two values from the arguments. |
| 132 dart_argc = argc - 2; |
| 133 dart_argv = &argv[2]; |
| 134 } |
| 99 } | 135 } |
| 100 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, | 136 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, |
| 101 dart_argv); | 137 dart_argv); |
| 102 ASSERT(set_vm_flags_success); | 138 ASSERT(set_vm_flags_success); |
| 103 bool init_success = Dart::InitOnce(NULL, NULL); | 139 bool init_success = Dart::InitOnce(NULL, NULL); |
| 104 ASSERT(init_success); | 140 ASSERT(init_success); |
| 105 // Apply the filter to all registered tests. | 141 // Apply the filter to all registered tests. |
| 106 TestCaseBase::RunAll(); | 142 TestCaseBase::RunAll(); |
| 107 // Apply the filter to all registered benchmarks. | 143 // Apply the filter to all registered benchmarks. |
| 108 Benchmark::RunAll(argv[0]); | 144 Benchmark::RunAll(argv[0]); |
| 109 // Print a warning message if no tests or benchmarks were matched. | 145 // Print a warning message if no tests or benchmarks were matched. |
| 110 if (run_matches == 0) { | 146 if (run_matches == 0) { |
| 111 fprintf(stderr, "No tests matched: %s\n", run_filter); | 147 fprintf(stderr, "No tests matched: %s\n", run_filter); |
| 112 return 1; | 148 return 1; |
| 113 } | 149 } |
| 150 // Dump symbol information for the profiler. |
| 151 DumpPprofSymbolInfo(pprof_filename); |
| 114 return 0; | 152 return 0; |
| 115 } | 153 } |
| 116 | 154 |
| 117 } // namespace dart | 155 } // namespace dart |
| 118 | 156 |
| 119 | 157 |
| 120 int main(int argc, const char** argv) { | 158 int main(int argc, const char** argv) { |
| 121 return dart::Main(argc, argv); | 159 return dart::Main(argc, argv); |
| 122 } | 160 } |
| OLD | NEW |