Chromium Code Reviews| Index: runtime/bin/run_vm_tests.cc |
| diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc |
| index ed1e0969e6eef19406a84b0dfd86bf54922dd643..33493f37e63aab091f707788d4ac717c715a041d 100644 |
| --- a/runtime/bin/run_vm_tests.cc |
| +++ b/runtime/bin/run_vm_tests.cc |
| @@ -6,7 +6,9 @@ |
| #include "bin/dartutils.h" |
| #include "bin/file.h" |
| +#include "bin/loader.h" |
| #include "bin/platform.h" |
| +#include "bin/snapshot_utils.h" |
| #include "platform/assert.h" |
| #include "vm/benchmark_test.h" |
| #include "vm/dart.h" |
| @@ -30,6 +32,7 @@ static const char* const kNone = "No Test or Benchmarks"; |
| static const char* const kList = "List all Tests and Benchmarks"; |
| static const char* const kAllBenchmarks = "All Benchmarks"; |
| static const char* run_filter = kNone; |
| +static const char* kernel_snapshot = NULL; |
| static int run_matches = 0; |
| @@ -75,12 +78,95 @@ void Benchmark::RunBenchmark() { |
| static void PrintUsage() { |
| OS::PrintErr( |
| - "run_vm_tests [--list | --benchmarks | " |
| - "<test name> | <benchmark name>]\n"); |
| - OS::PrintErr("run_vm_tests [vm-flags ...] <test name>\n"); |
| - OS::PrintErr("run_vm_tests [vm-flags ...] <benchmark name>\n"); |
| + "Usage: one of the following\n" |
| + " run_vm_tests --list\n" |
| + " run_vm_tests [--run_vm_test_with_kernel_snapshot=<snapshot file " |
| + "name>] --benchmarks\n" |
| + " run_vm_tests [--run_vm_test_with_kernel_snapshot=<snapshot file " |
| + "name>] [vm-flags ...] <test name>\n" |
| + " run_vm_tests [--run_vm_test_with_kernel_snapshot=<snapshot file " |
| + "name>] [vm-flags ...] <benchmark name>\n"); |
| } |
| +#define CHECK_RESULT(result) \ |
| + if (Dart_IsError(result)) { \ |
| + *error = strdup(Dart_GetError(result)); \ |
| + Dart_ExitScope(); \ |
| + Dart_ShutdownIsolate(); \ |
| + return NULL; \ |
| + } |
| + |
| + |
| +static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| + const char* main, |
| + const char* package_root, |
| + const char* packages_config, |
| + Dart_IsolateFlags* flags, |
| + void* data, |
| + char** error) { |
| + ASSERT(script_uri != NULL); |
| + const bool is_service_isolate = |
| + strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; |
| + if (is_service_isolate) { |
| + // We don't need service isolate for VM tests. |
| + return NULL; |
| + } |
| + const bool is_kernel_isolate = |
| + strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; |
| + const uint8_t* isolate_snapshot_data = bin::core_isolate_snapshot_data; |
| + const uint8_t* isolate_snapshot_instructions = |
| + bin::core_isolate_snapshot_instructions; |
| + if (is_kernel_isolate) { |
| + if (kernel_snapshot == NULL) { |
| + *error = strdup( |
| + "Kernel snapshot location has to be specified via " |
| + "--run_vm_test_with_kernel_snapshot option"); |
| + return NULL; |
| + } |
| + script_uri = kernel_snapshot; |
| + bin::AppSnapshot* app_snapshot = |
| + bin::Snapshot::TryReadAppSnapshot(script_uri); |
| + if (app_snapshot == NULL) { |
| + *error = strdup("Failed to read kernel service app snapshot"); |
| + return NULL; |
| + } |
| + const uint8_t* ignore_vm_snapshot_data; |
| + const uint8_t* ignore_vm_snapshot_instructions; |
| + app_snapshot->SetBuffers( |
| + &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
| + &isolate_snapshot_data, &isolate_snapshot_instructions); |
| + } |
| + |
|
siva
2017/05/15 04:34:26
Will this code run for non kernel isolates too?
aam
2017/05/15 23:49:14
Yes, if I understand correctly, this callback will
|
| + bin::IsolateData* isolate_data = new bin::IsolateData( |
| + script_uri, package_root, packages_config, NULL /* app_snapshot */); |
| + Dart_Isolate isolate = Dart_CreateIsolate( |
| + script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, |
| + flags, isolate_data, error); |
| + if (isolate == NULL) { |
| + *error = strdup("Failed to create isolate"); |
| + delete isolate_data; |
| + return NULL; |
| + } |
| + |
| + Dart_EnterScope(); |
| + |
| + bin::DartUtils::SetOriginalWorkingDirectory(); |
| + Dart_Handle result = bin::DartUtils::PrepareForScriptLoading( |
| + false /* is_service_isolate */, false /* trace_loading */); |
| + CHECK_RESULT(result); |
| + |
| + Dart_ExitScope(); |
| + Dart_ExitIsolate(); |
| + bool retval = Dart_IsolateMakeRunnable(isolate); |
| + if (!retval) { |
| + *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| + Dart_EnterIsolate(isolate); |
| + Dart_ShutdownIsolate(); |
| + return NULL; |
| + } |
| + |
| + return isolate; |
| +} |
| static int Main(int argc, const char** argv) { |
| // Flags being passed to the Dart VM. |
| @@ -96,36 +182,53 @@ static int Main(int argc, const char** argv) { |
| // 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]); |
| - TestCaseBase::RunAllRaw(); |
| - fflush(stdout); |
| - return 0; |
| - } else if (strcmp(argv[1], "--benchmarks") == 0) { |
| - run_filter = kAllBenchmarks; |
| - } else { |
| - run_filter = argv[1]; |
| + } |
| + |
| + if (argc == 2 && 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]); |
| + TestCaseBase::RunAllRaw(); |
| + fflush(stdout); |
| + return 0; |
| + } |
| + |
| + int arg_pos = 1; |
| + if (strstr(argv[arg_pos], "--run_vm_test_with_kernel_snapshot") == |
|
siva
2017/05/15 04:34:26
Can we rename this option to --dfe same as the one
aam
2017/05/15 23:49:14
--dfe option is picked up by VM, not run_vm_test o
aam
2017/05/16 00:48:32
Thanks for clarifying main.cc(embedder) '--dfe' ve
|
| + argv[arg_pos]) { |
| + const char* delim = strstr(argv[1], "="); |
| + if (delim == NULL || strlen(delim + 1) == 0) { |
| + OS::PrintErr("Invalid value for the option: %s\n", argv[1]); |
| + PrintUsage(); |
| + return 1; |
| } |
| + kernel_snapshot = strdup(delim + 1); |
| + ++arg_pos; |
| + } |
| + |
| + if (arg_pos == argc - 1 && strcmp(argv[arg_pos], "--benchmarks") == 0) { |
| + // "--benchmarks" is the last argument. |
| + run_filter = kAllBenchmarks; |
| } 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]; |
| + dart_argc = argc - arg_pos; |
| + dart_argv = &argv[arg_pos]; |
| } |
| bool set_vm_flags_success = |
| Flags::ProcessCommandLineFlags(dart_argc, dart_argv); |
| ASSERT(set_vm_flags_success); |
| const char* err_msg = Dart::InitOnce( |
| - dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, NULL, |
| - NULL, NULL, NULL, dart::bin::DartUtils::OpenFile, |
| - dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile, |
| - dart::bin::DartUtils::CloseFile, NULL, NULL); |
| + dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, |
| + CreateIsolateAndSetup /* create */, NULL /* shutdown */, |
| + NULL /* cleanup */, NULL /* thread_exit */, |
| + dart::bin::DartUtils::OpenFile, dart::bin::DartUtils::ReadFile, |
| + dart::bin::DartUtils::WriteFile, dart::bin::DartUtils::CloseFile, |
| + NULL /* entropy_source */, NULL /* get_service_assets */); |
| + |
| ASSERT(err_msg == NULL); |
| // Apply the filter to all registered tests. |
| TestCaseBase::RunAll(); |