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] [-- [<test scripts args>] [-- [<test binary args>]]] `

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 <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-02-22 09:05:32 -08:00 committed by Sebastien Boeuf
parent ec7d4e727a
commit 4552d07a80
9 changed files with 23 additions and 14 deletions

View File

@ -183,7 +183,7 @@ cmd_help() {
echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol"
echo " --hypervisor Underlying hypervisor. Options kvm, mshv" echo " --hypervisor Underlying hypervisor. Options kvm, mshv"
echo "" echo ""
echo " tests [--unit|--cargo|--all] [--libc musl|gnu] [-- [<cargo test args>]]" echo " tests [--unit|--cargo|--all] [--libc musl|gnu] [-- [<test scripts args>] [-- [<test binary args>]]] "
echo " Run the Cloud Hypervisor tests." echo " Run the Cloud Hypervisor tests."
echo " --unit Run the unit tests." echo " --unit Run the unit tests."
echo " --cargo Run the cargo tests." echo " --cargo Run the cargo tests."
@ -369,7 +369,7 @@ cmd_tests() {
exported_device="/dev/mshv" exported_device="/dev/mshv"
fi fi
set -- "$@" '--hypervisor' "$hypervisor" set -- '--hypervisor' "$hypervisor" "$@"
ensure_build_dir ensure_build_dir
ensure_latest_ctr ensure_latest_ctr

View File

@ -311,13 +311,13 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
sudo chmod a+rwX /dev/hugepages sudo chmod a+rwX /dev/hugepages
# Run all direct kernel boot (Device Tree) test cases in mod `parallel` # 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=$? RES=$?
# Run some tests in sequence since the result could be affected by other tests # Run some tests in sequence since the result could be affected by other tests
# running in parallel. # running in parallel.
if [ $RES -eq 0 ]; then 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=$? RES=$?
else else
exit $RES exit $RES
@ -325,7 +325,7 @@ fi
# Run all ACPI test cases # Run all ACPI test cases
if [ $RES -eq 0 ]; then 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=$? RES=$?
else else
exit $RES exit $RES
@ -333,7 +333,7 @@ fi
# Run all test cases related to live migration # Run all test cases related to live migration
if [ $RES -eq 0 ]; then 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=$? RES=$?
else else
exit $RES exit $RES

View File

@ -87,7 +87,7 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
sudo chmod a+rwX /dev/hugepages sudo chmod a+rwX /dev/hugepages
export RUST_BACKTRACE=1 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=$? RES=$?
exit $RES exit $RES

View File

@ -27,7 +27,7 @@ strip target/$BUILD_TARGET/release/cloud-hypervisor
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
time cargo test $features "sgx::$test_filter" time cargo test $features "sgx::$test_filter" -- ${test_binary_args[*]}
RES=$? RES=$?
exit $RES exit $RES

View File

@ -21,7 +21,7 @@ strip target/$BUILD_TARGET/release/cloud-hypervisor
export RUST_BACKTRACE=1 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=$? RES=$?
exit $RES exit $RES

View File

@ -51,7 +51,7 @@ export RUST_BACKTRACE=1
# Only run with 1 thread to avoid tests interfering with one another because # Only run with 1 thread to avoid tests interfering with one another because
# Windows has a static IP configured # Windows has a static IP configured
time cargo test $features "windows::$test_filter" time cargo test $features "windows::$test_filter" -- ${test_binary_args[*]}
RES=$? RES=$?
dmsetup remove_all -f dmsetup remove_all -f

View File

@ -201,14 +201,14 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
sudo chmod a+rwX /dev/hugepages sudo chmod a+rwX /dev/hugepages
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
time cargo test $features "parallel::$test_filter" time cargo test $features "parallel::$test_filter" -- ${test_binary_args[*]}
RES=$? RES=$?
# Run some tests in sequence since the result could be affected by other tests # Run some tests in sequence since the result could be affected by other tests
# running in parallel. # running in parallel.
if [ $RES -eq 0 ]; then if [ $RES -eq 0 ]; then
export RUST_BACKTRACE=1 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=$? RES=$?
fi fi

View File

@ -88,7 +88,7 @@ echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
sudo chmod a+rwX /dev/hugepages sudo chmod a+rwX /dev/hugepages
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
time target/$BUILD_TARGET/release/performance-metrics time target/$BUILD_TARGET/release/performance-metrics ${test_binary_args[*]}
RES=$? RES=$?
exit $RES exit $RES

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
hypervisor="kvm" hypervisor="kvm"
test_filter="" test_filter=""
test_binary_args=()
cmd_help() { cmd_help() {
echo "" echo ""
@ -28,12 +29,20 @@ process_common_args() {
shift shift
test_filter="$1" test_filter="$1"
;; ;;
"--") {
shift
break
} ;;
*) *)
;; echo "Unknown test scripts argument: $1. Please use '-- --help' for help."
exit
;;
esac esac
shift shift
done done
if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then
die "Hypervisor value must be kvm or mshv" die "Hypervisor value must be kvm or mshv"
fi fi
test_binary_args="$@"
} }