diff --git a/guest-test/guest.test_executor.sh b/guest-test/guest.test_executor.sh index a7e1bfd..6dbf5c4 100755 --- a/guest-test/guest.test_executor.sh +++ b/guest-test/guest.test_executor.sh @@ -201,6 +201,46 @@ case "$TESTCASE" in guest_test_close fi ;; + TD_MEM_ACCEPT_TIME_4G) + guest_test_prepare tdx/tdx_mem_test.sh + guest_test_entry tdx_mem_test.sh "-t MEM_ACCEPT_TIME_4G" || \ + { die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACCEPT_TIME_4G"; return 1; } + if [[ $GCOV == "off" ]]; then + guest_test_close + fi + ;; + TD_MEM_ACCEPT_TIME_16G) + guest_test_prepare tdx/tdx_mem_test.sh + guest_test_entry tdx_mem_test.sh "-t MEM_ACCEPT_TIME_16G" || \ + { die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACCEPT_TIME_16G"; return 1; } + if [[ $GCOV == "off" ]]; then + guest_test_close + fi + ;; + TD_MEM_ACCEPT_TIME_32G) + guest_test_prepare tdx/tdx_mem_test.sh + guest_test_entry tdx_mem_test.sh "-t MEM_ACCEPT_TIME_32G" || \ + { die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACCEPT_TIME_32G"; return 1; } + if [[ $GCOV == "off" ]]; then + guest_test_close + fi + ;; + TD_MEM_ACCEPT_TIME_64G) + guest_test_prepare tdx/tdx_mem_test.sh + guest_test_entry tdx_mem_test.sh "-t MEM_ACCEPT_TIME_64G" || \ + { die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACCEPT_TIME_64G"; return 1; } + if [[ $GCOV == "off" ]]; then + guest_test_close + fi + ;; + TD_MEM_ACCEPT_TIME_96G) + guest_test_prepare tdx/tdx_mem_test.sh + guest_test_entry tdx_mem_test.sh "-t MEM_ACCEPT_TIME_96G" || \ + { die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACCEPT_TIME_96G"; return 1; } + 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_mem_test.sh b/guest-test/tdx/tdx_mem_test.sh index 1c7aa3b..a31a188 100755 --- a/guest-test/tdx/tdx_mem_test.sh +++ b/guest-test/tdx/tdx_mem_test.sh @@ -43,11 +43,65 @@ ebizzy_func() { fi } +# function based on stress-ng calculate total remained mem accepted time +mem_accepted_time() { +# common expected time consumed in seconds +expected_time=$1 +# prepare for prerequisites + if [ ! "$(which stress-ng)" ]; then + dnf install -y stress-ng > /dev/null + apt install -y stress-ng > /dev/null + else + test_print_trc "stress-ng prerequisites is ready for use" + test_print_trc "unaccepted memory drained time calculation is starting now..." + fi +# calculate memory accepted fully completed time +SECONDS=0 && stress-ng --vm 1 --vm-bytes 100% & +while (true); do + if [[ $(grep "nr_unaccepted" /proc/vmstat | awk '{print $2}') -eq 0 ]]; then + actual_time=$SECONDS; + pkill stress-ng; + break; + fi +done +# check if memory accept time far exceed expected (passed in value) +compare_result=$(echo "scale=2; ($actual_time/$expected_time)" | bc) +baseline_result=1.1 +result=$(awk -v n1="$compare_result" -v n2="$baseline_result" 'BEGIN {if (n1>n2) print 1; else print 0}') +if [ $result -eq 0 ]; then + test_print_trc "Memory accepted full time consumed: $actual_time" + return 0 +else + die "Memory accepted full time consumed over expectation $expected_time seconds 10% more!!!" + return 1 +fi +} + ###################### Do Works ###################### case "$MEM_CASE" in EBIZZY_FUNC) ebizzy_func ;; + MEM_ACCEPT_TIME_4G) + # expected 4 secs + mem_accepted_time 4 + ;; + MEM_ACCEPT_TIME_16G) + # expected 1 min 4 secs + mem_accepted_time 64 + ;; + MEM_ACCEPT_TIME_32G) + # expected 2 mins 18 secs + mem_accepted_time 138 + ;; + MEM_ACCEPT_TIME_64G) + # expected 4 mins 46 secs + mem_accepted_time 286 + ;; + MEM_ACCEPT_TIME_96G) + # expected 5 mins 59 secs + mem_accepted_time 359 + ;; :) test_print_err "Must specify the memory case option by [-t]" exit 1 diff --git a/guest-test/tdx/tests b/guest-test/tdx/tests index 5e2ec05..ae4952d 100644 --- a/guest-test/tdx/tests +++ b/guest-test/tdx/tests @@ -19,4 +19,9 @@ guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_TSM_ATTEST_QUOTE_NEG -c # 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 # case implemented by tdx_mem_test.sh -guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -x TD_MEM_EBIZZY_FUNC -c "accept_memory=lazy" -p off \ No newline at end of file +guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -x TD_MEM_EBIZZY_FUNC -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 4 -s 1 -m 4 -d on -t tdx -x TD_MEM_ACCEPT_TIME_4G -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 16 -s 1 -m 4 -d on -t tdx -x TD_MEM_ACCEPT_TIME_16G -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 16 -s 1 -m 4 -d on -t tdx -x TD_MEM_ACCEPT_TIME_32G -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 16 -s 1 -m 4 -d on -t tdx -x TD_MEM_ACCEPT_TIME_64G -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 16 -s 1 -m 4 -d on -t tdx -x TD_MEM_ACCEPT_TIME_96G -c "accept_memory=lazy" -p off \ No newline at end of file