From c96cd27a2eee1010e76cd77e82e0d8825cf53d5a Mon Sep 17 00:00:00 2001 From: Hongyu Ning Date: Mon, 23 Oct 2023 16:49:13 +0800 Subject: [PATCH] [guest-test] Test Enhance: tab format unified across all source code all tab format unified to 2 spaces across all source code [Test Components] tdx [Test Types] func [Supported Devices] spr,emr,gnr.srf Signed-off-by: Hongyu Ning --- guest-test/guest.test_launcher.sh | 62 +++++------ guest-test/qemu.config.json | 88 +++++++-------- guest-test/qemu_get_config.py | 142 ++++++++++++------------- guest-test/qemu_runner.py | 12 +-- guest-test/tdx/tdx_attest_check.sh | 114 ++++++++++---------- guest-test/tdx/tdx_guest_boot_check.sh | 46 ++++---- 6 files changed, 232 insertions(+), 232 deletions(-) diff --git a/guest-test/guest.test_launcher.sh b/guest-test/guest.test_launcher.sh index 3284e8d5..075a6027 100755 --- a/guest-test/guest.test_launcher.sh +++ b/guest-test/guest.test_launcher.sh @@ -75,7 +75,7 @@ EOF } guest_kernel_reboot() { - sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF + sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF systemctl reboot --reboot-argument=now EOF } @@ -86,11 +86,11 @@ source ../.env ## PART 0: prepare test prerequisites ## if [ ! "$(which sshpass)" ]; then - dnf install -y sshpass > /dev/null - apt install -y sshpass > /dev/null + dnf install -y sshpass > /dev/null + apt install -y sshpass > /dev/null else - test_print_trc "sshpass prerequisites is ready for use" - test_print_trc "VM test is starting now..." + test_print_trc "sshpass prerequisites is ready for use" + test_print_trc "VM test is starting now..." fi ## PART 1: get params from qemu.cfg.json and script args ## @@ -142,7 +142,7 @@ while getopts :v:s:m:d:t:x:c:p:g:h arg; do GCOV=$OPTARG echo GCOV="\"$GCOV\"" >> "$SCRIPT_DIR"/test_params.py ;; - h) + h) usage && exit 0 ;; :) @@ -205,13 +205,13 @@ export GCOV 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" + echo "[${VM_TYPE}_vm]: $line" # within $TIMEOUT but bypass the very first 2 seconds to avoid unexpected $BOOT_PATTERN match (from parameter handling logic) - if [[ $SECONDS -lt $TIMEOUT ]] && [[ $SECONDS -ge 2 ]]; then - if [[ $line == $BOOT_PATTERN ]] && [[ $EXEC_FLAG -ne 0 ]]; then - test_print_trc "VM_TYPE: $VM_TYPE, VCPU: $VCPU, SOCKETS: $SOCKETS, MEM: $MEM, DEBUG: $DEBUG, PMU: $PMU, CMDLINE: $CMDLINE, TESTCASE: $TESTCASE, SECONDS: $SECONDS" + if [[ $SECONDS -lt $TIMEOUT ]] && [[ $SECONDS -ge 2 ]]; then + if [[ $line == $BOOT_PATTERN ]] && [[ $EXEC_FLAG -ne 0 ]]; then + test_print_trc "VM_TYPE: $VM_TYPE, VCPU: $VCPU, SOCKETS: $SOCKETS, MEM: $MEM, DEBUG: $DEBUG, PMU: $PMU, CMDLINE: $CMDLINE, TESTCASE: $TESTCASE, SECONDS: $SECONDS" EXEC_FLAG=0 - if ! ./guest.test_executor.sh; then EXEC_FLAG=1 && break; fi # break while read loop in case of TD VM test failure + if ! ./guest.test_executor.sh; then EXEC_FLAG=1 && break; fi # break while read loop in case of TD VM test failure # err_handlers string matching elif [[ $line == $ERR_STR1 ]]; then test_print_err "There is $ERR_STR1, test is not fully PASS" @@ -228,11 +228,11 @@ while read -r line; do elif [[ $line == $ERR_STR5 ]]; then test_print_wrg "There is $ERR_STR5, please check" ERR_FLAG5=1 - fi + fi # end of err_handlers string matching - elif [[ $SECONDS -ge $TIMEOUT ]]; then # break while read loop in case of TD VM boot timeout (no $BOOT_PATTERN found) - break - fi + 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 test_print_trc "${VM_TYPE}vm_$PORT keep alive for gcov data collection" && ./guest.qemu_runner.sh; fi) @@ -278,28 +278,28 @@ sleep 3 # 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 ! guest_kernel_check; 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 - pkill "${VM_TYPE}vm_$PORT" - die "TEST TIMEOUT!!!!!!!!!!!!" - elif [ "$GCOV" == "off" ] && [ "$EXEC_FLAG" -eq 1 ]; 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 + pkill "${VM_TYPE}vm_$PORT" + die "TEST TIMEOUT!!!!!!!!!!!!" + elif [ "$GCOV" == "off" ] && [ "$EXEC_FLAG" -eq 1 ]; then pkill "${VM_TYPE}vm_$PORT" - die "$VM_TYPE VM test seems fail at beginning, please check test log" - fi + die "$VM_TYPE VM test seems fail at beginning, please check test log" + fi # guest_kernel_kernel function zero return value shows TDVM is still accessible handling # handling: no matter why it's still accessible, close it by guest_kernel_reboot function elif [ "$GCOV" == "off" ]; then - if ! guest_kernel_reboot; then - test_print_trc "$VM_TYPE VM is still up" - test_print_trc "time: $SECONDS" - test_print_trc "SSHPASS: $SSHPASS" - test_print_trc "PORT: $PORT" - test_print_trc "$VM_TYPE VM closed" + if ! guest_kernel_reboot; then + test_print_trc "$VM_TYPE VM is still up" + test_print_trc "time: $SECONDS" + test_print_trc "SSHPASS: $SSHPASS" + test_print_trc "PORT: $PORT" + test_print_trc "$VM_TYPE VM closed" # must die here since TDVM should be closed and not accessible if test complete all correctly # else it's due to test die before reaching final close point td_test_close function - die "$VM_TYPE VM test fail, please check test log" - fi + die "$VM_TYPE VM test fail, please check test log" + fi else # [ $GCOV == "on" ] || [ guest_kernel_check return 0 ] test_print_trc "${VM_TYPE}vm_$PORT keep alive for gcov data collection" test_print_trc "'ssh -p $PORT root@localhost' with PASSWORD '$SSHPASS' to login and get data" diff --git a/guest-test/qemu.config.json b/guest-test/qemu.config.json index 565bcfbb..5fd58edf 100644 --- a/guest-test/qemu.config.json +++ b/guest-test/qemu.config.json @@ -1,49 +1,49 @@ { - "common": { - "kernel_img": "/boot/vmlinuz-xxx-yyy", - "initrd_img": "/boot/initramfs-xxx-yyy", - "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*an*x86_64*", - "guest_root_passwd": "123456", - "vm_type": "tdx", - "pmu": "off", - "cpus": "4", - "sockets": "1", - "mem": "16", - "cmdline": "accept_memory=lazy", - "debug": "on" - }, + "common": { + "kernel_img": "/boot/vmlinuz-xxx-yyy", + "initrd_img": "/boot/initramfs-xxx-yyy", + "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*an*x86_64*", + "guest_root_passwd": "123456", + "vm_type": "tdx", + "pmu": "off", + "cpus": "4", + "sockets": "1", + "mem": "16", + "cmdline": "accept_memory=lazy", + "debug": "on" + }, - "vm": { - "cfg_1": "-accel kvm -no-reboot -nographic -vga none -device virtio-net-pci,netdev=mynet0,mac=DE:AD:BE:EF:AB:CD,romfile= ", - "cfg_2": "-chardev stdio,id=mux,mux=on,signal=off -device virtio-serial,romfile= -device virtconsole,chardev=mux ", - "cfg_3": "-serial chardev:mux -monitor chardev:mux -monitor pty -no-hpet -nodefaults ", - "cfg_var_1": "-name process=$VM_TYPEVM_$PORT,debug-threads=on ", - "cfg_var_2": "-cpu host,host-phys-bits,pmu=$PMU ", - "cfg_var_3": "-smp cpus=$VCPU,sockets=$SOCKETS ", - "cfg_var_4": "-m $MEMG ", - "cfg_var_5": "-kernel $KERNEL_IMG ", - "cfg_var_6": "-initrd $INITRD_IMG", - "cfg_var_7": "-netdev user,id=mynet0,hostfwd=tcp::$PORT-:22 ", - "cfg_var_8": "-drive file=$GUEST_IMG,if=virtio,format=$IMG_FORMAT ", - "cfg_var_9": "-append \"root=/dev/vda3 ro console=hvc0 earlyprintk=ttyS0 ignore_loglevel debug earlyprintk l1tf=off initcall_debug log_buf_len=200M nokaslr tsc=reliable efi=debug mce=off efi=debug $CMDLINE\" ", - "cfg_var_10": "-bios $BIOS_IMG " - }, + "vm": { + "cfg_1": "-accel kvm -no-reboot -nographic -vga none -device virtio-net-pci,netdev=mynet0,mac=DE:AD:BE:EF:AB:CD,romfile= ", + "cfg_2": "-chardev stdio,id=mux,mux=on,signal=off -device virtio-serial,romfile= -device virtconsole,chardev=mux ", + "cfg_3": "-serial chardev:mux -monitor chardev:mux -monitor pty -no-hpet -nodefaults ", + "cfg_var_1": "-name process=$VM_TYPEVM_$PORT,debug-threads=on ", + "cfg_var_2": "-cpu host,host-phys-bits,pmu=$PMU ", + "cfg_var_3": "-smp cpus=$VCPU,sockets=$SOCKETS ", + "cfg_var_4": "-m $MEMG ", + "cfg_var_5": "-kernel $KERNEL_IMG ", + "cfg_var_6": "-initrd $INITRD_IMG", + "cfg_var_7": "-netdev user,id=mynet0,hostfwd=tcp::$PORT-:22 ", + "cfg_var_8": "-drive file=$GUEST_IMG,if=virtio,format=$IMG_FORMAT ", + "cfg_var_9": "-append \"root=/dev/vda3 ro console=hvc0 earlyprintk=ttyS0 ignore_loglevel debug earlyprintk l1tf=off initcall_debug log_buf_len=200M nokaslr tsc=reliable efi=debug mce=off efi=debug $CMDLINE\" ", + "cfg_var_10": "-bios $BIOS_IMG " + }, - "tdx": { - "cfg_1": "-machine q35,kernel_irqchip=split,confidential-guest-support=tdx,memory-backend=ram1 ", - "cfg_var_1": "-object tdx-guest,id=tdx,debug=$DEBUG,sept-ve-disable=on,quote-generation-service=vsock:2:4050 ", - "cfg_var_2": "-object memory-backend-memfd-private,id=ram1,size=$MEMG " - }, + "tdx": { + "cfg_1": "-machine q35,kernel_irqchip=split,confidential-guest-support=tdx,memory-backend=ram1 ", + "cfg_var_1": "-object tdx-guest,id=tdx,debug=$DEBUG,sept-ve-disable=on,quote-generation-service=vsock:2:4050 ", + "cfg_var_2": "-object memory-backend-memfd-private,id=ram1,size=$MEMG " + }, - "tdxio": { - "cfg_1": "-object iommufd,id=iommufd0 ", - "cfg_2": "-device vfio-pci,host=tee_bdf1,id=hostdev2,addr=0x3,x-secure-mode=on ", - "cfg_3": "-device vfio-pci,host=tee_bdf2,id=hostdev3,addr=0x4,x-secure-mode=on ", - "cfg_4": "-device vfio-pci,host=tee_bdf3,id=hostdev4,addr=0x5,x-secure-mode=on ", - "cfg_5": "-device vfio-pci,host=tee_bdf4,id=hostdev5,addr=0x6,x-secure-mode=on " - } + "tdxio": { + "cfg_1": "-object iommufd,id=iommufd0 ", + "cfg_2": "-device vfio-pci,host=tee_bdf1,id=hostdev2,addr=0x3,x-secure-mode=on ", + "cfg_3": "-device vfio-pci,host=tee_bdf2,id=hostdev3,addr=0x4,x-secure-mode=on ", + "cfg_4": "-device vfio-pci,host=tee_bdf3,id=hostdev4,addr=0x5,x-secure-mode=on ", + "cfg_5": "-device vfio-pci,host=tee_bdf4,id=hostdev5,addr=0x6,x-secure-mode=on " + } } \ No newline at end of file diff --git a/guest-test/qemu_get_config.py b/guest-test/qemu_get_config.py index d9e906d0..d21cc47c 100755 --- a/guest-test/qemu_get_config.py +++ b/guest-test/qemu_get_config.py @@ -25,9 +25,9 @@ # read from qemu.config.json format for all raw qemu vm config cwd = Path(os.getcwd()) if cwd.stem == "guest-test": - raw_config = Path(f"{os.getcwd()}/qemu.config.json").read_text() + raw_config = Path(f"{os.getcwd()}/qemu.config.json").read_text() else: - exit(1) + exit(1) qemu_config = json.loads(raw_config) @@ -54,40 +54,40 @@ # O-list variables default value from qemu.config.json vm_type = qemu_config["common"]["vm_type"] if 'PMU' in dir(): - pmu = PMU + pmu = PMU else: - pmu = qemu_config["common"]["pmu"] + pmu = qemu_config["common"]["pmu"] if 'VCPU' in dir(): - cpus = VCPU + cpus = VCPU else: - cpus = qemu_config["common"]["cpus"] + cpus = qemu_config["common"]["cpus"] if 'SOCKETS' in dir(): - sockets = SOCKETS + sockets = SOCKETS else: - sockets = qemu_config["common"]["sockets"] + sockets = qemu_config["common"]["sockets"] if 'MEM' in dir(): - mem = MEM + mem = MEM else: - mem = qemu_config["common"]["mem"] + mem = qemu_config["common"]["mem"] if 'CMDLINE' in dir(): - cmdline = CMDLINE + cmdline = CMDLINE else: - cmdline = qemu_config["common"]["cmdline"] + cmdline = qemu_config["common"]["cmdline"] if 'DEBUG' in dir(): - debug = DEBUG + debug = DEBUG else: - debug = qemu_config["common"]["debug"] + debug = qemu_config["common"]["debug"] if 'TESTCASE' in dir(): - testcase = TESTCASE + testcase = TESTCASE else: - print("No TESTCASE info found, can't run any test!") - exit(1) + print("No TESTCASE info found, can't run any test!") + exit(1) # O-list variables override value handling with args passed options, not used in framework, keep it for customization params_o_list = argparse.ArgumentParser() @@ -111,21 +111,21 @@ # NOTICE!! O-list veriables' value will be override if passed through above args option if args.vmtype is not None: - vm_type = args.vmtype + vm_type = args.vmtype if args.pmu is not None: - pmu = args.pmu + pmu = args.pmu if args.cpus is not None: - cpus = args.cpus + cpus = args.cpus if args.sockets is not None: - sockets = args.sockets + sockets = args.sockets if args.mem is not None: - mem = args.mem + mem = args.mem if args.cmdline is not None: - cmdline = args.cmdline + cmdline = args.cmdline if args.debug is not None: - debug = args.debug + debug = args.debug if args.testcase is not None: - testcase = args.testcase + testcase = args.testcase # end of O-list variables handling @@ -138,18 +138,18 @@ qemu_config["vm"]["cfg_var_5"] = qemu_config["vm"]["cfg_var_5"].replace("$KERNEL_IMG", kernel_img) # bypass -initrd config option in case it's not provided if os.path.isfile(initrd_img): - qemu_config["vm"]["cfg_var_6"] = qemu_config["vm"]["cfg_var_6"].replace("$INITRD_IMG", initrd_img) + qemu_config["vm"]["cfg_var_6"] = qemu_config["vm"]["cfg_var_6"].replace("$INITRD_IMG", initrd_img) else: - qemu_config["vm"]["cfg_var_6"] = "" + qemu_config["vm"]["cfg_var_6"] = "" qemu_config["vm"]["cfg_var_7"] = qemu_config["vm"]["cfg_var_7"].replace("$PORT", str(port)) qemu_config["vm"]["cfg_var_8"] = qemu_config["vm"]["cfg_var_8"].replace("$GUEST_IMG", guest_img).replace("$IMG_FORMAT", guest_img_format) qemu_config["vm"]["cfg_var_9"] = qemu_config["vm"]["cfg_var_9"].replace("$CMDLINE", cmdline) # bypass -bios config option in case it's not provided, default seabios to use if os.path.isfile(bios_img): - qemu_config["vm"]["cfg_var_10"] = qemu_config["vm"]["cfg_var_10"].replace("$BIOS_IMG", bios_img) + qemu_config["vm"]["cfg_var_10"] = qemu_config["vm"]["cfg_var_10"].replace("$BIOS_IMG", bios_img) else: - qemu_config["vm"]["cfg_var_10"] = "" + qemu_config["vm"]["cfg_var_10"] = "" qemu_config["tdx"]["cfg_var_1"] = qemu_config["tdx"]["cfg_var_1"].replace("$DEBUG", debug) qemu_config["tdx"]["cfg_var_2"] = qemu_config["tdx"]["cfg_var_2"].replace("$MEM", str(mem)) @@ -158,31 +158,31 @@ ###################### Functions ###################### def get_sub_keys(d, key): - """ - Recursively get all 2nd-level keys in a dictionary. - """ - if isinstance(d, dict): - for k, v in d.items(): - if isinstance(v, dict): - if k == key: - for k2 in v.keys(): - yield k2 + """ + Recursively get all 2nd-level keys in a dictionary. + """ + if isinstance(d, dict): + for k, v in d.items(): + if isinstance(v, dict): + if k == key: + for k2 in v.keys(): + yield k2 def print_sub_keys(l, key): - """ - Recursively get each 2nd-level key. - """ - print("Key %s has sub-keys:" %(key)) - for i in l: - print(i) + """ + Recursively get each 2nd-level key. + """ + print("Key %s has sub-keys:" %(key)) + for i in l: + print(i) def get_sub_cfgs(l, key, result=""): - """ - Recursively collect all 2nd-level key cfg string. - """ - for i in l: - result += qemu_config[key][i] - return result + """ + Recursively collect all 2nd-level key cfg string. + """ + for i in l: + result += qemu_config[key][i] + return result ###################### Do Works ###################### #common_keys = list(get_sub_keys(qemu_config, "common")) @@ -192,30 +192,30 @@ def get_sub_cfgs(l, key, result=""): #print_sub_keys(vm_keys, "vm") 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(vm_cfg) + 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(vm_cfg) #print_sub_keys(tdx_keys, "tdx") if vm_type == "tdx": - 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(vm_cfg) - print("#### qemu config option, part 2 ####") - print(tdx_cfg) + 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(vm_cfg) + print("#### qemu config option, part 2 ####") + print(tdx_cfg) #print_sub_keys(tdxio_keys, "tdxio") if vm_type == "tdxio": - vm_cfg = get_sub_cfgs(vm_keys, "vm") - 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(vm_cfg) - print("#### qemu config option, part 2 ####") - print(tdx_cfg) - print("#### qemu config option, part 3 ####") - print(tdxio_cfg) \ No newline at end of file + vm_cfg = get_sub_cfgs(vm_keys, "vm") + 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(vm_cfg) + print("#### qemu config option, part 2 ####") + print(tdx_cfg) + print("#### qemu config option, part 3 ####") + print(tdxio_cfg) \ No newline at end of file diff --git a/guest-test/qemu_runner.py b/guest-test/qemu_runner.py index 6164352e..cb5ada75 100644 --- a/guest-test/qemu_runner.py +++ b/guest-test/qemu_runner.py @@ -27,15 +27,15 @@ ###################### Do Works ###################### # launch legacy common vm based on vm_type config if vm_type == "legacy": - command = '{} {}'.format(qemu_img, vm_cfg) - sp.run(command, shell=True) + command = '{} {}'.format(qemu_img, vm_cfg) + sp.run(command, shell=True) # launch tdx vm based on vm_type config if vm_type == "tdx": - command = '{} {} {}'.format(qemu_img, vm_cfg, tdx_cfg) - sp.run(command, shell=True) + command = '{} {} {}'.format(qemu_img, vm_cfg, tdx_cfg) + sp.run(command, shell=True) # launch tdxio vm based on vm_type config if vm_type == "tdxio": - command = '{} {} {} {}'.format(qemu_img, vm_cfg, tdx_cfg, tdxio_cfg) - sp.run(command, shell=True) + command = '{} {} {} {}'.format(qemu_img, vm_cfg, tdx_cfg, tdxio_cfg) + sp.run(command, shell=True) \ No newline at end of file diff --git a/guest-test/tdx/tdx_attest_check.sh b/guest-test/tdx/tdx_attest_check.sh index 0fdada8e..ccde1059 100755 --- a/guest-test/tdx/tdx_attest_check.sh +++ b/guest-test/tdx/tdx_attest_check.sh @@ -16,69 +16,69 @@ echo "$SCRIPT_DIR" source common.sh while getopts :t: arg; do - case $arg in - t) - ATTEST_CASE=$OPTARG - ;; - *) - test_print_err "Must supply an argument to -$OPTARG." - exit 1 - ;; - esac + case $arg in + t) + ATTEST_CASE=$OPTARG + ;; + *) + test_print_err "Must supply an argument to -$OPTARG." + exit 1 + ;; + esac done ###################### Functions ###################### attest_result() { - selftest_item=$1 - case "$selftest_item" in - global.verify_report) - selftest_num=1 - ;; - global.verify_reportmac) - selftest_num=2 - ;; - global.verify_rtmr_extend) - selftest_num=3 - ;; - global.verify_quote) - selftest_num=4 - ;; - esac - test_print_trc "TD attestation - $selftest_item start." - if [ -f "attest.log" ]; then - rm -rf attest.log - fi - ./tdx_guest_test | tee attest.log - results=$(grep "not ok $selftest_num $selftest_item" attest.log) - if [ -z "$results" ]; then - test_print_trc "TD attestation - $selftest_item PASS." - else - die "TD attestation - $selftest_item FAIL." - return 1 - fi + selftest_item=$1 + case "$selftest_item" in + global.verify_report) + selftest_num=1 + ;; + global.verify_reportmac) + selftest_num=2 + ;; + global.verify_rtmr_extend) + selftest_num=3 + ;; + global.verify_quote) + selftest_num=4 + ;; + esac + test_print_trc "TD attestation - $selftest_item start." + if [ -f "attest.log" ]; then + rm -rf attest.log + fi + ./tdx_guest_test | tee attest.log + results=$(grep "not ok $selftest_num $selftest_item" attest.log) + if [ -z "$results" ]; then + test_print_trc "TD attestation - $selftest_item PASS." + else + die "TD attestation - $selftest_item FAIL." + return 1 + fi } ###################### Do Works ###################### case "$ATTEST_CASE" in - global.verify_report) - attest_result "$ATTEST_CASE" - ;; - global.verify_reportmac) - attest_result "$ATTEST_CASE" - ;; - global.verify_rtmr_extend) - attest_result "$ATTEST_CASE" - ;; - global.verify_quote) - attest_result "$ATTEST_CASE" - ;; - :) - test_print_err "Must specify the attest case option by [-t]" - exit 1 - ;; - \?) - test_print_err "Input test case option $ATTEST_CASE is not supported" - exit 1 - ;; -esac \ No newline at end of file + global.verify_report) + attest_result "$ATTEST_CASE" + ;; + global.verify_reportmac) + attest_result "$ATTEST_CASE" + ;; + global.verify_rtmr_extend) + attest_result "$ATTEST_CASE" + ;; + global.verify_quote) + attest_result "$ATTEST_CASE" + ;; + :) + test_print_err "Must specify the attest case option by [-t]" + exit 1 + ;; + \?) + test_print_err "Input test case option $ATTEST_CASE is not supported" + exit 1 + ;; +esac \ 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 5830db9b..4815c9bd 100755 --- a/guest-test/tdx/tdx_guest_boot_check.sh +++ b/guest-test/tdx/tdx_guest_boot_check.sh @@ -15,21 +15,21 @@ echo "$SCRIPT_DIR" source common.sh while getopts :v:s:m: arg; do - case $arg in - v) - VCPU=$OPTARG - ;; - s) - SOCKETS=$OPTARG - ;; - m) - MEM=$OPTARG - ;; - *) - test_print_err "Must supply an argument to -$OPTARG." - exit 1 - ;; - esac + case $arg in + v) + VCPU=$OPTARG + ;; + s) + SOCKETS=$OPTARG + ;; + m) + MEM=$OPTARG + ;; + *) + test_print_err "Must supply an argument to -$OPTARG." + exit 1 + ;; + esac done ###################### Do Works ###################### @@ -40,11 +40,11 @@ test_print_trc "vcpu_td: $vcpu_td" test_print_trc "sockets_td: $sockets_td" if [[ "$vcpu_td" -ne "$VCPU" ]]; then - die "Guest TD VM boot with vcpu: $vcpu_td (expected $VCPU)" + die "Guest TD VM boot with vcpu: $vcpu_td (expected $VCPU)" fi if [[ "$sockets_td" -ne "$SOCKETS" ]]; then - die "Guest TD VM boot with sockets: $sockets_td (expected $SOCKETS)" + die "Guest TD VM boot with sockets: $sockets_td (expected $SOCKETS)" fi # check memory size @@ -53,14 +53,14 @@ 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 - die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" - fi + 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 - die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" - fi + if [[ $(( MEM / mem_td )) -ne 1 ]]; then + die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" + fi fi test_print_trc "Guest TD VM boot up successfully with config:"