Skip to content

Commit e651157

Browse files
committed
ci: utilize ssh for qemu command execution, replacing the screen-based workflow
1 parent 0257474 commit e651157

30 files changed

+258
-441
lines changed

ci/ci.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ pushd ../tests
2525
# probability of detecting failures early in the pipeline.
2626
# Run std only tests
2727
if [ "$STD" ]; then
28-
./test_serde.sh
29-
./test_message_passing_interface.sh
28+
# move the EXPAND_TA_MEMORY tests together
3029
./test_tls_client.sh
3130
./test_tls_server.sh
31+
32+
./test_serde.sh
33+
./test_message_passing_interface.sh
3234
./test_eth_wallet.sh
3335
./test_secure_db_abstraction.sh
3436
else

tests/optee-qemuv8.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ cd $1 && ./qemu-system-aarch64 \
3232
-kernel Image \
3333
-fsdev local,id=fsdev0,path=$(pwd)/../shared,security_model=none \
3434
-device virtio-9p-device,fsdev=fsdev0,mount_tag=host \
35-
-netdev user,id=vmnic,hostfwd=:127.0.0.1:54433-:4433 \
35+
-netdev user,id=vmnic,hostfwd=:127.0.0.1:54433-:4433,hostfwd=:127.0.0.1:54432-:22 \
3636
-device virtio-net-device,netdev=vmnic

tests/setup.sh

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,73 @@ OPTEE_TAG=optee-$(cat ../optee-version.txt)
2626
# Define IMG_VERSION
2727
IMG_VERSION="$(uname -m)-$OPTEE_TAG-qemuv8-ubuntu-24.04"
2828

29-
# Set IMG based on NEED_EXPANDED_MEM
29+
IMG="$IMG_VERSION"
30+
NORMAL_SESSION_NAME="qemu_screen"
31+
EXPAND_MEMORY_SESSION_NAME="qemu_screen_expand_ta_memory"
32+
33+
CURRENT_SESSION_NAME=$NORMAL_SESSION_NAME
34+
OTHER_SESSION_NAME=$EXPAND_MEMORY_SESSION_NAME
35+
# Change Options based on NEED_EXPANDED_MEM
3036
if [ "$NEED_EXPANDED_MEM" = true ]; then
3137
IMG="${IMG_VERSION}-expand-ta-memory"
32-
else
33-
IMG="$IMG_VERSION"
38+
CURRENT_SESSION_NAME=$EXPAND_MEMORY_SESSION_NAME
39+
OTHER_SESSION_NAME=$NORMAL_SESSION_NAME
3440
fi
3541

42+
SSH_PORT=54432
43+
# StrictHostKeyChecking=no: Bypasses the interactive prompt to confirm the
44+
# host's authenticity.
45+
# UserKnownHostsFile=/dev/null: Prevents saving host keys to disk; this avoids
46+
# "Host key verification failed" errors when the QEMU instance restarts with
47+
# a new identity.
48+
SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes"
49+
SSH_TARGET="root@127.0.0.1"
50+
51+
SCREEN_LOG_PATH=screenlog.0
52+
SERIAL_LOG_PATH=/tmp/serial.log
53+
3654
# Function to download image
3755
download_image() {
3856
curl "https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/${IMG}.tar.gz" | tar zxv
3957
}
4058

41-
# Functions for running commands in QEMU screen
59+
# Functions for running commands in QEMU
4260
run_in_qemu() {
43-
(screen -S qemu_screen -p 0 -X stuff "$1\n") || (echo "run_in_qemu '$1' failed" && cat /tmp/serial.log)
44-
sleep 5
61+
run_in_qemu_with_timeout_secs "$1" 10s
4562
}
4663

4764
run_in_qemu_with_timeout_secs() {
48-
(screen -S qemu_screen -p 0 -X stuff "$1\n") || (echo "run_in_qemu '$1' failed" && cat /tmp/serial.log)
49-
sleep $2
65+
timeout "$2" \
66+
ssh $SSH_TARGET -p $SSH_PORT $SSH_OPTIONS "$1"
67+
}
68+
69+
copy_to_qemu() {
70+
local dest_path=$1
71+
shift
72+
73+
timeout 60s \
74+
scp -P $SSH_PORT $SSH_OPTIONS $@ $SSH_TARGET:"$dest_path"
75+
}
76+
77+
copy_ta_to_qemu() {
78+
copy_to_qemu "/lib/optee_armtz/" $@
79+
run_in_qemu "chmod 0444 /lib/optee_armtz/*.ta"
80+
}
81+
82+
copy_ca_to_qemu() {
83+
copy_to_qemu "/usr/bin/" $@
84+
}
85+
86+
copy_plugin_to_qemu() {
87+
copy_to_qemu "/usr/lib/tee-supplicant/plugins/" $@
88+
run_in_qemu "chmod 0666 /usr/lib/tee-supplicant/plugins/*.so"
89+
}
90+
91+
# Functions for handling failure
92+
print_detail_and_exit() {
93+
cat -v $SCREEN_LOG_PATH
94+
cat -v $SERIAL_LOG_PATH
95+
exit 1
5096
}
5197

