From 4552d07a80dcdd93cf4ff8c466592a36497d0c51 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Tue, 22 Feb 2022 09:05:32 -0800 Subject: [PATCH] scripts: Support custom arguments to the test binary with dev_cli.sh The dev container interface script (e.g. 'dev_cli.sh') now supports the following arguments syntax for running tests: `tests [--unit|--cargo|--all] [--libc musl|gnu] [-- [] [-- []]] ` In this way, we can pass custom arguments to the test binary (either "cargo test" or "performance-metrics") with our dev container script. For example: `$ ./dev_cli.sh tests --metrics -- -- --report-file /tmp/metrics.json --test-filter latency` `$ ./dev_cli.sh tests --integration -- --test-filter "test_serial" -- --nocapture --test-threads=1` Fixes: #3739 Signed-off-by: Bo Chen --- scripts/dev_cli.sh | 4 ++-- scripts/run_integration_tests_aarch64.sh | 8 ++++---- scripts/run_integration_tests_live_migration.sh | 2 +- scripts/run_integration_tests_sgx.sh | 2 +- scripts/run_integration_tests_vfio.sh | 2 +- scripts/run_integration_tests_windows.sh | 2 +- scripts/run_integration_tests_x86_64.sh | 4 ++-- scripts/run_metrics.sh | 2 +- scripts/test-util.sh | 11 ++++++++++- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/scripts/dev_cli.sh b/scripts/dev_cli.sh index e67140980..6c69c7400 100755 --- a/scripts/dev_cli.sh +++ b/scripts/dev_cli.sh @@ -183,7 +183,7 @@ cmd_help() { echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" echo " --hypervisor Underlying hypervisor. Options kvm, mshv" echo "" - echo " tests [--unit|--cargo|--all] [--libc musl|gnu] [-- []]" + echo " tests [--unit|--cargo|--all] [--libc musl|gnu] [-- [] [-- []]] " echo " Run the Cloud Hypervisor tests." echo " --unit Run the unit tests." echo " --cargo Run the cargo tests." @@ -369,7 +369,7 @@ cmd_tests() { exported_device="/dev/mshv" fi - set -- "$@" '--hypervisor' "$hypervisor" + set -- '--hypervisor' "$hypervisor" "$@" ensure_build_dir ensure_latest_ctr diff --git a/scripts/run_integration_tests_aarch64.sh b/scripts/run_integration_tests_aarch64.sh index c679c00d1..5afaa6434 100755 --- a/scripts/run_integration_tests_aarch64.sh +++ b/scripts/run_integration_tests_aarch64.sh @@ -311,13 +311,13 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages sudo chmod a+rwX /dev/hugepages # Run all direct kernel boot (Device Tree) test cases in mod `parallel` -time cargo test $features "parallel::$test_filter" +time cargo test $features "parallel::$test_filter" -- ${test_binary_args[*]} RES=$? # Run some tests in sequence since the result could be affected by other tests # running in parallel. if [ $RES -eq 0 ]; then - time cargo test $features "sequential::$test_filter" -- --test-threads=1 + time cargo test $features "sequential::$test_filter" -- --test-threads=1 ${test_binary_args[*]} RES=$? else exit $RES @@ -325,7 +325,7 @@ fi # Run all ACPI test cases if [ $RES -eq 0 ]; then - time cargo test $features "aarch64_acpi::$test_filter" + time cargo test $features "aarch64_acpi::$test_filter" -- ${test_binary_args[*]} RES=$? else exit $RES @@ -333,7 +333,7 @@ fi # Run all test cases related to live migration if [ $RES -eq 0 ]; then - time cargo test $features "live_migration::$test_filter" -- --test-threads=1 + time cargo test $features "live_migration::$test_filter" -- --test-threads=1 ${test_binary_args[*]} RES=$? else exit $RES diff --git a/scripts/run_integration_tests_live_migration.sh b/scripts/run_integration_tests_live_migration.sh index 2c28b30cb..e03c8460e 100755 --- a/scripts/run_integration_tests_live_migration.sh +++ b/scripts/run_integration_tests_live_migration.sh @@ -87,7 +87,7 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages sudo chmod a+rwX /dev/hugepages export RUST_BACKTRACE=1 -time cargo test $features "live_migration::$test_filter" -- --test-threads=1 +time cargo test $features "live_migration::$test_filter" -- --test-threads=1 ${test_binary_args[*]} RES=$? exit $RES diff --git a/scripts/run_integration_tests_sgx.sh b/scripts/run_integration_tests_sgx.sh index 6388d6034..6a5334aac 100755 --- a/scripts/run_integration_tests_sgx.sh +++ b/scripts/run_integration_tests_sgx.sh @@ -27,7 +27,7 @@ strip target/$BUILD_TARGET/release/cloud-hypervisor export RUST_BACKTRACE=1 -time cargo test $features "sgx::$test_filter" +time cargo test $features "sgx::$test_filter" -- ${test_binary_args[*]} RES=$? exit $RES diff --git a/scripts/run_integration_tests_vfio.sh b/scripts/run_integration_tests_vfio.sh index 10a3b479d..542dfe973 100755 --- a/scripts/run_integration_tests_vfio.sh +++ b/scripts/run_integration_tests_vfio.sh @@ -21,7 +21,7 @@ strip target/$BUILD_TARGET/release/cloud-hypervisor export RUST_BACKTRACE=1 -time cargo test $features "vfio::$test_filter" -- --test-threads=1 +time cargo test $features "vfio::$test_filter" -- --test-threads=1 ${test_binary_args[*]} RES=$? exit $RES diff --git a/scripts/run_integration_tests_windows.sh b/scripts/run_integration_tests_windows.sh index c43388da3..9e07bb239 100755 --- a/scripts/run_integration_tests_windows.sh +++ b/scripts/run_integration_tests_windows.sh @@ -51,7 +51,7 @@ export RUST_BACKTRACE=1 # Only run with 1 thread to avoid tests interfering with one another because # Windows has a static IP configured -time cargo test $features "windows::$test_filter" +time cargo test $features "windows::$test_filter" -- ${test_binary_args[*]} RES=$? dmsetup remove_all -f diff --git a/scripts/run_integration_tests_x86_64.sh b/scripts/run_integration_tests_x86_64.sh index abe480b75..684b148da 100755 --- a/scripts/run_integration_tests_x86_64.sh +++ b/scripts/run_integration_tests_x86_64.sh @@ -201,14 +201,14 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages sudo chmod a+rwX /dev/hugepages export RUST_BACKTRACE=1 -time cargo test $features "parallel::$test_filter" +time cargo test $features "parallel::$test_filter" -- ${test_binary_args[*]} RES=$? # Run some tests in sequence since the result could be affected by other tests # running in parallel. if [ $RES -eq 0 ]; then export RUST_BACKTRACE=1 - time cargo test $features "sequential::$test_filter" -- --test-threads=1 + time cargo test $features "sequential::$test_filter" -- --test-threads=1 ${test_binary_args[*]} RES=$? fi diff --git a/scripts/run_metrics.sh b/scripts/run_metrics.sh index a4446cb47..f19e9489e 100755 --- a/scripts/run_metrics.sh +++ b/scripts/run_metrics.sh @@ -88,7 +88,7 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages sudo chmod a+rwX /dev/hugepages export RUST_BACKTRACE=1 -time target/$BUILD_TARGET/release/performance-metrics +time target/$BUILD_TARGET/release/performance-metrics ${test_binary_args[*]} RES=$? exit $RES diff --git a/scripts/test-util.sh b/scripts/test-util.sh index 4c25f9033..9964b738d 100644 --- a/scripts/test-util.sh +++ b/scripts/test-util.sh @@ -1,6 +1,7 @@ #!/bin/bash hypervisor="kvm" test_filter="" +test_binary_args=() cmd_help() { echo "" @@ -28,12 +29,20 @@ process_common_args() { shift test_filter="$1" ;; + "--") { + shift + break + } ;; *) - ;; + echo "Unknown test scripts argument: $1. Please use '-- --help' for help." + exit + ;; esac shift done if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then die "Hypervisor value must be kvm or mshv" fi + + test_binary_args="$@" }