diff --git a/guest-test/tdx/tdx.test_executor.sh b/guest-test/tdx/tdx.test_executor.sh index 5948f427..b36ef4b7 100755 --- a/guest-test/tdx/tdx.test_executor.sh +++ b/guest-test/tdx/tdx.test_executor.sh @@ -248,6 +248,16 @@ case "$TESTCASE" in 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 + ;; :) test_print_err "Must specify the test scenario option by [-t]" usage && exit 1 diff --git a/guest-test/tdx/tdx_halt_test_module/.gitignore b/guest-test/tdx/tdx_halt_test_module/.gitignore new file mode 100644 index 00000000..b0a810a9 --- /dev/null +++ b/guest-test/tdx/tdx_halt_test_module/.gitignore @@ -0,0 +1 @@ +halt_test.ko \ No newline at end of file diff --git a/guest-test/tdx/tdx_halt_test_module/Makefile b/guest-test/tdx/tdx_halt_test_module/Makefile new file mode 100644 index 00000000..97e0e4f1 --- /dev/null +++ b/guest-test/tdx/tdx_halt_test_module/Makefile @@ -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 \ No newline at end of file diff --git a/guest-test/tdx/tdx_halt_test_module/halt_test.c b/guest-test/tdx/tdx_halt_test_module/halt_test.c new file mode 100644 index 00000000..a6bd92a3 --- /dev/null +++ b/guest-test/tdx/tdx_halt_test_module/halt_test.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include + +static int __init test_tdx_hlt_init(void) +{ + printk(KERN_ALERT "[TD guest test] Start to trigger hlt instr.\n"); + asm("cli"); + asm("hlt"); + return 0; +} + +static void __exit test_tdx_hlt_exit(void) +{ + printk(KERN_ALERT "[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"); diff --git a/guest-test/tdx/tdx_test_module.sh b/guest-test/tdx/tdx_test_module.sh new file mode 100755 index 00000000..67224d92 --- /dev/null +++ b/guest-test/tdx/tdx_test_module.sh @@ -0,0 +1,38 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) 2023 Intel Corporation + +# Author: Hongyu Ning +# +# History: 13, Dec., 2023 - Hongyu Ning - creation + + +# @desc This script do test by kernel test module in TDX Guest VM + +###################### Variables ###################### +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +echo "$SCRIPT_DIR" +source common.sh +test_module=$1 + +###################### Functions ###################### +module_check() { + lsmod | grep "$test_module" || \ + { die "test module $test_module not found in lsmod"; return 1; } + test_print_trc "test module loaded and test should be completed now" +} + +###################### Do Works ###################### +if [[ -f "$test_module".ko ]]; then + test_print_trc "Kernel test module: $test_module.ko is ready for test" + insmod "$test_module".ko || \ + { die "Fail to insmod test module $test_module.ko"; exit 1; } + test_print_trc "$test_module.ko inserted and hlt instruction triggered" + module_check + sleep 3 + rmmod "$test_module" || \ + { die "Fail to rmmod test module $test_module.ko"; exit 1; } +else + die "Kernel test module $test_module.ko not found" + exit 1 +fi \ No newline at end of file diff --git a/guest-test/tdx/tests b/guest-test/tdx/tests index d4684731..23cf850c 100644 --- a/guest-test/tdx/tests +++ b/guest-test/tdx/tests @@ -34,4 +34,6 @@ guest.test_launcher.sh -v 32 -s 1 -m 96 -d on -t tdx -f tdx -x TD_MEM_ACPT_T_32C guest.test_launcher.sh -v 32 -s 1 -m 96 -d on -t tdx -f tdx -x TD_MEM_ACPT_T_32C_96G_256W -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -f tdx -x TD_MEM_ACPT_FUNC -c "accept_memory=lazy" -p off guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -f tdx -x TD_MEM_ACPT_CAL -c "accept_memory=lazy" -p off -guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -f tdx -x TD_MEM_ACPT_NEG -c "accept_memory=eager" -p off \ No newline at end of file +guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -f tdx -x TD_MEM_ACPT_NEG -c "accept_memory=eager" -p off +# case implemented by tdx_test_module.sh +guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -f tdx -x TD_VE_HALT -c "accept_memory=lazy" -p off \ No newline at end of file