5298
# Check if the image file exists locally
@@ -58,11 +104,29 @@ else
58104
fi
59105

60106
mkdir -p shared
107+
# Keeps the shared folder for ease of manual developer verification.
108+
# "mkdir -p shared && mount -t 9p -o trans=virtio host shared"
61109

110+
# Terminate existing QEMU screen sessions to prevent conflicts.
111+
if screen -list | grep -q "\.${OTHER_SESSION_NAME}[[:space:]]"; then
112+
echo "Other Session '${OTHER_SESSION_NAME}' is running, terminate it to prevent conflicts"
113+
screen -S $OTHER_SESSION_NAME -X quit
114+
rm -f $SERIAL_LOG_PATH && rm -f $SCREEN_LOG_PATH
115+
fi
62116
# Start QEMU screen
63-
screen -L -d -m -S qemu_screen ./optee-qemuv8.sh $IMG
64-
sleep 30
65-
run_in_qemu "root"
66-
run_in_qemu "mkdir -p shared && mount -t 9p -o trans=virtio host shared && cd shared"
67-
# libteec.so.2 since OP-TEE 4.2.0, for legacy versions:
68-
run_in_qemu "[ ! -e /usr/lib/libteec.so.1 ] && ln -s /usr/lib/libteec.so /usr/lib/libteec.so.1"
117+
if screen -list | grep -q "\.${CURRENT_SESSION_NAME}[[:space:]]"; then
118+
echo "Session '${CURRENT_SESSION_NAME}' is already running. Skipping start."
119+
else
120+
echo "Starting new session: ${CURRENT_SESSION_NAME}"
121+
screen -L -d -m -S $CURRENT_SESSION_NAME ./optee-qemuv8.sh $IMG
122+
fi
123+
124+
TEST_QEMU_SCRIPT_NAME=/tmp/teaclave-$CURRENT_SESSION_NAME.sh
125+
cat <<EOF > "$TEST_QEMU_SCRIPT_NAME"
126+
until ssh -p $SSH_PORT $SSH_TARGET $SSH_OPTIONS "true" >/dev/null 2>&1; do
127+
printf "."
128+
sleep 1
129+
done
130+
EOF
131+
timeout 30s bash $TEST_QEMU_SCRIPT_NAME
132+
echo "QEMU SSH Ready"

tests/test_acipher.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,14 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/acipher-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/acipher-rs/host/target/$TARGET_HOST/release/acipher-rs shared
26+
copy_ta_to_qemu ../examples/acipher-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/acipher-rs/host/target/$TARGET_HOST/release/acipher-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./acipher-rs 256 teststring\n"
32-
run_in_qemu "^C"
30+
OUTPUT=$(run_in_qemu "acipher-rs 256 teststring") || print_detail_and_exit
3331

3432
# Script specific checks
3533
{
36-
grep -q "Success encrypt input text \".*\" as [0-9]* bytes cipher text:" screenlog.0 &&
37-
grep -q "Success decrypt the above ciphertext as [0-9]* bytes plain text:" screenlog.0
38-
} || {
39-
cat -v screenlog.0
40-
cat -v /tmp/serial.log
41-
false
42-
}
43-
44-
rm screenlog.0
34+
grep -q "Success encrypt input text \".*\" as [0-9]* bytes cipher text:" <<< "$OUTPUT" &&
35+
grep -q "Success decrypt the above ciphertext as [0-9]* bytes plain text:" <<< "$OUTPUT"
36+
} || print_detail_and_exit

tests/test_aes.sh

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,18 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/aes-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/aes-rs/host/target/$TARGET_HOST/release/aes-rs shared
26+
copy_ta_to_qemu ../examples/aes-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/aes-rs/host/target/$TARGET_HOST/release/aes-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./aes-rs\n"
32-
run_in_qemu "^C"
30+
OUTPUT=$(run_in_qemu "aes-rs") || print_detail_and_exit
3331

