Skip to content

Commit

Permalink
[guest-next] New Test: add unaccepted memory full accept time test
Browse files Browse the repository at this point in the history
Add 5 TCs to cover TDVM kernel remained unaccepted memory fully accepted
time calculation and check

[Test Components] tdx
[Test Types] func
[Supported Devices] spr,emr,gnr,srf

Signed-off-by: Hongyu Ning <[email protected]>
  • Loading branch information
hongyuni committed Nov 27, 2023
1 parent ee5cd35 commit bf57bde
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
40 changes: 40 additions & 0 deletions guest-test/guest.test_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions guest-test/tdx/tdx_mem_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion guest-test/tdx/tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit bf57bde

Please sign in to comment.