Skip to content

Commit

Permalink
[tdx-guest] New Test: add 24 normal TDVM kexec TCs
Browse files Browse the repository at this point in the history
add 24 new TCs of normal TDVM kexec test, with memory drain before kexec
and memory drain after kexec scenarios both covered, under difference
VCPU and MEMORY configurations

[Test Components] tdx-guest
[Test Types] func
[Supported Devices] spr,emr,gnr,srf

Signed-off-by: Hongyu Ning <[email protected]>
  • Loading branch information
hongyuni committed Aug 23, 2024
1 parent bcba2bf commit bd478cc
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 0 deletions.
30 changes: 30 additions & 0 deletions BM/tdx-guest/tdx.guest_test_executor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,36 @@ case "$TESTCASE" in
guest_test_close
fi
;;
# continous TD KEXEC test group with $VCPU VCPU $MEM GB mem and no mem drain
TD_KEXEC_NO_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_2 | TD_KEXEC_NO_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_1)
guest_test_prepare tdx_kexec_test.sh
guest_test_entry tdx_kexec_test.sh "-v $VCPU -m $MEM -o no -k $KEXEC_CNT" || \
die "Failed on $TESTCASE tdx_kexec_test.sh -v $VCPU -m $MEM -o no -k $KEXEC_CNT"
;;
TD_KEXEC_NO_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_0)
guest_test_prepare tdx_kexec_test.sh
guest_test_entry tdx_kexec_test.sh "-v $VCPU -m $MEM -o no -k $KEXEC_CNT" || \
die "Failed on $TESTCASE tdx_kexec_test.sh -v $VCPU -m $MEM -o no -k $KEXEC_CNT"
if [[ "$GCOV" == "off" ]]; then
guest_test_close
fi
;;
# continous TD KEXEC test group with $VCPU VCPU $MEM GB mem and mem drain
TD_KEXEC_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_2 | TD_KEXEC_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_1)
guest_test_prepare tdx_kexec_test.sh
guest_test_entry tdx_kexec_test.sh "-v $VCPU -m $MEM -o yes -k $KEXEC_CNT" || \
die "Failed on $TESTCASE tdx_kexec_test.sh -v $VCPU -m $MEM -o yes -k $KEXEC_CNT"
guest_test_entry tdx_kexec_test.sh "-s yes" || \
die "Failed on $TESTCASE tdx_kexec_test.sh -s yes"
;;
TD_KEXEC_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_0)
guest_test_prepare tdx_kexec_test.sh
guest_test_entry tdx_kexec_test.sh "-v $VCPU -m $MEM -o yes -k $KEXEC_CNT" || \
die "Failed on $TESTCASE tdx_kexec_test.sh -v $VCPU -m $MEM -o yes -k $KEXEC_CNT"
if [[ "$GCOV" == "off" ]]; then
guest_test_close
fi
;;
:)
test_print_err "Must specify the test scenario option by [-t]"
usage && exit 1
Expand Down
172 changes: 172 additions & 0 deletions BM/tdx-guest/tdx_kexec_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2024 Intel Corporation

# Author: Hongyu Ning <[email protected]>
#
# History: 16, Aug., 2024 - Hongyu Ning - creation


# @desc This script do kexec related test and check in TDX Guest VM

###################### Variables ######################
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
echo "$SCRIPT_DIR"
source common.sh

while getopts :v:m:o:k:s: arg; do
case $arg in
v)
VCPU=$OPTARG
;;
m)
MEM=$OPTARG
;;
o)
MEM_DRAIN=$OPTARG
;;
k)
KEXEC_CNT=$OPTARG
;;
s)
KEXEC_SSH=$OPTARG
;;
*)
test_print_err "Must supply an argument to -$OPTARG."
exit 1
;;
esac
done

###################### Functions ######################
# function to check unaccepted memory and do mem drain
memory_drain() {
# check unaccepted memory
unaccepted_mem=$(grep "naccepted" /proc/meminfo | awk '{print $2}')
# drain memory if unaccepted memory is not zero
if [[ "$unaccepted_mem" -gt 0 ]]; then
tail /dev/zero
elif [[ "$unaccepted_mem" -eq 0 ]]; then
test_print_trc "unaccepted memory is zero now"
else
die "unaccepted memory check failed with unaccepted mem: $unaccepted_mem"
fi
}

