From 24e53f7269572e025844936b2a87f73bbd3aadf5 Mon Sep 17 00:00:00 2001 From: Hongyu Ning Date: Wed, 27 Sep 2023 15:18:59 +0800 Subject: [PATCH] [New][guest-test][tdx]: add $TESTCASE TD_BOOT test script and tests please refer to this implmentation to add more guest vm testcases Signed-off-by: Hongyu Ning --- guest-test/tdx/tdx_guest_boot_check.sh | 63 ++++++++++++++++++++++++++ guest-test/tdx/tests | 10 ++++ 2 files changed, 73 insertions(+) create mode 100755 guest-test/tdx/tdx_guest_boot_check.sh create mode 100644 guest-test/tdx/tests diff --git a/guest-test/tdx/tdx_guest_boot_check.sh b/guest-test/tdx/tdx_guest_boot_check.sh new file mode 100755 index 0000000..36e4382 --- /dev/null +++ b/guest-test/tdx/tdx_guest_boot_check.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (c) 2023 Intel Corporation + +# Author: Hongyu Ning +# +# History: 24, Aug., 2023 - Hongyu Ning - creation + + +# @desc This script do basic TD guest booting check in TDX Guest VM + +###################### Variables ###################### +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +echo "$SCRIPT_DIR" +source common.sh + +while getopts :v:s:m: arg; do + case $arg in + v) + VCPU=$OPTARG + ;; + s) + SOCKETS=$OPTARG + ;; + m) + MEM=$OPTARG + ;; + esac +done + +###################### Do Works ###################### +# check vcpu and socket number +vcpu_td=$(lscpu | grep "CPU(s)" | head -1 | awk '{print $2}') +sockets_td=$(lscpu | grep "Socket(s)" | awk '{print $2}') +test_print_trc "vcpu_td: $vcpu_td" +test_print_trc "sockets_td: $sockets_td" + +if [[ "$vcpu_td" -ne "$VCPU" ]]; then + die "Guest TD VM boot with vcpu: $vcpu_td (expected $VCPU)" +fi + +if [[ "$sockets_td" -ne "$SOCKETS" ]]; then + die "Guest TD VM boot with sockets: $sockets_td (expected $SOCKETS)" +fi + +# check memory size +mem_td=$(grep "MemTotal" /proc/meminfo | awk '$3=="kB" {printf "%.0f\n", $2/(1024*1024)}') +test_print_trc "mem_td: $mem_td" + +# $MEM less than or equal to 4GB need special memory size check +if [[ $MEM -le 4 ]]; then + if [[ $(( $MEM / $mem_td )) -lt 1 ]] || [[ $(( $MEM / $mem_td )) -gt 2 ]]; then + die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" + fi +# $MEM more than 4GB use general memory size check +else + if [[ $(( $MEM / $mem_td )) -ne 1 ]]; then + die "Guest TD VM boot with memory: $mem_td GB (expected $MEM GB)" + fi +fi + +test_print_trc "Guest TD VM boot up successfully with config:" +test_print_trc "vcpu $VCPU, socket $SOCKETS, memory $MEM GB" \ No newline at end of file diff --git a/guest-test/tdx/tests b/guest-test/tdx/tests new file mode 100644 index 0000000..3bd4016 --- /dev/null +++ b/guest-test/tdx/tests @@ -0,0 +1,10 @@ +# case implemented by tdx_guest_boot_check.sh +guest.test_launcher.sh -v 1 -s 1 -m 1 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 4 -s 1 -m 4 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 4 -s 2 -m 4 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 4 -s 2 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 64 -s 8 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 288 -s 1 -m 1 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 288 -s 8 -m 96 -d on -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off +guest.test_launcher.sh -v 1 -s 1 -m 1 -d off -t tdx -x TD_BOOT -c "accept_memory=lazy" -p off