Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guest test td func 1213 #154

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions guest-test/guest.test_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ EOF
return 1
fi
EOF
ERR_NUM=$?
if [ $ERR_NUM -eq 0 ]; then
test_print_trc "Guest VM test source code and binary prepare complete"
return 0
else
return 1
fi
ERR_NUM=$?
if [ $ERR_NUM -eq 0 ]; then
test_print_trc "Guest VM test source code and binary prepare complete"
return 0
else
return 1
fi
}

# function based on sshpass to execute $1 test_script.sh and potential $2 script params in Guest VM
Expand All @@ -77,12 +77,12 @@ guest_test_entry() {
test_print_trc "guest_test_entry args 2: $2"
./$1 $2
EOF
ERR_NUM=$?
if [ $ERR_NUM -eq 0 ] || [ $ERR_NUM -eq 255 ]; then
return 0
else
return 1
fi
ERR_NUM=$?
if [ $ERR_NUM -eq 0 ] || [ $ERR_NUM -eq 255 ]; then
return 0
else
return 1
fi
}

# function based on sshpass to close VM
Expand All @@ -92,7 +92,13 @@ guest_test_close() {
test_print_trc "guest test complete, close VM now"
systemctl reboot --reboot-argument=now
EOF
test_print_trc "Guest VM closed properly after test"
ERR_NUM=$?
if [ $ERR_NUM -eq 0 ]; then
test_print_trc "Guest VM closed properly after test"
return 0
else
return 1
fi
}

###################### Do Works ######################
Expand All @@ -109,4 +115,4 @@ if [ "${BASH_SOURCE[0]}" -ef "$0" ]; then
# select specific "$FEATURE.test_executor.sh" by $FEATURE
"$FEATURE"/"$FEATURE".test_executor.sh || \
{ die "Failed on $TESTCASE of $FEATURE"; return 1; }
fi
fi
11 changes: 8 additions & 3 deletions guest-test/guest.test_launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "$SCRIPT_DIR"
GCOV="off"
# timeout control in case of TD VM booting hang
SECONDS=0
TIMEOUT=300
TIMEOUT=900
# EXEC_FLAG=0 shows test_executor being called
EXEC_FLAG=1

Expand Down Expand Up @@ -249,8 +249,13 @@ while read -r line; do
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)
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
)

## PART 3: err_handlers error management
# unexpected error/bug/warning/call trace handling
Expand Down
72 changes: 53 additions & 19 deletions guest-test/tdx/tdx.test_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ guest_attest_test() {
guest_test_entry tdx_attest_check.sh "-t $selftest_item" || \
{ die "Failed on $TESTCASE tdx_attest_check.sh -t $selftest_item"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
}

Expand All @@ -39,7 +39,7 @@ guest_tsm_attest() {
guest_test_entry tdx_attest_check.sh "-t $test_item" || \
{ die "Failed on $TESTCASE tdx_attest_check.sh -t $test_item"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
}

Expand Down Expand Up @@ -70,16 +70,16 @@ case "$TESTCASE" in
guest_test_entry tdx_guest_boot_check.sh "-v $VCPU -s $SOCKETS -m $MEM" || \
die "Failed on TD_BOOT test tdx_guest_boot_check.sh -v $VCPU -s $SOCKETS -m $MEM"
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
GUEST_TESTCASE_EXAMPLE)
guest_test_prepare guest_test.sh
guest_test_source_code test_source_code_dir_example test_binary_example
guest_test_entry guest_test.sh "-t $TESTCASE" || \
die "Failed on $TESTCASE guest_test.sh -t $TESTCASE"
{ die "Failed on $TESTCASE guest_test.sh -t $TESTCASE"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_ATTEST_VERIFY_REPORT)
Expand All @@ -103,7 +103,7 @@ case "$TESTCASE" in
guest_test_entry tdx_speed_test.sh || \
die "Failed on TD_NET_SPEED tdx_speed_test.sh"
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_TSM_ATTEST_QUOTE_PRECHECK)
Expand All @@ -125,103 +125,137 @@ case "$TESTCASE" in
guest_test_entry tdx_mem_test.sh "-t EBIZZY_FUNC" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t EBIZZY_FUNC"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_8G_1W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_8G_1W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_8G_1W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_8G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_8G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_8G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_32G_1W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_32G_1W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_32G_1W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_32G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_32G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_32G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_96G_1W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_96G_1W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_96G_1W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_1C_96G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_1C_96G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_1C_96G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_8G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_8G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_8G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_8G_256W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_8G_256W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_8G_256W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_32G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_32G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_32G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_32G_256W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_32G_256W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_32G_256W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_96G_32W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_96G_32W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_96G_32W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_T_32C_96G_256W)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_T_32C_96G_256W" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_T_32C_96G_256W"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_FUNC)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_FUNC" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_FUNC"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_CAL)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_CAL" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_CAL"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_MEM_ACPT_NEG)
guest_test_prepare tdx_mem_test.sh
guest_test_entry tdx_mem_test.sh "-t MEM_ACPT_NEG" || \
{ die "Failed on $TESTCASE tdx_mem_test.sh -t MEM_ACPT_NEG"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
TD_VE_HALT)
guest_test_prepare tdx_test_module.sh
guest_test_source_code tdx_halt_test_module halt_test || \
{ die "Failed to prepare guest test kernel module for $TESTCASE"; return 1; }
guest_test_entry tdx_test_module.sh "halt_test" || \
{ die "Failed on $TESTCASE tdx_test_module.sh halt_test"; return 1; }
if [[ $GCOV == "off" ]]; then
guest_test_close || { die "Failed on close guest VM"; return 1; }
fi
;;
:)
Expand Down
1 change: 1 addition & 0 deletions guest-test/tdx/tdx_halt_test_module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
halt_test.ko
12 changes: 12 additions & 0 deletions guest-test/tdx/tdx_halt_test_module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-only

MODULES = halt_test.ko

obj-m += halt_test.o

KDIR ?= /lib/modules/$(shell uname -r)/build

all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
22 changes: 22 additions & 0 deletions guest-test/tdx/tdx_halt_test_module/halt_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

static int __init test_tdx_hlt_init(void)
{
pr_info("[TD guest test] Start to trigger hlt instr.\n");
asm("cli");
asm("hlt");
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worthwhile to create a separate kernel module for this?
I have an idea about creating a common test module in LKVS.
Let's have a discussion later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be nice, let's discuss your common test module solution

}

static void __exit test_tdx_hlt_exit(void)
{
pr_info("[TD guest test] Complete of hlt instr. test, test module exit\n");
}

module_init(test_tdx_hlt_init);
module_exit(test_tdx_hlt_exit);
MODULE_INFO(intree, "Y");
MODULE_LICENSE("GPL");
Loading