# function to load kexec target kenrel image and trigger kexec switch to target kernel
kexec_load_switch() {
# load kexec target kernel image and initrd, reuse kernel cmdline
if ! kexec -d -l "/boot/vmlinuz-$(uname -r)" --initrd="/boot/initramfs-$(uname -r).img" --reuse-cmdline; then
die "failed to load kexec target kernel image, test failed"
else
test_print_trc "kexec target kernel image loaded"
fi
sleep 45
# trigger kexec switch to target kernel
test_print_trc "kexec switch to target kernel triggered"
kexec -d -e &
}

# function to check VCPU and MEMORY size in TDX guest
vcpu_mem_check() {
# check vcpu and socket number
vcpu_td=$(lscpu | grep "CPU(s)" | head -1 | awk '{print $2}')
test_print_trc "vcpu_td: $vcpu_td"

if [[ "$vcpu_td" -ne "$VCPU" ]]; then
die "Guest TD VM boot with vcpu: $vcpu_td (expected $VCPU)"
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, memory $MEM GB"
}

# function to free memory by clear memory page caches
clear_mem_cache() {
test_print_trc "Start to clear memory page caches"
sync
sleep 1
# free page cache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
test_print_trc "Free memory by clear memory page caches done"
}

# function to increase swap space for more virtual memory
increase_swap_space() {
test_print_trc "Start to increase swap space"
# create swap file with 2GB size
dd if=/dev/zero of=/swapfile bs=1M count=2048
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
test_print_trc "Increase swap space done"
}

###################### Do Works ######################
if [[ "$KEXEC_SSH" != "yes" ]]; then
test_print_trc "start kexec test with vcpu: $VCPU, memory: $MEM, mem_drain: $MEM_DRAIN, kexec_cnt: $KEXEC_CNT, kexec_ssh: $KEXEC_SSH"
# do memory_drain if $MEM_DRAIN option enabled "yes"
if [[ "$MEM_DRAIN" == "yes" ]]; then
test_print_trc "start memory drain before kexec test"
memory_drain
elif [[ "$MEM_DRAIN" == "no" ]]; then
if [[ "$KEXEC_CNT" -ne 0 ]]; then
test_print_trc "skip memory drain before kexec test"
fi
else
die "unsupported memory drain option: $MEM_DRAIN"
fi

#do memory_drain in final test loop even if $MEM_DRAIN not enabled
if [[ "$KEXEC_CNT" -eq 0 ]] && [[ "$MEM_DRAIN" == "no" ]]; then
test_print_trc "Start memory drain in final test loop in case of no mem_drain before kexec test"
memory_drain
unaccepted_mem=$(grep "naccepted" /proc/meminfo | awk '{print $2}')
if [[ "$unaccepted_mem" -gt 0 ]]; then
die "unaccepted memory is not drained: $unaccepted_mem"
elif [[ "$unaccepted_mem" -eq 0 ]]; then
test_print_trc "unaccepted memory is zero now"
else
die "unaccepted memory check failed with unaccepted mem: $unaccepted_mem"
fi
fi

# do VCPU and MEM check
vcpu_mem_check || die "failed on vcpu_mem_check"

# do kexec load and switch
if [[ "$KEXEC_CNT" -gt 0 ]]; then
if [[ "$MEM_DRAIN" == "yes" ]]; then
clear_mem_cache || die "failed on clear_mem_cache"
sleep 3
increase_swap_space || die "failed on increase_swap_space"
sleep 3
elif [[ "$MEM_DRAIN" == "no" ]]; then
kexec_load_switch || die "failed on kexec_load_switch"
fi
elif [[ "$KEXEC_CNT" -eq 0 ]]; then
test_print_trc "skip kexec load and switch in final test loop"
else
die "unsupported kexec test cycle count: $KEXEC_CNT"
fi
else # $KEXEC_SSH == "yes", run kexec via ssh standalone to bypass abnormal kexec stuck
test_print_trc "run kexec_load_switch via ssh standalone"
sleep 45
kexec_load_switch || die "failed on kexec_load_switch ssh standalone"
fi
74 changes: 74 additions & 0 deletions BM/tdx-guest/tdx_kexec_test_entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2024 Intel Corporation

# Author: Hongyu Ning <[email protected]>
#
# History: 15, Aug., 2024 - Hongyu Ning - creation


