Files
sdk/runtime/bin/run_vm_tests.cc
T
meh@google.com 432978367e Clean up CodeObservers
Move CodeObserver registration to the OS abstraction.
Move Pprof logic to the OS abstraction.
Remove pprof from VM tests because now pprof logic is in the VM itself.
Add DISALLOW and AllStatic to Code Observers where appropriate.

Previous review: https://codereview.chromium.org/11572032/

BUG=7321

Review URL: https://codereview.chromium.org//11660011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16462 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-22 00:23:25 +00:00

127 lines
3.7 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <stdio.h>
#include "bin/file.h"
#include "vm/benchmark_test.h"
#include "vm/dart.h"
#include "vm/unit_test.h"
// TODO(iposva, asiva): This is a placeholder for the real unittest framework.
namespace dart {
// Only run tests that match the filter string. The default does not match any
// tests.
static const char* const kNone = "No Test or Benchmarks";
static const char* const kAll = "All";
static const char* const kList = "List all Tests and Benchmarks";
static const char* const kAllTests = "All Tests";
static const char* const kAllBenchmarks = "All Benchmarks";
static const char* run_filter = kNone;
static int run_matches = 0;
void TestCase::Run() {
fprintf(stdout, "Running test: %s\n", name());
(*run_)();
fprintf(stdout, "Done: %s\n", name());
}
void TestCaseBase::RunTest() {
if ((run_filter == kAll) ||
(run_filter == kAllTests) ||
(strcmp(run_filter, this->name()) == 0)) {
this->Run();
run_matches++;
} else if (run_filter == kList) {
fprintf(stdout, "%s\n", this->name());
run_matches++;
}
}
void Benchmark::RunBenchmark() {
if ((run_filter == kAll) ||
(run_filter == kAllBenchmarks) ||
(strcmp(run_filter, this->name()) == 0)) {
this->Run();
OS::Print("%s(RunTime): %"Pd"\n", this->name(), this->score());
run_matches++;
} else if (run_filter == kList) {
fprintf(stdout, "%s\n", this->name());
run_matches++;
}
}
static void PrintUsage() {
fprintf(stderr, "run_vm_tests [--list | --benchmarks | "
"--tests | --all | <test name> | <benchmark name>]\n");
fprintf(stderr, "run_vm_tests [vm-flags ...] <test name>\n");
fprintf(stderr, "run_vm_tests [vm-flags ...] <benchmark name>\n");
}
static int Main(int argc, const char** argv) {
// Flags being passed to the Dart VM.
int dart_argc = 0;
const char** dart_argv = NULL;
if (argc < 2) {
// Bad parameter count.
PrintUsage();
return 1;
} else if (argc == 2) {
if (strcmp(argv[1], "--list") == 0) {
run_filter = kList;
// List all tests and benchmarks and exit without initializing the VM.
TestCaseBase::RunAll();
Benchmark::RunAll(argv[0]);
return 0;
} else if (strcmp(argv[1], "--all") == 0) {
run_filter = kAll;
} else if (strcmp(argv[1], "--tests") == 0) {
run_filter = kAllTests;
} else if (strcmp(argv[1], "--benchmarks") == 0) {
run_filter = kAllBenchmarks;
} else {
run_filter = argv[1];
}
} else {
// Last argument is the test name, the rest are vm flags.
run_filter = argv[argc - 1];
// Remove the first value (executable) from the arguments and
// exclude the last argument which is the test name.
dart_argc = argc - 2;
dart_argv = &argv[1];
}
bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc,
dart_argv);
ASSERT(set_vm_flags_success);
const char* err_msg = Dart::InitOnce(NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
ASSERT(err_msg == NULL);
// Apply the filter to all registered tests.
TestCaseBase::RunAll();
// Apply the filter to all registered benchmarks.
Benchmark::RunAll(argv[0]);
// Print a warning message if no tests or benchmarks were matched.
if (run_matches == 0) {
fprintf(stderr, "No tests matched: %s\n", run_filter);
return 1;
}
return 0;
}
} // namespace dart
int main(int argc, const char** argv) {
return dart::Main(argc, argv);
}