3432
# Script specific checks
3533
{
36-
grep -q "Prepare encode operation" screenlog.0 &&
37-
grep -q "Load key in TA" screenlog.0 &&
38-
grep -q "Reset ciphering operation in TA (provides the initial vector)" screenlog.0 &&
39-
grep -q "Encode buffer from TA" screenlog.0 &&
40-
grep -q "Prepare decode operation" screenlog.0 &&
41-
grep -q "Clear text and decoded text match" screenlog.0
42-
} || {
43-
cat -v screenlog.0
44-
cat -v /tmp/serial.log
45-
false
46-
}
47-
48-
rm screenlog.0
34+
grep -q "Prepare encode operation" <<< "$OUTPUT" &&
35+
grep -q "Load key in TA" <<< "$OUTPUT" &&
36+
grep -q "Reset ciphering operation in TA (provides the initial vector)" <<< "$OUTPUT" &&
37+
grep -q "Encode buffer from TA" <<< "$OUTPUT" &&
38+
grep -q "Prepare decode operation" <<< "$OUTPUT" &&
39+
grep -q "Clear text and decoded text match" <<< "$OUTPUT"
40+
} || print_detail_and_exit

tests/test_authentication.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,14 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/authentication-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/authentication-rs/host/target/$TARGET_HOST/release/authentication-rs shared
26+
copy_ta_to_qemu ../examples/authentication-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/authentication-rs/host/target/$TARGET_HOST/release/authentication-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./authentication-rs\n"
32-
run_in_qemu "^C"
30+
OUTPUT=$(run_in_qemu "authentication-rs") || print_detail_and_exit
3331

3432
# Script specific checks
3533
{
36-
grep -q "Clear text and decoded text match" screenlog.0 &&
37-
grep -q "Success" screenlog.0
38-
} || {
39-
cat -v screenlog.0
40-
cat -v /tmp/serial.log
41-
false
42-
}
43-
44-
rm screenlog.0
34+
grep -q "Clear text and decoded text match" <<< "$OUTPUT" &&
35+
grep -q "Success" <<< "$OUTPUT"
36+
} || print_detail_and_exit

tests/test_big_int.sh

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,13 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/big_int-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/big_int-rs/host/target/$TARGET_HOST/release/big_int-rs shared
26+
copy_ta_to_qemu ../examples/big_int-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/big_int-rs/host/target/$TARGET_HOST/release/big_int-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./big_int-rs\n"
32-
run_in_qemu "^C"
30+
OUTPUT=$(run_in_qemu "big_int-rs") || print_detail_and_exit
3331

3432
# Script specific checks
3533
{
36-
grep -q "\[.*] > \[.*]\|\[.*] < \[.*]\|\[.*] == \[.*]" /tmp/serial.log &&
37-
grep -q "\[.*] in u8 array is \[.*]" /tmp/serial.log &&
38-
grep -q "\[.*] in i32 is [0-9]*" /tmp/serial.log &&
39-
grep -q "\[.*] + \[.*] = \[.*]" /tmp/serial.log &&
40-
grep -q "\[.*] - \[.*] = \[.*]" /tmp/serial.log &&
41-
grep -q "\[.*] \* \[.*] = \[.*]" /tmp/serial.log &&
42-
grep -q "\[.*] / \[.*] = \[.*]" /tmp/serial.log &&
43-
grep -q "\[.*] % \[.*] = \[.*]" /tmp/serial.log &&
44-
grep -q "Success" screenlog.0
45-
} || {
46-
cat -v screenlog.0
47-
cat -v /tmp/serial.log
48-
false
49-
}
50-
51-
rm screenlog.0
34+
grep -q "Success" <<< "$OUTPUT"
35+
} || print_detail_and_exit

tests/test_build_with_optee_utee_sys.sh

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,17 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/build_with_optee_utee_sys-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/build_with_optee_utee_sys-rs/host/target/$TARGET_HOST/release/build_with_optee_utee_sys-rs shared
26+
copy_ta_to_qemu ../examples/build_with_optee_utee_sys-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/build_with_optee_utee_sys-rs/host/target/$TARGET_HOST/release/build_with_optee_utee_sys-rs
2828

