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 <[email protected]>
  • Loading branch information
hongyuni committed Dec 27, 2023
1 parent 246036b commit 7b88e6d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions guest-test/guest.qemu_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ 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=$(echo ${version_raw#0x} | sed 's/^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=$(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"
local attributes=$(cat "$tdx_module_path"attributes)
attributes=$(version_check "$attributes")
local vendor_id=$(cat "$tdx_module_path"vendor_id)
local major_version=$(cat "$tdx_module_path"major_version)
major_version=$(version_check "$major_version")
local minor_version=$(cat "$tdx_module_path"minor_version)
minor_version=$(version_check "$minor_version")
local build_date=$(cat "$tdx_module_path"build_date)
local 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,6 +115,7 @@ 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
Expand Down

0 comments on commit 7b88e6d

Please sign in to comment.