From 8934b1ef0857bc08626a2206a6f5f718942c14fc Mon Sep 17 00:00:00 2001 From: Aaron Knobloch Date: Wed, 29 May 2024 20:46:34 -0700 Subject: [PATCH] Add QEMU user option for running tests. The QEMU option is particularly useful for running RISC-V based tests, for which there does not exist any RISC-V hardware for native execution. This change was verified locally using the following command: go run util/all_tests.go \ --qemu /usr/local/google/home/aknobloch/Downloads/qemu-build/usr/bin/qemu-riscv64 \ The tests took ~20 minutes to complete. Change-Id: Ide9514d5d6a024d8c42a4a129d7e4a6582b5878a Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68887 Reviewed-by: David Benjamin Commit-Queue: David Benjamin Auto-Submit: Aaron Knobloch --- util/all_tests.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/all_tests.go b/util/all_tests.go index 4090943f3..d80cd6098 100644 --- a/util/all_tests.go +++ b/util/all_tests.go @@ -48,6 +48,7 @@ var ( mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask each test to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") simulateARMCPUs = flag.Bool("simulate-arm-cpus", simulateARMCPUsDefault(), "If true, runs tests simulating different ARM CPUs.") + qemuBinary = flag.String("qemu", "", "Optional, absolute path to a binary location for QEMU runtime.") ) func simulateARMCPUsDefault() bool { @@ -145,6 +146,13 @@ func sdeOf(cpu, path string, args ...string) *exec.Cmd { return exec.Command(*sdePath, sdeArgs...) } +func qemuOf(path string, args ...string) *exec.Cmd { + // The QEMU binary becomes the program to run, and the previous test program + // to run instead becomes an additional argument to the QEMU binary. + args = append([]string{path}, args...) + return exec.Command(*qemuBinary, args...) +} + var ( errMoreMallocs = errors.New("child process did not exhaust all allocation calls") errTestSkipped = errors.New("test was skipped") @@ -161,6 +169,7 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) { // detected. args = append(args, "--no_unwind_tests") } + var cmd *exec.Cmd if *useValgrind { cmd = valgrindOf(false, prog, args...) @@ -170,6 +179,8 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) { cmd = gdbOf(prog, args...) } else if *useSDE { cmd = sdeOf(test.cpu, prog, args...) + } else if *qemuBinary != "" { + cmd = qemuOf(prog, args...) } else { cmd = exec.Command(prog, args...) }