From 27b5f8d7e3f092fc93a57165a29bc633f4cadfbf Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Tue, 17 Nov 2020 16:37:27 -0800 Subject: [PATCH] scripts: Add an option to accept hypervisor argument Signed-off-by: Muminul Islam --- scripts/dev_cli.sh | 36 ++++++++++++++++++------ scripts/run_cargo_tests.sh | 3 ++ scripts/run_integration_tests_aarch64.sh | 9 ++++-- scripts/run_integration_tests_sgx.sh | 10 +++++-- scripts/run_integration_tests_windows.sh | 10 +++++-- scripts/run_integration_tests_x86_64.sh | 14 +++++++-- scripts/run_unit_tests.sh | 5 +++- scripts/test-util.sh | 34 ++++++++++++++++++++++ 8 files changed, 102 insertions(+), 19 deletions(-) create mode 100644 scripts/test-util.sh diff --git a/scripts/dev_cli.sh b/scripts/dev_cli.sh index cada4da2e..0931c3a71 100755 --- a/scripts/dev_cli.sh +++ b/scripts/dev_cli.sh @@ -175,6 +175,7 @@ cmd_help() { echo " --release Build the release binaries." echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu" 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 " Run the Cloud Hypervisor tests." @@ -185,6 +186,7 @@ cmd_help() { echo " --integration-windows Run the Windows guest integration tests." echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu" echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol" + echo " --hypervisor Underlying hypervisor. Options kvm, mshv" echo " --all Run all tests." echo "" echo " build-container [--type]" @@ -205,6 +207,8 @@ cmd_help() { cmd_build() { build="debug" libc="gnu" + hypervisor="kvm" + features_build="" while [ $# -gt 0 ]; do case "$1" in @@ -221,6 +225,10 @@ cmd_build() { shift arg_vols="$1" ;; + "--hypervisor") + shift + hypervisor="$1" + ;; "--") { shift; break; } ;; *) die "Unknown build argument: $1. Please use --help for help." @@ -229,6 +237,9 @@ cmd_build() { shift done process_volumes_args + if [[ "$hypervisor" != "kvm" ]]; then + die "Hypervisor value must be kvm" + fi target="$(uname -m)-unknown-linux-${libc}" @@ -251,7 +262,7 @@ cmd_build() { --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ --env RUSTFLAGS="$rustflags" \ "$CTR_IMAGE" \ - cargo build --all \ + cargo build --all $features_build \ --target-dir "$CTR_CLH_CARGO_TARGET" \ "${cargo_args[@]}" && say "Binaries placed under $CLH_CARGO_TARGET/$target/$build" } @@ -278,7 +289,8 @@ cmd_tests() { integration_windows=false libc="gnu" arg_vols="" - + hypervisor="kvm" + saved_args=("$@") while [ $# -gt 0 ]; do case "$1" in "-h"|"--help") { cmd_help; exit 1; } ;; @@ -297,6 +309,10 @@ cmd_tests() { shift arg_vols="$1" ;; + "--hypervisor") + shift + hypervisor="$1" + ;; "--all") { cargo=true; unit=true; integration=true; } ;; "--") { shift; break; } ;; *) @@ -305,7 +321,9 @@ cmd_tests() { esac shift done - + if [[ "$hypervisor" != "kvm" ]]; then + die "Hypervisor value must be kvm" + fi process_volumes_args target="$(uname -m)-unknown-linux-${libc}" cflags="" @@ -315,7 +333,7 @@ cmd_tests() { cflags="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/" fi - if [ "$unit" = true ] ; then + if [[ "$unit" = true && $hypervisor = "kvm" ]] ; then say "Running unit tests for $target..." $DOCKER_RUNTIME run \ --workdir "$CTR_CLH_ROOT_DIR" \ @@ -328,7 +346,7 @@ cmd_tests() { --env CFLAGS="$cflags" \ --env TARGET_CC="$target_cc" \ "$CTR_IMAGE" \ - ./scripts/run_unit_tests.sh "$@" || fix_dir_perms $? || exit $? + ./scripts/run_unit_tests.sh "${saved_args[@]}" || fix_dir_perms $? || exit $? fi if [ "$cargo" = true ] ; then @@ -338,7 +356,7 @@ cmd_tests() { --rm \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" $exported_volumes \ "$CTR_IMAGE" \ - ./scripts/run_cargo_tests.sh || fix_dir_perms $? || exit $? + ./scripts/run_cargo_tests.sh "${saved_args[@]}" || fix_dir_perms $? || exit $? fi if [ "$integration" = true ] ; then @@ -357,7 +375,7 @@ cmd_tests() { --env USER="root" \ --env CH_LIBC="${libc}" \ "$CTR_IMAGE" \ - ./scripts/run_integration_tests_$(uname -m).sh "$@" || fix_dir_perms $? || exit $? + ./scripts/run_integration_tests_$(uname -m).sh "${saved_args[@]}" || fix_dir_perms $? || exit $? fi if [ "$integration_sgx" = true ] ; then @@ -376,7 +394,7 @@ cmd_tests() { --env USER="root" \ --env CH_LIBC="${libc}" \ "$CTR_IMAGE" \ - ./scripts/run_integration_tests_sgx.sh "$@" || fix_dir_perms $? || exit $? + ./scripts/run_integration_tests_sgx.sh "${saved_args[@]}" || fix_dir_perms $? || exit $? fi if [ "$integration_windows" = true ] ; then @@ -395,7 +413,7 @@ cmd_tests() { --env USER="root" \ --env CH_LIBC="${libc}" \ "$CTR_IMAGE" \ - ./scripts/run_integration_tests_windows.sh "$@" || fix_dir_perms $? || exit $? + ./scripts/run_integration_tests_windows.sh "${saved_args[@]}" || fix_dir_perms $? || exit $? fi fix_dir_perms $? } diff --git a/scripts/run_cargo_tests.sh b/scripts/run_cargo_tests.sh index 20127dfe0..96dba25a3 100755 --- a/scripts/run_cargo_tests.sh +++ b/scripts/run_cargo_tests.sh @@ -3,6 +3,9 @@ set -e set -x source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh + +process_common_args "$@" # Install cargo components time rustup component add clippy diff --git a/scripts/run_integration_tests_aarch64.sh b/scripts/run_integration_tests_aarch64.sh index 79e62b3ea..6ad58c5bb 100755 --- a/scripts/run_integration_tests_aarch64.sh +++ b/scripts/run_integration_tests_aarch64.sh @@ -2,6 +2,7 @@ set -x source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh export BUILD_TARGET=${BUILD_TARGET-aarch64-unknown-linux-gnu} @@ -177,6 +178,10 @@ update_workloads() { fi } +process_common_args "$@" +features_build="--no-default-features --features kvm " +features_test="--no-default-features --features integration_tests,kvm" + # lock the workloads folder to avoid parallel updating by different containers ( echo "try to lock $WORKLOADS_DIR folder and update" @@ -204,7 +209,7 @@ TARGET_CC="musl-gcc" CFLAGS="-I /usr/include/aarch64-linux-musl/ -idirafter /usr/include/" fi -cargo build --all --release --no-default-features --features kvm --target $BUILD_TARGET +cargo build --all --release $features_build --target $BUILD_TARGET strip target/$BUILD_TARGET/release/cloud-hypervisor strip target/$BUILD_TARGET/release/vhost_user_net strip target/$BUILD_TARGET/release/ch-remote @@ -216,7 +221,7 @@ sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs" sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run" export RUST_BACKTRACE=1 -time cargo test --no-default-features --features "integration_tests,kvm" "tests::parallel::$@" +time cargo test $features_test "tests::parallel::" RES=$? # Tear vhost_user_net test network down diff --git a/scripts/run_integration_tests_sgx.sh b/scripts/run_integration_tests_sgx.sh index 806ada439..6c35aeaf6 100755 --- a/scripts/run_integration_tests_sgx.sh +++ b/scripts/run_integration_tests_sgx.sh @@ -2,6 +2,12 @@ set -x source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh + +process_common_args "$@" +# For now these values are deafult for kvm +features_build="" +features_test="--features integration_tests" BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}" CFLAGS="" @@ -11,12 +17,12 @@ TARGET_CC="musl-gcc" CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/" fi -cargo build --all --release --target $BUILD_TARGET +cargo build --all --release $features_build --target $BUILD_TARGET strip target/$BUILD_TARGET/release/cloud-hypervisor export RUST_BACKTRACE=1 -time cargo test --features "integration_tests" "tests::sgx::$@" +time cargo test $features_test "tests::sgx::" RES=$? exit $RES diff --git a/scripts/run_integration_tests_windows.sh b/scripts/run_integration_tests_windows.sh index 77a928d78..82abd9afb 100755 --- a/scripts/run_integration_tests_windows.sh +++ b/scripts/run_integration_tests_windows.sh @@ -2,6 +2,12 @@ set -x source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh + +process_common_args "$@" +# For now these values are deafult for kvm +features_build="" +features_test="--features integration_tests" BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}" CFLAGS="" @@ -11,14 +17,14 @@ TARGET_CC="musl-gcc" CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/" fi -cargo build --all --release --target $BUILD_TARGET +cargo build --all --release $features_build --target $BUILD_TARGET strip target/$BUILD_TARGET/release/cloud-hypervisor 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 "integration_tests" "tests::windows::$@" -- --test-threads=1 +time cargo test $features_test "tests::windows::" -- --test-threads=1 RES=$? exit $RES diff --git a/scripts/run_integration_tests_x86_64.sh b/scripts/run_integration_tests_x86_64.sh index 3f7ae4525..d9cf0307c 100755 --- a/scripts/run_integration_tests_x86_64.sh +++ b/scripts/run_integration_tests_x86_64.sh @@ -2,12 +2,20 @@ set -x source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh export BUILD_TARGET=${BUILD_TARGET-x86_64-unknown-linux-gnu} WORKLOADS_DIR="$HOME/workloads" mkdir -p "$WORKLOADS_DIR" + +process_common_args "$@" + +# For now these values are deafult for kvm +features_build="" +features_test="--features integration_tests" + cp scripts/sha1sums-x86_64 $WORKLOADS_DIR FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]') @@ -215,7 +223,7 @@ TARGET_CC="musl-gcc" CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/" fi -cargo build --all --release --target $BUILD_TARGET +cargo build --all --release $features_build --target $BUILD_TARGET strip target/$BUILD_TARGET/release/cloud-hypervisor strip target/$BUILD_TARGET/release/vhost_user_net strip target/$BUILD_TARGET/release/ch-remote @@ -235,14 +243,14 @@ echo 4096 | sudo tee /proc/sys/vm/nr_hugepages sudo chmod a+rwX /dev/hugepages export RUST_BACKTRACE=1 -time cargo test --features "integration_tests" "tests::parallel::$@" +time cargo test $features_test "tests::parallel::" 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 "integration_tests" "tests::sequential::$@" -- --test-threads=1 + time cargo test $features_test "tests::sequential::" -- --test-threads=1 RES=$? fi diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh index dea876542..781ee378d 100755 --- a/scripts/run_unit_tests.sh +++ b/scripts/run_unit_tests.sh @@ -1,9 +1,12 @@ #!/bin/bash source $HOME/.cargo/env +source $(dirname "$0")/test-util.sh + +process_common_args "$@" BUILD_TARGET=${BUILD_TARGET-x86_64-unknown-linux-gnu} -cargo_args=("$@") +cargo_args=("") [ $(uname -m) = "aarch64" ] && cargo_args+=("--no-default-features") [ $(uname -m) = "aarch64" ] && cargo_args+=("--features kvm") diff --git a/scripts/test-util.sh b/scripts/test-util.sh new file mode 100644 index 000000000..373a49297 --- /dev/null +++ b/scripts/test-util.sh @@ -0,0 +1,34 @@ +#!/bin/bash +hypervisor="kvm" +cmd_help() { + echo "" + echo "Cloud Hypervisor $(basename $0)" + echo "Usage: $(basename $0) []" + echo "" + echo "Available arguments:" + echo "" + echo " --hypervisor Underlying hypervisor. Options kvm, mshv" + echo "" + echo " --help Display this help message." + echo "" +} + +process_common_args() { + while [ $# -gt 0 ]; do + case "$1" in + "-h"|"--help") { cmd_help; exit 1; } ;; + "--hypervisor") + shift + hypervisor="$1" + ;; + *) + # We only care about hypervisor , do nothing for other arguments + ;; + esac + shift + done + if [[ "$hypervisor" != "kvm" ]]; then + echo "Hypervisor value must be kvm" + exit 1 + fi +} \ No newline at end of file