Skip to content

Commit

Permalink
[New][guest-test][tdx]: add $TESTCASE TD_BOOT test script and tests
Browse files Browse the repository at this point in the history
please refer to this implmentation to add more guest vm testcases

Signed-off-by: Hongyu Ning <[email protected]>
  • Loading branch information
hongyuni committed Sep 27, 2023
1 parent 6bd7707 commit 24e53f7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
63 changes: 63 additions & 0 deletions guest-test/tdx/tdx_guest_boot_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2023 Intel Corporation

# Author: Hongyu Ning <[email protected]>
#
# 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"
10 changes: 10 additions & 0 deletions guest-test/tdx/tests
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 24e53f7

Please sign in to comment.