diff --git a/guest-test/guest.test_executor.sh b/guest-test/guest.test_executor.sh index 30961054..557ccb5d 100755 --- a/guest-test/guest.test_executor.sh +++ b/guest-test/guest.test_executor.sh @@ -161,6 +161,14 @@ case "$TESTCASE" in guest_test_close fi ;; + TD_NET_SPEED) + guest_test_prepare tdx/tdx_speed_test.sh + guest_test_entry tdx_speed_test.sh || \ + die "Failed on TD_NET_SPEED tdx_speed_test.sh" + if [[ $GCOV == "off" ]]; then + guest_test_close + fi + ;; :) test_print_err "Must specify the test scenario option by [-t]" usage && exit 1 diff --git a/guest-test/osv_sanity/common.json b/guest-test/osv_sanity/common.json index 04d92b04..212c667e 100644 --- a/guest-test/osv_sanity/common.json +++ b/guest-test/osv_sanity/common.json @@ -1,10 +1,8 @@ { - "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", + "guest_img_format": "raw or qcow2", "boot_pattern": "*Kernel*on*an*x86_64*", "guest_root_passwd": "123456" } \ No newline at end of file diff --git a/guest-test/qemu_get_config.py b/guest-test/qemu_get_config.py index 5d79b711..28a98ae0 100755 --- a/guest-test/qemu_get_config.py +++ b/guest-test/qemu_get_config.py @@ -42,8 +42,14 @@ qemu_config = json.loads(raw_config) # pre-config G-list variables' values confirmed by common.json -kernel_img = image_config["kernel_img"] -initrd_img = image_config["initrd_img"] +if os.path.isfile(image_config["kernel_img"]): + kernel_img = image_config["kernel_img"] +else: + kernel_img = "not_use" +if os.path.isfile(image_config["initrd_img"]): + initrd_img = image_config["initrd_img"] +else: + initrd_img = "not_use" bios_img = image_config["bios_img"] qemu_img = image_config["qemu_img"] guest_img = image_config["guest_img"] diff --git a/guest-test/tdx/tdx_speed_test.sh b/guest-test/tdx/tdx_speed_test.sh new file mode 100755 index 00000000..1cb8f9dc --- /dev/null +++ b/guest-test/tdx/tdx_speed_test.sh @@ -0,0 +1,72 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) 2023 Intel Corporation + +# Author: Hongyu Ning +# +# History: 15, Nov., 2023 - Hongyu Ning - creation + + +# @desc This script do basic internet BW test in TDX Guest VM +# test tool based on speedtest-cli + +###################### Variables ###################### +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +echo "$SCRIPT_DIR" +source common.sh +ID=0 +DOWNLOAD=0 +DOWNLOAD_DATA=0 +UPLOAD=0 +UPLOAD_DATA=0 + +###################### Functions ###################### +float_num_compare() { + if awk -v n1="$1" -v n2="1" 'BEGIN {if (n1>n2) exit 0; exit 1}' + then + return 0 + else + return 1 + fi +} + +###################### Do Works ###################### +# prepare speedtest-cli +if [ ! "$(which speedtest-cli)" ]; then + dnf install -y speedtest-cli > /dev/null + apt install -y speedtest-cli > /dev/null +else + test_print_trc "speedtest-cli prerequisites is ready for use" + test_print_trc "TDVM internet BW test is starting now..." +fi + +# get nearest server ID for test +ID=$(speedtest-cli --list | awk -F')' 'NR==2 {print $1; exit}') +if [ "$ID" -gt 0 ]; then + test_print_trc "BW test server ID: $ID" +else + test_print_err "BW test get server failed" + exit 1 +fi + +# get download bandwidth +DOWNLOAD=$(speedtest-cli --single --bytes --simple --server "$ID" | awk -F':' 'NR==2 {print $2; exit}') +DOWNLOAD_DATA=$(echo "$DOWNLOAD" | awk '{print $1; exit}') +if float_num_compare "$DOWNLOAD_DATA"; then + test_print_trc "BW test download result: $DOWNLOAD" +else + test_print_trc "BW test download result: $DOWNLOAD" + test_print_err "BW test download test failed" + exit 1 +fi + +# get upload bandwidth +UPLOAD=$(speedtest-cli --single --bytes --simple --server "$ID" | awk -F':' 'NR==3 {print $2; exit}') +UPLOAD_DATA=$(echo "$UPLOAD" | awk '{print $1; exit}') +if float_num_compare "$UPLOAD_DATA"; then + test_print_trc "BW test upload result: $UPLOAD" +else + test_print_trc "BW test upload result: $UPLOAD" + test_print_err "BW test upload test failed" + exit 1 +fi \ No newline at end of file diff --git a/guest-test/tdx/tests b/guest-test/tdx/tests index 89b51bfa..c7e868a7 100644 --- a/guest-test/tdx/tests +++ b/guest-test/tdx/tests @@ -7,7 +7,11 @@ guest.test_launcher.sh -v 4 -s 2 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory guest.test_launcher.sh -v 64 -s 8 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 288 -s 1 -m 1 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 288 -s 8 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 1 -s 1 -m 1 -d off -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +# case implemented by tdx_attest_check.sh guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_ATTEST_VERIFY_REPORT -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_ATTEST_VERITY_REPORTMAC -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_ATTEST_VERIFY_RTMR_EXTEND -c "accept_memory=lazy" -p off -guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_ATTEST_VERIFY_QUOTE -c "accept_memory=lazy" -p off \ No newline at end of file +guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_ATTEST_VERIFY_QUOTE -c "accept_memory=lazy" -p off +# case implemented by tdx_speed_test.sh +guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_NET_SPEED -c "accept_memory=lazy" -p off \ No newline at end of file