-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tdx-guest] New Test: add 24 normal TDVM kexec TCs
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
Showing
4 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters