-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New][guest-test]: test_executor initial commit
test_executor includes basic framework to prepare and run tests in guest vm based on $TESTCASE Signed-off-by: Hongyu Ning <[email protected]>
- Loading branch information
Showing
1 changed file
with
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/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 prepare and run $TESTCASE in Guest VM | ||
|
||
###################### Variables ###################### | ||
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" | ||
echo "$SCRIPT_DIR" | ||
GUEST_TEST_DIR="/root/guest_test/" | ||
|
||
###################### Functions ###################### | ||
|
||
# function based on sshpass to scp common.sh and $1 test_script.sh to Guest VM | ||
guest_test_prepare() { | ||
rm -rf common.sh | ||
wget https://raw.githubusercontent.com/intel/lkvs/main/common/common.sh | ||
sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF | ||
rm -rf $GUEST_TEST_DIR | ||
mkdir $GUEST_TEST_DIR | ||
EOF | ||
sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no common.sh root@localhost:$GUEST_TEST_DIR | ||
sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no $1 root@localhost:$GUEST_TEST_DIR | ||
test_print_trc "Guest VM test script prepare complete" | ||
} | ||
|
||
# function based on sshpass to scp $1 source_code_dir and compile $2 test_binary in Guest VM | ||
guest_test_source_code() { | ||
sshpass -e scp -P "$PORT" -o StrictHostKeyChecking=no -r $1 root@localhost:$GUEST_TEST_DIR | ||
sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF | ||
source $GUEST_TEST_DIR/common.sh | ||
cd $GUEST_TEST_DIR/$1 | ||
make || die "Failed to compile source code $1" | ||
if [ -f $2 ]; then | ||
chmod a+x $2 | ||
cp $2 $GUEST_TEST_DIR | ||
else | ||
die "Can't find test binary $2" | ||
fi | ||
EOF | ||
test_print_trc "Guest VM test source code and binary prepare complete" | ||
} | ||
|
||
# function based on sshpass to execute $1 test_script.sh and potential $2 script params in Guest VM | ||
guest_test_entry() { | ||
sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF | ||
source $GUEST_TEST_DIR/common.sh | ||
cd $GUEST_TEST_DIR | ||
test_print_trc "guest_test_entry args 1: $1" | ||
test_print_trc "guest_test_entry args 2: $2" | ||
./$1 $2 | ||
EOF | ||
ERR_NUM=$? | ||
if [ $ERR_NUM -eq 0 ] || [ $ERR_NUM -eq 255 ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# function based on sshpass to close VM | ||
guest_test_close() { | ||
sshpass -e ssh -p "$PORT" -o StrictHostKeyChecking=no root@localhost << EOF | ||
source $GUEST_TEST_DIR/common.sh | ||
test_print_trc "guest test complete, close VM now" | ||
systemctl reboot --reboot-argument=now | ||
EOF | ||
test_print_trc "Guest VM closed properly after test" | ||
} | ||
|
||
###################### Do Works ###################### | ||
cd "$(dirname "$0")" 2>/dev/null || exit 1 | ||
source ../.env | ||
|
||
# get test scenario config for test_executor | ||
source $SCRIPT_DIR/test_params.py | ||
|
||
cd $SCRIPT_DIR | ||
# select test_functions by $TEST_SCENARIO | ||
case "$TESTCASE" in | ||
TD_BOOT) | ||
guest_test_prepare tdx_guest_boot_check.sh | ||
guest_test_entry tdx_guest_boot_check.sh "-v $VCPU -s $SOCKETS -m $MEM" || \ | ||
die "Failed on TD_BOOT test tdx_guest_boot_check.sh -v $VCPU -s $SOCKETS -m $MEM" | ||
if [[ $GCOV == "off" ]]; then | ||
guest_test_close | ||
fi | ||
;; | ||
GUEST_TESTCASE_EXAMPLE) | ||
guest_test_prepare guest_test.sh | ||
guest_test_source_code test_source_code_dir_example test_binary_example | ||
guest_test_entry guest_test.sh "-t $TESTCASE" || \ | ||
die "Failed on GUEST_TESTCASE_EXAMPLE guest_test.sh -t $TESTCASE" | ||
if [[ $GCOV == "off" ]]; then | ||
guest_test_close | ||
fi | ||
;; | ||
:) | ||
test_print_err "Must specify the test scenario option by [-t]" | ||
usage && exit 1 | ||
;; | ||
\?) | ||
test_print_err "Input test case option $TESTCASE is not supported" | ||
usage && exit 1 | ||
;; | ||
esac |