[test_runner] Support for arm32 VM in JIT mode on x64 via QEMU

Using QEMU in AOT mode is still pending.

Issue: https://github.com/dart-lang/sdk/issues/40337

Change-Id: Idf68f5420eee91048eeca01534954f26ddba11ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133231
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
diff --git a/pkg/test_runner/lib/src/configuration.dart b/pkg/test_runner/lib/src/configuration.dart
index 6c413d7..ba2f2da 100644
--- a/pkg/test_runner/lib/src/configuration.dart
+++ b/pkg/test_runner/lib/src/configuration.dart
@@ -68,7 +68,8 @@
       this.outputDirectory,
       this.reproducingArguments,
       this.fastTestsOnly,
-      this.printPassingStdout})
+      this.printPassingStdout,
+      this.useQemu})
       : _packages = packages;
 
   final Map<String, RegExp> selectors;
@@ -97,6 +98,7 @@
   final bool writeResults;
   final bool writeLogs;
   final bool printPassingStdout;
+  final bool useQemu;
 
   Architecture get architecture => configuration.architecture;
   Compiler get compiler => configuration.compiler;
diff --git a/pkg/test_runner/lib/src/options.dart b/pkg/test_runner/lib/src/options.dart
index a9707d5..cedfc85 100644
--- a/pkg/test_runner/lib/src/options.dart
+++ b/pkg/test_runner/lib/src/options.dart
@@ -188,6 +188,8 @@
     _Option.bool('use_elf',
         'Directly generate an ELF shared libraries for precompilation.',
         hide: true),
+    _Option.bool('use_qemu', 'Use qemu to test arm32 on x64 host machines.',
+        hide: true),
     _Option.bool('keep_generated_files', 'Keep any generated files.',
         abbr: 'k'),
     _Option.int('timeout', 'Timeout in seconds.', abbr: 't'),
@@ -749,7 +751,8 @@
           reproducingArguments:
               _reproducingCommand(data, namedConfiguration != null),
           fastTestsOnly: data["fast_tests"] as bool,
-          printPassingStdout: data["print_passing_stdout"] as bool);
+          printPassingStdout: data["print_passing_stdout"] as bool,
+          useQemu: data["use_qemu"] as bool);
 
       if (configuration.validate()) {
         result.add(configuration);
diff --git a/pkg/test_runner/lib/src/runtime_configuration.dart b/pkg/test_runner/lib/src/runtime_configuration.dart
index 78bfe6b..b377f637 100644
--- a/pkg/test_runner/lib/src/runtime_configuration.dart
+++ b/pkg/test_runner/lib/src/runtime_configuration.dart
@@ -273,6 +273,10 @@
     if (type == 'application/kernel-ir-fully-linked') {
       executable = dartVmExecutableFileName;
     }
+    if (_configuration.useQemu) {
+      arguments.insertAll(0, ['-L', '/usr/arm-linux-gnueabihf/', executable]);
+      executable = 'qemu-arm';
+    }
     return [VMCommand(executable, arguments, environmentOverrides)];
   }
 }