Skip to content

Commit

Permalink
[guest-test] Test Enhance: add tdx_module_check function
Browse files Browse the repository at this point in the history
add tdx_module_check function for basic tdx/tdxio host machine status
checking

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

Signed-off-by: Hongyu Ning <hongyu.ning@intel.com>
  • Loading branch information
hongyuni committed Dec 27, 2023
1 parent 246036b commit dab2643
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion guest-test/guest.qemu_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,49 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
echo "$SCRIPT_DIR"

###################### Functions ######################
# function to remove 0x and prefix useless 0 for hex data
version_check() {
local version_raw=$1
if [[ "$version_raw" = "0x00000000" ]]; then
local version=0x0
else
local version_hex
version_hex=${version_raw#0x}
version_hex=${version_hex##+(0)}
local version=$((16#$version_hex))
fi
echo "$version"
}

# function to do tdx module status and version check
tdx_module_check() {
local tdx_module_path="/sys/firmware/tdx/tdx_module/"
local status
local attributes
local vendor_id
local major_version
local minor_version
local build_date
local build_num
status=$(cat "$tdx_module_path"status)
[[ "$status" = "initialized" ]] || \
die "TDX module not initialized correctly, \
please check host kernel tdx enabling setup."
test_print_trc "TDX module initialized correctly"
attributes=$(cat "$tdx_module_path"attributes)
attributes=$(version_check "$attributes")
vendor_id=$(cat "$tdx_module_path"vendor_id)
major_version=$(cat "$tdx_module_path"major_version)
major_version=$(version_check "$major_version")
minor_version=$(cat "$tdx_module_path"minor_version)
minor_version=$(version_check "$minor_version")
build_date=$(cat "$tdx_module_path"build_date)
build_num=$(cat "$tdx_module_path"build_num)
build_num=$(version_check "$build_num")
test_print_trc "TDX module: attributes $attributes, vendor_id $vendor_id, \
major_version $major_version, minor_version $minor_version, \
build_date $build_date, build_num $build_num"
}

# function to do TDX/TDXIO VM launching basic pre-check
# list all the variables value
Expand Down Expand Up @@ -81,8 +124,9 @@ source "$SCRIPT_DIR"/test_params.py
# do basic pre-check for TDX/TDXIO VM launching
if [[ $VM_TYPE == "tdx" ]] || [[ $VM_TYPE == "tdxio" ]]; then
tdx_pre_check
tdx_module_check
fi

# launch VM by qemu via qemu_runner.py
test_print_trc "qemu_runner start to launch $VM_TYPE VM"
python3 "$SCRIPT_DIR"/qemu_runner.py
python3 "$SCRIPT_DIR"/qemu_runner.py

0 comments on commit dab2643

Please sign in to comment.