29-
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
3129
# Run command twice, ensure the instance are keeping alive.
32-
run_in_qemu "./build_with_optee_utee_sys-rs\n"
33-
run_in_qemu "./build_with_optee_utee_sys-rs\n"
34-
run_in_qemu "^C"
30+
OUTPUT1=$(run_in_qemu "build_with_optee_utee_sys-rs") || print_detail_and_exit
31+
OUTPUT2=$(run_in_qemu "build_with_optee_utee_sys-rs") || print_detail_and_exit
3532

3633
# Script specific checks
3734
{
38-
grep -q "result is: 0" screenlog.0 &&
39-
grep -q "result is: 1" screenlog.0 &&
40-
grep -q "result is: 2" screenlog.0 &&
41-
grep -q "result is: 3" screenlog.0
42-
} || {
43-
cat -v screenlog.0
44-
cat -v /tmp/serial.log
45-
false
46-
}
47-
48-
rm screenlog.0
35+
grep -q "result is: 0" <<< "$OUTPUT1" &&
36+
grep -q "result is: 1" <<< "$OUTPUT1" &&
37+
grep -q "result is: 2" <<< "$OUTPUT2" &&
38+
grep -q "result is: 3" <<< "$OUTPUT2"
39+
} || print_detail_and_exit

tests/test_client_pool.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,15 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/client_pool-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/client_pool-rs/host/target/$TARGET_HOST/release/client_pool-rs shared
26+
copy_ta_to_qemu ../examples/client_pool-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/client_pool-rs/host/target/$TARGET_HOST/release/client_pool-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./client_pool-rs thread -p 2 -c 2 -t 500 -e 2000\n"
32-
run_in_qemu "./client_pool-rs async -p 2 -c 2 -t 500 -e 2000\n"
33-
run_in_qemu "^C"
30+
OUTPUT1=$(run_in_qemu "client_pool-rs thread -p 2 -c 2 -t 500 -e 2000") || print_detail_and_exit
31+
OUTPUT2=$(run_in_qemu "client_pool-rs async -p 2 -c 2 -t 500 -e 2000") || print_detail_and_exit
3432

3533
# Script specific checks
3634
{
37-
grep -q "r2d2: total tasks: 2, total finish: 2" screenlog.0 &&
38-
grep -q "mobc: total tasks: 2, total finish: 2" screenlog.0
39-
} || {
40-
cat -v screenlog.0
41-
cat -v /tmp/serial.log
42-
false
43-
}
44-
45-
rm screenlog.0
35+
grep -q "r2d2: total tasks: 2, total finish: " <<< "$OUTPUT1" &&
36+
grep -q "mobc: total tasks: 2, total finish: " <<< "$OUTPUT2"
37+
} || print_detail_and_exit

tests/test_diffie_hellman.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,15 @@ set -xe
2323
source setup.sh
2424

2525
# Copy TA and host binary
26-
cp ../examples/diffie_hellman-rs/ta/target/$TARGET_TA/release/*.ta shared
27-
cp ../examples/diffie_hellman-rs/host/target/$TARGET_HOST/release/diffie_hellman-rs shared
26+
copy_ta_to_qemu ../examples/diffie_hellman-rs/ta/target/$TARGET_TA/release/*.ta
27+
copy_ca_to_qemu ../examples/diffie_hellman-rs/host/target/$TARGET_HOST/release/diffie_hellman-rs
2828

2929
# Run script specific commands in QEMU
30-
run_in_qemu "cp *.ta /lib/optee_armtz/\n"
31-
run_in_qemu "./diffie_hellman-rs\n"
32-
run_in_qemu "^C"
30+
OUTPUT=$(run_in_qemu "diffie_hellman-rs") || print_detail_and_exit
3331

3432
# Script specific checks
3533
{
36-
grep -q "get key [0|1] pair as public: \[.*], private: \[.*]" screenlog.0 &&
37-
grep -q "Derived share key as \[.*]" screenlog.0 &&
38-
grep -q "Success" screenlog.0
39-
} || {
40-
cat -v screenlog.0
41-
cat -v /tmp/serial.log
42-
false
43-
}
44-
45-
rm screenlog.0
34+
grep -q "get key [0|1] pair as public: \[.*], private: \[.*]" <<< "$OUTPUT" &&
35+
grep -q "Derived share key as \[.*]" <<< "$OUTPUT" &&
36+
grep -q "Success" <<< "$OUTPUT"
37+
} || print_detail_and_exit

0 commit comments

Comments
 (0)