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/tdx/tdx_speed_test.sh b/guest-test/tdx/tdx_speed_test.sh new file mode 100755 index 00000000..0391c7de --- /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