# @desc This script is general tdx guest kexec test entry

###################### Variables ######################
source common.sh
DEBUG=on

###################### Functions ######################
# helper function
usage() {
cat <<-EOF
usage: ./${0##*/}
-v number of vcpus
-m memory size in GB
-o memory drained option yes or no
-k pos-integer value for normal kexec test cycle count
-r abs. path to single rpm file: kernel-img, kernel-devel or kernel-headers
-h HELP info
EOF
}

while getopts :v:m:o:k:r:h arg; do
case $arg in
v)
VCPU=$OPTARG
;;
m)
MEM=$OPTARG
;;
o)
MEM_DRAIN=$OPTARG
;;
k)
KEXEC_CNT=$OPTARG
;;
r)
RPM=$OPTARG
;;
h)
usage && exit 0
;;
*)
test_print_err "Must supply an argument to -$OPTARG."
exit 1
;;
esac
done

###################### Do Works ######################
# install kexec test kernel rpm in target TDX guest OS image
./guest-test/guest.test_launcher.sh -v 1 -s 1 -m 16 -d "$DEBUG" -t tdx -e tdx-guest -f tdx \
-x TD_RPM_INSTALL -c "accept_memory=lazy" -p off -r "$RPM" || \
die "Failed on kexec test kernel rpm install"
sleep 3
# prepare and trigger kexec in target TDX guest OS image
if [[ "$MEM_DRAIN" == "yes" ]]; then
./guest-test/guest.test_launcher.sh -v "$VCPU" -s 1 -m "$MEM" -d "$DEBUG" -t tdx -e tdx-guest -f tdx \
-x TD_KEXEC_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_"$KEXEC_CNT" -c "accept_memory=lazy crashkernel=1G-4G:256M,4G-64G:384M,64G-:512M" -p off -o yes -k "$KEXEC_CNT" || \
die "Failed on kexec test"
elif [[ "$MEM_DRAIN" == "no" ]]; then
./guest-test/guest.test_launcher.sh -v "$VCPU" -s 1 -m "$MEM" -d "$DEBUG" -t tdx -e tdx-guest -f tdx \
-x TD_KEXEC_NO_MEM_DRAIN_"$VCPU"C_"$MEM"G_CYCLE_"$KEXEC_CNT" -c "accept_memory=lazy" -p off -o no -k "$KEXEC_CNT" || \
die "Failed on kexec test"
else
die "Invalid memory drained option"
fi
50 changes: 50 additions & 0 deletions BM/tdx-guest/tests
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,53 @@
./guest-test/guest.test_launcher.sh -v 1 -s 1 -m 16 -d on -t tdx -e tdx-guest -f tdx -x TD_STRESS_SOCK_IOMIX_1C_16G_8W -c "accept_memory=lazy" -p off
# case info: In TDVM, stress test on memory with stress-ng network socket + iomix stressor under config of 1VCPU + 96G MEM + 48 stressors
./guest-test/guest.test_launcher.sh -v 1 -s 1 -m 96 -d on -t tdx -e tdx-guest -f tdx -x TD_STRESS_SOCK_IOMIX_1C_96G_48W -c "accept_memory=lazy" -p off
# case implemented by tdx_kexec_test_entry.sh
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 1 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 1 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 4 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 4 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 96 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 96 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 1 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 1 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 4 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 4 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 96 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 96 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 1 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 1 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 4 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 4 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 96 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 96 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 1 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 1 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 4 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 4 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 96 GB memory drain before kexec test 2 kexec cycles
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 96 -o yes -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 1 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 1 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 4 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 4 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 1 memory size 96 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 1 -m 96 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 1 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 1 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 4 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 4 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 2 memory size 96 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 2 -m 96 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 1 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 1 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 4 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 4 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 32 memory size 96 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 32 -m 96 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 1 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 1 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 4 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 4 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"
# case info: [NA for upstream kernel yet] tdx guest kexec functional check with vcpu 64 memory size 96 GB no memory drain before kexec test 2 kexec cycles, do memory drain after kexec cycles complete
./tdx-guest/tdx_kexec_test_entry.sh -v 64 -m 96 -o no -k 2 -r "/abs/path/to/kdump_test/kenrel_rpm/kernel-x-version-under-test.rpm"

0 comments on commit bd478cc

Please sign in to comment.