diff --git a/guest-test/guest.qemu_runner.sh b/guest-test/guest.qemu_runner.sh index a218acb8..b0bfd854 100755 --- a/guest-test/guest.qemu_runner.sh +++ b/guest-test/guest.qemu_runner.sh @@ -76,7 +76,7 @@ cd "$(dirname "$0")" 2>/dev/null || exit 1 source ../.env # get test scenario config for qemu_runner -source $SCRIPT_DIR/test_params.py +source "$SCRIPT_DIR"/test_params.py # do basic pre-check for TDX/TDXIO VM launching if [[ $VM_TYPE == "tdx" ]] || [[ $VM_TYPE == "tdxio" ]]; then @@ -85,4 +85,4 @@ fi # launch VM by qemu via qemu_runner.py test_print_trc "qemu_runner start to launch $VM_TYPE VM" -python3 $SCRIPT_DIR/qemu_runner.py \ No newline at end of file +python3 "$SCRIPT_DIR"/qemu_runner.py \ No newline at end of file diff --git a/guest-test/guest.test_executor.sh b/guest-test/guest.test_executor.sh index 13369ad9..e746fc78 100755 --- a/guest-test/guest.test_executor.sh +++ b/guest-test/guest.test_executor.sh @@ -24,14 +24,14 @@ guest_test_prepare() { rm -rf $GUEST_TEST_DIR mkdir $GUEST_TEST_DIR EOF - sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no common.sh root@localhost:$GUEST_TEST_DIR - sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no $1 root@localhost:$GUEST_TEST_DIR + sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no common.sh root@localhost:"$GUEST_TEST_DIR" + sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no $1 root@localhost:"$GUEST_TEST_DIR" test_print_trc "Guest VM test script prepare complete" } # function based on sshpass to scp $1 source_code_dir and compile $2 test_binary in Guest VM guest_test_source_code() { - sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no -r $1 root@localhost:$GUEST_TEST_DIR + sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no -r $1 root@localhost:"$GUEST_TEST_DIR" sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF source $GUEST_TEST_DIR/common.sh cd $GUEST_TEST_DIR/$1 @@ -78,9 +78,9 @@ cd "$(dirname "$0")" 2>/dev/null || exit 1 source ../.env # get test scenario config for test_executor -source $SCRIPT_DIR/test_params.py +source "$SCRIPT_DIR"/test_params.py -cd $SCRIPT_DIR +cd "$SCRIPT_DIR" || die "fail to switch to $SCRIPT_DIR" # select test_functions by $TEST_SCENARIO case "$TESTCASE" in TD_BOOT) diff --git a/guest-test/guest.test_launcher.sh b/guest-test/guest.test_launcher.sh index ebdda31d..1d50fd65 100755 --- a/guest-test/guest.test_launcher.sh +++ b/guest-test/guest.test_launcher.sh @@ -85,7 +85,7 @@ fi # generate a unified random port number in one test cycle PORT=$(shuf -i 10010-10900 -n 1) # generate test_params.py based on script args -echo PORT=$PORT > $SCRIPT_DIR/test_params.py +echo PORT="$PORT" > "$SCRIPT_DIR"/test_params.py # 1.1 get test scenario config related params from script args # append following params in above fresh new test_params.py @@ -96,39 +96,42 @@ while getopts :v:s:m:d:t:x:c:p:g:h arg; do case $arg in v) VCPU=$OPTARG - echo VCPU=$VCPU >> $SCRIPT_DIR/test_params.py + echo VCPU="$VCPU" >> "$SCRIPT_DIR"/test_params.py ;; s) SOCKETS=$OPTARG - echo SOCKETS=$SOCKETS >> $SCRIPT_DIR/test_params.py + echo SOCKETS="$SOCKETS" >> "$SCRIPT_DIR"/test_params.py ;; m) MEM=$OPTARG - echo MEM=$MEM >> $SCRIPT_DIR/test_params.py + echo MEM="$MEM" >> "$SCRIPT_DIR"/test_params.py ;; d) DEBUG=$OPTARG - echo DEBUG=\"$DEBUG\" >> $SCRIPT_DIR/test_params.py + echo DEBUG="\"$DEBUG\"" >> "$SCRIPT_DIR"/test_params.py ;; t) VM_TYPE=$OPTARG - echo VM_TYPE=\"$VM_TYPE\" >> $SCRIPT_DIR/test_params.py + echo VM_TYPE="\"$VM_TYPE\"" >> "$SCRIPT_DIR"/test_params.py ;; x) TESTCASE=$OPTARG - echo TESTCASE=\"$TESTCASE\" >> $SCRIPT_DIR/test_params.py + echo TESTCASE="\"$TESTCASE\"" >> "$SCRIPT_DIR"/test_params.py ;; c) CMDLINE=$OPTARG - echo CMDLINE=\"$CMDLINE\" >> $SCRIPT_DIR/test_params.py + echo CMDLINE="\"$CMDLINE\"" >> "$SCRIPT_DIR"/test_params.py ;; p) PMU=$OPTARG - echo PMU=\"$PMU\" >> $SCRIPT_DIR/test_params.py + echo PMU="\"$PMU\"" >> "$SCRIPT_DIR"/test_params.py ;; g) GCOV=$OPTARG - echo GCOV=\"$GCOV\" >> $SCRIPT_DIR/test_params.py + echo GCOV="\"$GCOV\"" >> "$SCRIPT_DIR"/test_params.py + ;; + h) + usage && exit 0 ;; :) test_print_err "Must supply an argument to -$OPTARG." @@ -148,15 +151,15 @@ done # $GUEST_IMG_FORMAT $BOOT_PATTERN $SSHPASS $PORT #global_variable -output=$(python3 $SCRIPT_DIR/qemu_get_config.py) -KERNEL_IMG=$(echo $output | awk '{print $1}') -INITRD_IMG=$(echo $output | awk '{print $2}') -BIOS_IMG=$(echo $output | awk '{print $3}') -QEMU_IMG=$(echo $output | awk '{print $4}') -GUEST_IMG=$(echo $output | awk '{print $5}') -GUEST_IMG_FORMAT=$(echo $output | awk '{print $6}') -BOOT_PATTERN=$(echo $output | awk '{print $7}') -SSHPASS=$(echo $output | awk '{print $8}') +output=$(python3 "$SCRIPT_DIR"/qemu_get_config.py) +KERNEL_IMG=$(echo "$output" | awk '{print $1}') +INITRD_IMG=$(echo "$output" | awk '{print $2}') +BIOS_IMG=$(echo "$output" | awk '{print $3}') +QEMU_IMG=$(echo "$output" | awk '{print $4}') +GUEST_IMG=$(echo "$output" | awk '{print $5}') +GUEST_IMG_FORMAT=$(echo "$output" | awk '{print $6}') +BOOT_PATTERN=$(echo "$output" | awk '{print $7}') +SSHPASS=$(echo "$output" | awk '{print $8}') test_print_trc "KERNEL_IMG $KERNEL_IMG" test_print_trc "INITRD_IMG $INITRD_IMG" @@ -187,7 +190,7 @@ export GCOV # 2.3 check TD VM boot $ERR_STRs, then run corresponding err_handler ($ERR_FLAGs) # 2.4 break while loop if reach $TIMEOUT seconds (in case of TD VM boot hang) -cd $SCRIPT_DIR +cd "$SCRIPT_DIR" || die "fail to switch to $SCRIPT_DIR" rm -rf /root/.ssh/known_hosts while read -r line; do echo "[${VM_TYPE}_vm]: $line" @@ -201,19 +204,19 @@ while read -r line; do break fi # err_handlers string matching - elif [[ $line == $ERR_STR1 ]]; then + elif [[ $line == "$ERR_STR1" ]]; then test_print_err "There is $ERR_STR1, test is not fully PASS" ERR_FLAG1=1 - elif [[ $line == $ERR_STR2 ]]; then + elif [[ $line == "$ERR_STR2" ]]; then test_print_err "There is $ERR_STR2, test failed" ERR_FLAG2=1 - elif [[ $line == $ERR_STR3 ]] && [[ $line != *"DEBUG"* ]]; then + elif [[ $line == "$ERR_STR3" ]] && [[ $line != *"DEBUG"* ]]; then test_print_wrg "There is $ERR_STR3, please check" ERR_FLAG3=1 - elif [[ $line == $ERR_STR4 ]]; then + elif [[ $line == "$ERR_STR4" ]]; then test_print_wrg "There is $ERR_STR4, please check" ERR_FLAG4=1 - elif [[ $line == $ERR_STR5 ]]; then + elif [[ $line == "$ERR_STR5" ]]; then test_print_wrg "There is $ERR_STR5, please check" ERR_FLAG5=1 fi @@ -221,7 +224,7 @@ while read -r line; do elif [[ $SECONDS -ge $TIMEOUT ]]; then # break while read loop in case of TD VM boot timeout (no $BOOT_PATTERN found) break fi -done < <(if [ $GCOV == "off" ]; then timeout $TIMEOUT ./guest.qemu_runner.sh; else ./guest.qemu_runner.sh; fi) +done < <(if [ "$GCOV" == "off" ]; then timeout "$TIMEOUT" ./guest.qemu_runner.sh; else ./guest.qemu_runner.sh; fi) ## PART 3: err_handlers error management # unexpected error/bug/warning/call trace handling @@ -269,17 +272,17 @@ EOF # time count less or qual than 3 is case b # - handling: nothing to do, die for TDVM boot early failure, likely qemu config issue if [ $? -ne 0 ]; then - if [ $SECONDS -gt 3 ] && [ $SECONDS -lt $TIMEOUT ] && [ $EXEC_FLAG -eq 0 ]; then + if [ "$SECONDS" -gt 3 ] && [ "$SECONDS" -lt "$TIMEOUT" ] && [ "$EXEC_FLAG" -eq 0 ]; then test_print_trc "$VM_TYPE VM test complete..." - elif [ $SECONDS -ge $TIMEOUT ] && [ $GCOV == "on" ]; then + elif [ "$SECONDS" -ge "$TIMEOUT" ] && [ "$GCOV" == "on" ]; then pkill "${VM_TYPE}vm_$PORT" die "TEST TIMEOUT!!!!!!!!!!!!" - elif [ $GCOV == "off" ]; then + elif [ "$GCOV" == "off" ]; then die "$VM_TYPE VM test seems fail at beginning, please check test log" fi # zero return value shows TDVM is still accessible handling # handing: no matter why it's still accessible, close it by ssh login -elif [ $GCOV == "off" ]; then +elif [ "$GCOV" == "off" ]; then sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF echo "$VM_TYPE VM guest kernel under test:" uname -r @@ -303,7 +306,7 @@ fi ## PART 5: clean up at test execution ends, kill tdvm_$PORT process if it's still up ## # VM life-cycles management step 3 # Kill the tdvm_$PORT process in case above ssh command close not accessible due to network or other issues -if [ $GCOV == "off" ]; then +if [ "$GCOV" == "off" ]; then pgrep "${VM_TYPE}vm_$PORT" if [ $? -ne 0 ]; then test_print_trc "$VM_TYPE VM test complete all correctly..." @@ -312,4 +315,4 @@ if [ $GCOV == "off" ]; then test_print_wrg "${VM_TYPE}vm_$PORT process is still up, kill it since test expected to end here" die "$VM_TYPE VM test fail, please check test log" fi -fi +fi \ No newline at end of file diff --git a/guest-test/qemu.config.json b/guest-test/qemu.config.json index 63fafcaa..49243370 100644 --- a/guest-test/qemu.config.json +++ b/guest-test/qemu.config.json @@ -1,10 +1,10 @@ { "common": { - "kernel_img": "/tdx/home/sdp/tdx/guest_kernel_github/tdx/arch/x86/boot/bzImage.guest-next.0105", + "kernel_img": "/boot/vmlinuz-xxx-yyy", "initrd_img": "/boot/initramfs-xxx-yyy", - "bios_img": "/tdx/home/sdp/tdx/hongyu/OVMF.edk2-stable202211.fd", - "qemu_img": "/tdx/home/sdp/tdx/host_qemu_github/qemu-tdx/build/qemu-system-x86_64.tdx-qemu-2023-3-13-v7.2-kvm-upstream-2023.03.10-v6.2-wa", - "guest_img": "/tdx/home/sdp/tdx/hongyu/emr-bkc-centos-stream-9-coreserver-host-6.2-13.3-43.image", + "bios_img": "/path/to/EDKII/OVMF.fd or other virtual BIOS", + "qemu_img": "/path/to/qemu-kvm with proper capabilty of VM test", + "guest_img": "/path/to/prepared/guest_os_image, in qcow2 or raw image format", "guest_img_format": "raw", "boot_pattern": "*Kernel*on*x86_64*", "guest_root_passwd": "123456", diff --git a/guest-test/qemu_get_config.py b/guest-test/qemu_get_config.py index 2179ad3a..d3325074 100755 --- a/guest-test/qemu_get_config.py +++ b/guest-test/qemu_get_config.py @@ -202,7 +202,7 @@ def get_sub_cfgs(l, key, result=""): if vm_type == "legacy": vm_cfg = get_sub_cfgs(vm_keys, "vm") print("HERE're all the vm configs to launch legacy vm:") - print("qemu config option, part 1:") + print("#### qemu config option, part 1 ####") print(vm_cfg) #print_sub_keys(tdx_keys, "tdx") @@ -210,9 +210,9 @@ def get_sub_cfgs(l, key, result=""): vm_cfg = get_sub_cfgs(vm_keys, "vm") tdx_cfg = get_sub_cfgs(tdx_keys, "tdx") print("HERE're all the tdx configs to launch tdx vm:") - print("qemu config option, part 1:") + print("#### qemu config option, part 1 ####") print(vm_cfg) - print("qemu config option, part 2:") + print("#### qemu config option, part 2 ####") print(tdx_cfg) #print_sub_keys(tdxio_keys, "tdxio") @@ -221,9 +221,9 @@ def get_sub_cfgs(l, key, result=""): tdx_cfg = get_sub_cfgs(tdx_keys, "tdx") tdxio_cfg = get_sub_cfgs(tdxio_keys, "tdxio") print("HERE're all the tdx configs to launch tdxio vm:") - print("qemu config option, part 1:") + print("#### qemu config option, part 1 ####") print(vm_cfg) - print("qemu config option, part 2:") + print("#### qemu config option, part 2 ####") print(tdx_cfg) - print("qemu config option, part 3:") - print(tdxio_cfg) + print("#### qemu config option, part 3 ####") + print(tdxio_cfg) \ No newline at end of file diff --git a/guest-test/tdx/tdx_guest_boot_check.sh b/guest-test/tdx/tdx_guest_boot_check.sh index 36e4382d..5830db9b 100755 --- a/guest-test/tdx/tdx_guest_boot_check.sh +++ b/guest-test/tdx/tdx_guest_boot_check.sh @@ -25,6 +25,10 @@ while getopts :v:s:m: arg; do m) MEM=$OPTARG ;; + *) + test_print_err "Must supply an argument to -$OPTARG." + exit 1 + ;; esac done @@ -49,12 +53,12 @@ test_print_trc "mem_td: $mem_td" # $MEM less than or equal to 4GB need special memory size check if [[ $MEM -le 4 ]]; then - if [[ $(( $MEM / $mem_td )) -lt 1 ]] || [[ $(( $MEM / $mem_td )) -gt 2 ]]; then + if [[ $(( MEM / mem_td )) -lt 1 ]] || [[ $(( MEM / mem_td )) -gt 2 ]]; then die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" fi # $MEM more than 4GB use general memory size check else - if [[ $(( $MEM / $mem_td )) -ne 1 ]]; then + if [[ $(( MEM / mem_td )) -ne 1 ]]; then die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" fi fi