Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: runtime/bin/run_vm_tests.cc

Issue 2898743003: Revert "Revert "Use Kernel frontend from run_vm_tests."" (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/BUILD.gn ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ddb8a4e37bb1846b32cc68cb8dade34fbce15b64 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,98 @@ 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 [--dfe=<snapshot file name>] --benchmarks\n"
+ " run_vm_tests [--dfe=<snapshot file name>] [vm-flags ...] <test name>\n"
+ " run_vm_tests [--dfe=<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;
+ if (!is_kernel_isolate) {
+ *error =
+ strdup("Spawning of only Kernel isolate is supported in run_vm_tests.");
+ return NULL;
+ }
+ if (kernel_snapshot == NULL) {
+ *error =
+ strdup("Kernel snapshot location has to be specified via --dfe 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* isolate_snapshot_data = bin::core_isolate_snapshot_data;
+ const uint8_t* isolate_snapshot_instructions =
+ bin::core_isolate_snapshot_instructions;
+
+ 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);
+
+ 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,20 +185,36 @@ 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], "--dfe") == 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);
+ // VM needs '--use-dart-frontend' option, which we will insert in place
+ // of '--dfe' option.
+ argv[arg_pos] = strdup("--use-dart-frontend");
+ ++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];
@@ -118,14 +223,18 @@ static int Main(int argc, const char** argv) {
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(
- 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();
« no previous file with comments | « runtime/bin/BUILD.gn ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698