You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by iv...@apache.org on 2026/02/06 11:56:43 UTC

(teaclave-trustzone-sdk) branch main updated (dcc65e6 -> e651157)

This is an automated email from the ASF dual-hosted git repository.

ivila pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git


    from dcc65e6  ci: split "build-and-test-examples" to reduce runtime
     new 0257474  ci: build qemu image with ssh enable
     new e651157  ci: utilize ssh for qemu command execution, replacing the screen-based workflow

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/reuse_build_test_qemu_image.yml |  3 +
 .patches/test_qemu/README.md                      | 10 +++
 .patches/test_qemu/optee-build_enable_ssh.patch   | 77 +++++++++++++++++++
 ci/ci.sh                                          |  6 +-
 tests/optee-qemuv8.sh                             |  2 +-
 tests/setup.sh                                    | 92 +++++++++++++++++++----
 tests/test_acipher.sh                             | 20 ++---
 tests/test_aes.sh                                 | 28 +++----
 tests/test_authentication.sh                      | 20 ++---
 tests/test_big_int.sh                             | 26 ++-----
 tests/test_build_with_optee_utee_sys.sh           | 27 +++----
 tests/test_client_pool.sh                         | 22 ++----
 tests/test_diffie_hellman.sh                      | 22 ++----
 tests/test_digest.sh                              | 20 ++---
 tests/test_error_handling.sh                      | 20 ++---
 tests/test_eth_wallet.sh                          | 17 ++---
 tests/test_hello_world.sh                         | 27 ++-----
 tests/test_hotp.sh                                | 20 ++---
 tests/test_inter_ta.sh                            | 18 ++---
 tests/test_message_passing_interface.sh           | 18 ++---
 tests/test_mnist_rs.sh                            | 26 +++----
 tests/test_property.sh                            | 17 +----
 tests/test_random.sh                              | 22 ++----
 tests/test_secure_db_abstraction.sh               | 19 +----
 tests/test_secure_storage.sh                      | 32 +++-----
 tests/test_serde.sh                               | 20 ++---
 tests/test_signature_verification.sh              | 20 ++---
 tests/test_supp_plugin.sh                         | 34 ++++-----
 tests/test_tcp_client.sh                          | 19 +----
 tests/test_time.sh                                | 18 ++---
 tests/test_tls_client.sh                          | 19 +----
 tests/test_tls_server.sh                          | 30 +++-----
 tests/test_udp_socket.sh                          | 18 ++---
 33 files changed, 348 insertions(+), 441 deletions(-)
 create mode 100644 .patches/test_qemu/optee-build_enable_ssh.patch


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org


(teaclave-trustzone-sdk) 02/02: ci: utilize ssh for qemu command execution, replacing the screen-based workflow

Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git

commit e6511571ef29dc7bd2dd971098027cdcfea86ded
Author: ivila <39...@qq.com>
AuthorDate: Fri Feb 6 14:51:42 2026 +0800

    ci: utilize ssh for qemu command execution, replacing the screen-based workflow
---
 ci/ci.sh                                |  6 ++-
 tests/optee-qemuv8.sh                   |  2 +-
 tests/setup.sh                          | 92 ++++++++++++++++++++++++++++-----
 tests/test_acipher.sh                   | 20 +++----
 tests/test_aes.sh                       | 28 ++++------
 tests/test_authentication.sh            | 20 +++----
 tests/test_big_int.sh                   | 26 ++--------
 tests/test_build_with_optee_utee_sys.sh | 27 ++++------
 tests/test_client_pool.sh               | 22 +++-----
 tests/test_diffie_hellman.sh            | 22 +++-----
 tests/test_digest.sh                    | 20 +++----
 tests/test_error_handling.sh            | 20 +++----
 tests/test_eth_wallet.sh                | 17 ++----
 tests/test_hello_world.sh               | 27 +++-------
 tests/test_hotp.sh                      | 20 +++----
 tests/test_inter_ta.sh                  | 18 +++----
 tests/test_message_passing_interface.sh | 18 ++-----
 tests/test_mnist_rs.sh                  | 26 ++++------
 tests/test_property.sh                  | 17 ++----
 tests/test_random.sh                    | 22 +++-----
 tests/test_secure_db_abstraction.sh     | 19 ++-----
 tests/test_secure_storage.sh            | 32 +++++-------
 tests/test_serde.sh                     | 20 +++----
 tests/test_signature_verification.sh    | 20 ++-----
 tests/test_supp_plugin.sh               | 34 +++++-------
 tests/test_tcp_client.sh                | 19 ++-----
 tests/test_time.sh                      | 18 ++-----
 tests/test_tls_client.sh                | 19 ++-----
 tests/test_tls_server.sh                | 30 ++++-------
 tests/test_udp_socket.sh                | 18 ++-----
 30 files changed, 258 insertions(+), 441 deletions(-)

diff --git a/ci/ci.sh b/ci/ci.sh
index fbd1ccc..6bde940 100755
--- a/ci/ci.sh
+++ b/ci/ci.sh
@@ -25,10 +25,12 @@ pushd ../tests
 # probability of detecting failures early in the pipeline.
 # Run std only tests
 if [ "$STD" ]; then
-    ./test_serde.sh
-    ./test_message_passing_interface.sh
+    # move the EXPAND_TA_MEMORY tests together
     ./test_tls_client.sh
     ./test_tls_server.sh
+
+    ./test_serde.sh
+    ./test_message_passing_interface.sh
     ./test_eth_wallet.sh
     ./test_secure_db_abstraction.sh
 else
diff --git a/tests/optee-qemuv8.sh b/tests/optee-qemuv8.sh
index bd334f2..ee397f6 100755
--- a/tests/optee-qemuv8.sh
+++ b/tests/optee-qemuv8.sh
@@ -32,5 +32,5 @@ cd $1 && ./qemu-system-aarch64 \
     -kernel Image \
     -fsdev local,id=fsdev0,path=$(pwd)/../shared,security_model=none \
     -device virtio-9p-device,fsdev=fsdev0,mount_tag=host \
-    -netdev user,id=vmnic,hostfwd=:127.0.0.1:54433-:4433 \
+    -netdev user,id=vmnic,hostfwd=:127.0.0.1:54433-:4433,hostfwd=:127.0.0.1:54432-:22 \
     -device virtio-net-device,netdev=vmnic
diff --git a/tests/setup.sh b/tests/setup.sh
index 34e938a..f4ae6c9 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -26,27 +26,73 @@ OPTEE_TAG=optee-$(cat ../optee-version.txt)
 # Define IMG_VERSION
 IMG_VERSION="$(uname -m)-$OPTEE_TAG-qemuv8-ubuntu-24.04"
 
-# Set IMG based on NEED_EXPANDED_MEM
+IMG="$IMG_VERSION"
+NORMAL_SESSION_NAME="qemu_screen"
+EXPAND_MEMORY_SESSION_NAME="qemu_screen_expand_ta_memory"
+
+CURRENT_SESSION_NAME=$NORMAL_SESSION_NAME
+OTHER_SESSION_NAME=$EXPAND_MEMORY_SESSION_NAME
+# Change Options based on NEED_EXPANDED_MEM
 if [ "$NEED_EXPANDED_MEM" = true ]; then
     IMG="${IMG_VERSION}-expand-ta-memory"
-else
-    IMG="$IMG_VERSION"
+    CURRENT_SESSION_NAME=$EXPAND_MEMORY_SESSION_NAME
+    OTHER_SESSION_NAME=$NORMAL_SESSION_NAME
 fi
 
+SSH_PORT=54432
+# StrictHostKeyChecking=no: Bypasses the interactive prompt to confirm the
+#   host's authenticity.
+# UserKnownHostsFile=/dev/null: Prevents saving host keys to disk; this avoids
+#   "Host key verification failed" errors when the QEMU instance restarts with
+#   a new identity.
+SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes"
+SSH_TARGET="root@127.0.0.1"
+
+SCREEN_LOG_PATH=screenlog.0
+SERIAL_LOG_PATH=/tmp/serial.log
+
 # Function to download image
 download_image() {
     curl "https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/${IMG}.tar.gz" | tar zxv
 }
 
-# Functions for running commands in QEMU screen
+# Functions for running commands in QEMU
 run_in_qemu() {
-    (screen -S qemu_screen -p 0 -X stuff "$1\n") || (echo "run_in_qemu '$1' failed" && cat /tmp/serial.log)
-    sleep 5
+    run_in_qemu_with_timeout_secs "$1" 10s
 }
 
 run_in_qemu_with_timeout_secs() {
-    (screen -S qemu_screen -p 0 -X stuff "$1\n") || (echo "run_in_qemu '$1' failed" && cat /tmp/serial.log)
-    sleep $2
+    timeout "$2" \
+        ssh $SSH_TARGET -p $SSH_PORT $SSH_OPTIONS "$1"
+}
+
+copy_to_qemu() {
+    local dest_path=$1
+    shift
+
+    timeout 60s \
+        scp -P $SSH_PORT $SSH_OPTIONS $@ $SSH_TARGET:"$dest_path"
+}
+
+copy_ta_to_qemu() {
+    copy_to_qemu "/lib/optee_armtz/" $@
+    run_in_qemu "chmod 0444 /lib/optee_armtz/*.ta"
+}
+
+copy_ca_to_qemu() {
+    copy_to_qemu "/usr/bin/" $@
+}
+
+copy_plugin_to_qemu() {
+    copy_to_qemu "/usr/lib/tee-supplicant/plugins/" $@
+    run_in_qemu "chmod 0666 /usr/lib/tee-supplicant/plugins/*.so"
+}
+
+# Functions for handling failure
+print_detail_and_exit() {
+    cat -v $SCREEN_LOG_PATH
+    cat -v $SERIAL_LOG_PATH
+    exit 1
 }
 
 # Check if the image file exists locally
@@ -58,11 +104,29 @@ else
 fi
 
 mkdir -p shared
+# Keeps the shared folder for ease of manual developer verification.
+# "mkdir -p shared && mount -t 9p -o trans=virtio host shared"
 
+# Terminate existing QEMU screen sessions to prevent conflicts.
+if screen -list | grep -q "\.${OTHER_SESSION_NAME}[[:space:]]"; then
+    echo "Other Session '${OTHER_SESSION_NAME}' is running, terminate it to prevent conflicts"
+    screen -S $OTHER_SESSION_NAME -X quit
+    rm -f $SERIAL_LOG_PATH && rm -f $SCREEN_LOG_PATH
+fi
 # Start QEMU screen
-screen -L -d -m -S qemu_screen ./optee-qemuv8.sh $IMG
-sleep 30
-run_in_qemu "root"
-run_in_qemu "mkdir -p shared && mount -t 9p -o trans=virtio host shared && cd shared"
-# libteec.so.2 since OP-TEE 4.2.0, for legacy versions:
-run_in_qemu "[ ! -e /usr/lib/libteec.so.1 ] && ln -s /usr/lib/libteec.so /usr/lib/libteec.so.1"
+if screen -list | grep -q "\.${CURRENT_SESSION_NAME}[[:space:]]"; then
+    echo "Session '${CURRENT_SESSION_NAME}' is already running. Skipping start."
+else
+    echo "Starting new session: ${CURRENT_SESSION_NAME}"
+    screen -L -d -m -S $CURRENT_SESSION_NAME ./optee-qemuv8.sh $IMG
+fi
+
+TEST_QEMU_SCRIPT_NAME=/tmp/teaclave-$CURRENT_SESSION_NAME.sh
+cat <<EOF > "$TEST_QEMU_SCRIPT_NAME"
+    until ssh -p $SSH_PORT $SSH_TARGET $SSH_OPTIONS "true" >/dev/null 2>&1; do
+        printf "."
+        sleep 1
+    done
+EOF
+timeout 30s bash $TEST_QEMU_SCRIPT_NAME
+echo "QEMU SSH Ready"
diff --git a/tests/test_acipher.sh b/tests/test_acipher.sh
index 247abd7..c76d3af 100755
--- a/tests/test_acipher.sh
+++ b/tests/test_acipher.sh
@@ -23,22 +23,14 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/acipher-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/acipher-rs/host/target/$TARGET_HOST/release/acipher-rs shared
+copy_ta_to_qemu ../examples/acipher-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/acipher-rs/host/target/$TARGET_HOST/release/acipher-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./acipher-rs 256 teststring\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "acipher-rs 256 teststring") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Success encrypt input text \".*\" as [0-9]* bytes cipher text:" screenlog.0 &&
-    grep -q "Success decrypt the above ciphertext as [0-9]* bytes plain text:" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
+    grep -q "Success encrypt input text \".*\" as [0-9]* bytes cipher text:" <<< "$OUTPUT" &&
+    grep -q "Success decrypt the above ciphertext as [0-9]* bytes plain text:" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_aes.sh b/tests/test_aes.sh
index d50fc65..156a707 100755
--- a/tests/test_aes.sh
+++ b/tests/test_aes.sh
@@ -23,26 +23,18 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/aes-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/aes-rs/host/target/$TARGET_HOST/release/aes-rs shared
+copy_ta_to_qemu ../examples/aes-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/aes-rs/host/target/$TARGET_HOST/release/aes-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./aes-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "aes-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Prepare encode operation" screenlog.0 &&
-    grep -q "Load key in TA" screenlog.0 &&
-    grep -q "Reset ciphering operation in TA (provides the initial vector)" screenlog.0 &&
-    grep -q "Encode buffer from TA" screenlog.0 &&
-    grep -q "Prepare decode operation" screenlog.0 &&
-    grep -q "Clear text and decoded text match" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Prepare encode operation" <<< "$OUTPUT" &&
+    grep -q "Load key in TA" <<< "$OUTPUT" &&
+    grep -q "Reset ciphering operation in TA (provides the initial vector)" <<< "$OUTPUT" &&
+    grep -q "Encode buffer from TA" <<< "$OUTPUT" &&
+    grep -q "Prepare decode operation" <<< "$OUTPUT" &&
+    grep -q "Clear text and decoded text match" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_authentication.sh b/tests/test_authentication.sh
index 51ad091..e2253ff 100755
--- a/tests/test_authentication.sh
+++ b/tests/test_authentication.sh
@@ -23,22 +23,14 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/authentication-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/authentication-rs/host/target/$TARGET_HOST/release/authentication-rs shared
+copy_ta_to_qemu ../examples/authentication-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/authentication-rs/host/target/$TARGET_HOST/release/authentication-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./authentication-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "authentication-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Clear text and decoded text match" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Clear text and decoded text match" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_big_int.sh b/tests/test_big_int.sh
index 33ffe0a..0bc68da 100755
--- a/tests/test_big_int.sh
+++ b/tests/test_big_int.sh
@@ -23,29 +23,13 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/big_int-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/big_int-rs/host/target/$TARGET_HOST/release/big_int-rs shared
+copy_ta_to_qemu ../examples/big_int-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/big_int-rs/host/target/$TARGET_HOST/release/big_int-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./big_int-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "big_int-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "\[.*] > \[.*]\|\[.*] < \[.*]\|\[.*] == \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] in u8 array is \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] in i32 is [0-9]*" /tmp/serial.log &&
-    grep -q "\[.*] + \[.*] = \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] - \[.*] = \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] \* \[.*] = \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] / \[.*] = \[.*]" /tmp/serial.log &&
-    grep -q "\[.*] % \[.*] = \[.*]" /tmp/serial.log &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_build_with_optee_utee_sys.sh b/tests/test_build_with_optee_utee_sys.sh
index 55afd94..b7e27bb 100755
--- a/tests/test_build_with_optee_utee_sys.sh
+++ b/tests/test_build_with_optee_utee_sys.sh
@@ -23,26 +23,17 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/build_with_optee_utee_sys-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/build_with_optee_utee_sys-rs/host/target/$TARGET_HOST/release/build_with_optee_utee_sys-rs shared
+copy_ta_to_qemu ../examples/build_with_optee_utee_sys-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/build_with_optee_utee_sys-rs/host/target/$TARGET_HOST/release/build_with_optee_utee_sys-rs
 
-# Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
 # Run command twice, ensure the instance are keeping alive.
-run_in_qemu "./build_with_optee_utee_sys-rs\n"
-run_in_qemu "./build_with_optee_utee_sys-rs\n"
-run_in_qemu "^C"
+OUTPUT1=$(run_in_qemu "build_with_optee_utee_sys-rs") || print_detail_and_exit
+OUTPUT2=$(run_in_qemu "build_with_optee_utee_sys-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "result is: 0" screenlog.0 &&
-    grep -q "result is: 1" screenlog.0 &&
-    grep -q "result is: 2" screenlog.0 &&
-    grep -q "result is: 3" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
+    grep -q "result is: 0" <<< "$OUTPUT1" &&
+    grep -q "result is: 1" <<< "$OUTPUT1" &&
+    grep -q "result is: 2" <<< "$OUTPUT2" &&
+    grep -q "result is: 3" <<< "$OUTPUT2"
+} || print_detail_and_exit
diff --git a/tests/test_client_pool.sh b/tests/test_client_pool.sh
index 176fd9a..220b0db 100755
--- a/tests/test_client_pool.sh
+++ b/tests/test_client_pool.sh
@@ -23,23 +23,15 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/client_pool-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/client_pool-rs/host/target/$TARGET_HOST/release/client_pool-rs shared
+copy_ta_to_qemu ../examples/client_pool-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/client_pool-rs/host/target/$TARGET_HOST/release/client_pool-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./client_pool-rs thread -p 2 -c 2 -t 500 -e 2000\n"
-run_in_qemu "./client_pool-rs async -p 2 -c 2 -t 500 -e 2000\n"
-run_in_qemu "^C"
+OUTPUT1=$(run_in_qemu "client_pool-rs thread -p 2 -c 2 -t 500 -e 2000") || print_detail_and_exit
+OUTPUT2=$(run_in_qemu "client_pool-rs async -p 2 -c 2 -t 500 -e 2000") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "r2d2: total tasks: 2, total finish: 2" screenlog.0 &&
-    grep -q "mobc: total tasks: 2, total finish: 2" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
+    grep -q "r2d2: total tasks: 2, total finish: " <<< "$OUTPUT1" &&
+    grep -q "mobc: total tasks: 2, total finish: " <<< "$OUTPUT2"
+} || print_detail_and_exit
diff --git a/tests/test_diffie_hellman.sh b/tests/test_diffie_hellman.sh
index 4eae75c..0b36c91 100755
--- a/tests/test_diffie_hellman.sh
+++ b/tests/test_diffie_hellman.sh
@@ -23,23 +23,15 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/diffie_hellman-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/diffie_hellman-rs/host/target/$TARGET_HOST/release/diffie_hellman-rs shared
+copy_ta_to_qemu ../examples/diffie_hellman-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/diffie_hellman-rs/host/target/$TARGET_HOST/release/diffie_hellman-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./diffie_hellman-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "diffie_hellman-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "get key [0|1] pair as public: \[.*], private: \[.*]" screenlog.0 &&
-    grep -q "Derived share key as \[.*]" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "get key [0|1] pair as public: \[.*], private: \[.*]" <<< "$OUTPUT" &&
+    grep -q "Derived share key as \[.*]" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_digest.sh b/tests/test_digest.sh
index 4b0e81c..3c71ecf 100755
--- a/tests/test_digest.sh
+++ b/tests/test_digest.sh
@@ -23,22 +23,14 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/digest-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/digest-rs/host/target/$TARGET_HOST/release/digest-rs shared
+copy_ta_to_qemu ../examples/digest-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/digest-rs/host/target/$TARGET_HOST/release/digest-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./digest-rs message1 message2\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "digest-rs message1 message2") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Get message hash as:" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Get message hash as:" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_error_handling.sh b/tests/test_error_handling.sh
index 82b83ce..d2494ea 100755
--- a/tests/test_error_handling.sh
+++ b/tests/test_error_handling.sh
@@ -23,22 +23,14 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/error_handling-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/error_handling-rs/host/target/$TARGET_HOST/release/error_handling-rs shared
+copy_ta_to_qemu ../examples/error_handling-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/error_handling-rs/host/target/$TARGET_HOST/release/error_handling-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./error_handling-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "error_handling-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q -v "panicked" screenlog.0 &&
-    grep -q "Test passed" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm -rf screenlog.0
+    grep -q -v "panicked" <<< "$OUTPUT" &&
+    grep -q "Test passed" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_eth_wallet.sh b/tests/test_eth_wallet.sh
index 3e41433..7775e69 100755
--- a/tests/test_eth_wallet.sh
+++ b/tests/test_eth_wallet.sh
@@ -23,20 +23,13 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../projects/web3/eth_wallet/ta/target/$TARGET_TA/release/*.ta shared
-cp ../projects/web3/eth_wallet/host/target/$TARGET_HOST/release/eth_wallet-rs shared
+copy_ta_to_qemu ../projects/web3/eth_wallet/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../projects/web3/eth_wallet/host/target/$TARGET_HOST/release/eth_wallet-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./eth_wallet-rs test\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "eth_wallet-rs test") || print_detail_and_exit
 
 # Script specific checks
 {
-	grep -q "Tests passed" screenlog.0
-} || {
-        cat -v screenlog.0
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+	grep -q "Tests passed" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_hello_world.sh b/tests/test_hello_world.sh
index 88f7d67..348c463 100755
--- a/tests/test_hello_world.sh
+++ b/tests/test_hello_world.sh
@@ -18,29 +18,18 @@
 # under the License.
 
 set -xe
-
 # Include base script
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/hello_world-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/hello_world-rs/host/target/$TARGET_HOST/release/hello_world-rs shared
+copy_ta_to_qemu ../examples/hello_world-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/hello_world-rs/host/target/$TARGET_HOST/release/hello_world-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./hello_world-rs\n"
-run_in_qemu "^C"
-
-# Script specific checks
+OUTPUT=$(run_in_qemu "hello_world-rs") || print_detail_and_exit
 {
-    grep -q "original value is 29" screenlog.0 &&
-    grep -q "inc value is 129" screenlog.0 &&
-    grep -q "dec value is 29" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "original value is 29" <<< "$OUTPUT" &&
+    grep -q "inc value is 129" <<< "$OUTPUT" &&
+    grep -q "dec value is 29" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_hotp.sh b/tests/test_hotp.sh
index 045695e..3fcad09 100755
--- a/tests/test_hotp.sh
+++ b/tests/test_hotp.sh
@@ -23,22 +23,14 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/hotp-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/hotp-rs/host/target/$TARGET_HOST/release/hotp-rs shared
+copy_ta_to_qemu ../examples/hotp-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/hotp-rs/host/target/$TARGET_HOST/release/hotp-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./hotp-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "hotp-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Get HOTP" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-        cat -v screenlog.0
-        cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
+    grep -q "Get HOTP" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_inter_ta.sh b/tests/test_inter_ta.sh
index 390ecb1..cec0d9b 100755
--- a/tests/test_inter_ta.sh
+++ b/tests/test_inter_ta.sh
@@ -23,21 +23,15 @@ set -xe
 source setup.sh
 
 # Copy hello_world-rs TA for testing
-cp ../examples/hello_world-rs/ta/target/$TARGET_TA/release/*.ta shared
+copy_ta_to_qemu ../examples/hello_world-rs/ta/target/$TARGET_TA/release/*.ta
 # Copy TA and host binary
-cp ../examples/inter_ta-rs/host/target/$TARGET_HOST/release/inter_ta-rs shared
-cp ../examples/inter_ta-rs/ta/target/$TARGET_TA/release/*.ta shared
+copy_ta_to_qemu ../examples/inter_ta-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/inter_ta-rs/host/target/$TARGET_HOST/release/inter_ta-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./inter_ta-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "inter_ta-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
\ No newline at end of file
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_message_passing_interface.sh b/tests/test_message_passing_interface.sh
index cf476a1..75a8252 100755
--- a/tests/test_message_passing_interface.sh
+++ b/tests/test_message_passing_interface.sh
@@ -23,21 +23,13 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/message_passing_interface-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/message_passing_interface-rs/host/target/$TARGET_HOST/release/message_passing_interface-rs shared
+copy_ta_to_qemu ../examples/message_passing_interface-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/message_passing_interface-rs/host/target/$TARGET_HOST/release/message_passing_interface-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./message_passing_interface-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "message_passing_interface-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-	grep -q "Hello, World" screenlog.0
-} || {
-	cat -v screenlog.0
-	cat -v /tmp/serial.log
-	false
-}
-
-rm screenlog.0
\ No newline at end of file
+	grep -q "Hello, World" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_mnist_rs.sh b/tests/test_mnist_rs.sh
index 8b66e79..5d6fc57 100755
--- a/tests/test_mnist_rs.sh
+++ b/tests/test_mnist_rs.sh
@@ -23,26 +23,18 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/mnist-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/mnist-rs/host/target/$TARGET_HOST/release/mnist-rs shared
-# Copy samples files
-cp -r ../examples/mnist-rs/host/samples shared
+copy_ta_to_qemu ../examples/mnist-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/mnist-rs/host/target/$TARGET_HOST/release/mnist-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
 # Do not export the model due to QEMU's memory limitations.
-run_in_qemu_with_timeout_secs "./mnist-rs train -n 1\n" 300
-run_in_qemu "./mnist-rs infer -m samples/model.bin -b samples/7.bin -i samples/7.png\n"
-run_in_qemu "^C"
+OUTPUT1=$(run_in_qemu_with_timeout_secs "mnist-rs train -n 1" 300) || print_detail_and_exit
+# Copy samples files
+copy_to_qemu "/tmp" ../examples/mnist-rs/host/samples/*
+OUTPUT2=$(run_in_qemu "mnist-rs infer -m /tmp/model.bin -b /tmp/7.bin -i /tmp/7.png") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Train Success" screenlog.0 &&
-    grep -q "Infer Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
+    grep -q "Train Success" <<< "$OUTPUT1" &&
+    grep -q "Infer Success" <<< "$OUTPUT2"
+} || print_detail_and_exit
diff --git a/tests/test_property.sh b/tests/test_property.sh
index 588c903..9385b5f 100755
--- a/tests/test_property.sh
+++ b/tests/test_property.sh
@@ -23,19 +23,8 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/property-rs/host/target/$TARGET_HOST/release/property-rs shared
-cp ../examples/property-rs/ta/target/$TARGET_TA/release/*.ta shared
+copy_ta_to_qemu ../examples/property-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/property-rs/host/target/$TARGET_HOST/release/property-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./property-rs\n"
-run_in_qemu "^C"
-
-# Script specific checks
-{
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
\ No newline at end of file
+run_in_qemu "property-rs" || print_detail_and_exit
diff --git a/tests/test_random.sh b/tests/test_random.sh
index dbc5b1d..f3cda17 100755
--- a/tests/test_random.sh
+++ b/tests/test_random.sh
@@ -23,23 +23,15 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/random-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/random-rs/host/target/$TARGET_HOST/release/random-rs shared
+copy_ta_to_qemu ../examples/random-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/random-rs/host/target/$TARGET_HOST/release/random-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./random-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "random-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Invoking TA to generate random UUID" screenlog.0 &&
-    grep -q "Generate random UUID: [a-z0-9]*-[a-z0-9]*-[a-z0-9]*-[a-z0-9]*" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-        cat -v screenlog.0
-        cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Invoking TA to generate random UUID" <<< "$OUTPUT" &&
+    grep -q "Generate random UUID: [a-z0-9]*-[a-z0-9]*-[a-z0-9]*-[a-z0-9]*" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_secure_db_abstraction.sh b/tests/test_secure_db_abstraction.sh
index db97190..1bf72dd 100755
--- a/tests/test_secure_db_abstraction.sh
+++ b/tests/test_secure_db_abstraction.sh
@@ -23,22 +23,9 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/secure_db_abstraction-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/secure_db_abstraction-rs/host/target/$TARGET_HOST/release/secure_db_abstraction-rs shared
+copy_ta_to_qemu ../examples/secure_db_abstraction-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/secure_db_abstraction-rs/host/target/$TARGET_HOST/release/secure_db_abstraction-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
 # IO could be much slower than expected
-run_in_qemu_with_timeout_secs "./secure_db_abstraction-rs\n" 10
-run_in_qemu "^C"
-
-# Script specific checks
-{
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
+run_in_qemu_with_timeout_secs "secure_db_abstraction-rs" 20 || print_detail_and_exit
diff --git a/tests/test_secure_storage.sh b/tests/test_secure_storage.sh
index e5d7e9b..116b804 100755
--- a/tests/test_secure_storage.sh
+++ b/tests/test_secure_storage.sh
@@ -23,32 +23,24 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/secure_storage-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/secure_storage-rs/host/target/$TARGET_HOST/release/secure_storage-rs shared
+copy_ta_to_qemu ../examples/secure_storage-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/secure_storage-rs/host/target/$TARGET_HOST/release/secure_storage-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
 # IO could be much slower than expected
-run_in_qemu_with_timeout_secs "./secure_storage-rs\n" 10
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu_with_timeout_secs "secure_storage-rs" 20) || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Test on object \"object#1\"" screenlog.0 &&
-    grep -q "\- Create and load object in the TA secure storage" screenlog.0 &&
-    grep -q "\- Read back the object" screenlog.0 &&
-    grep -q "\- Content read-out correctly" screenlog.0 &&
-    grep -q "\- Delete the object" screenlog.0 &&
+    grep -q "Test on object \"object#1\"" <<< "$OUTPUT" &&
+    grep -q "\- Create and load object in the TA secure storage" <<< "$OUTPUT" &&
+    grep -q "\- Read back the object" <<< "$OUTPUT" &&
+    grep -q "\- Content read-out correctly" <<< "$OUTPUT" &&
+    grep -q "\- Delete the object" <<< "$OUTPUT" &&
 
-    grep -q "Test on object \"object#2\"" screenlog.0 &&
+    grep -q "Test on object \"object#2\"" <<< "$OUTPUT" &&
     #miss the read correctly output
-    grep -Eq "\- Object not found in TA secure storage, create it|\- Object found in TA secure storage, delete it" screenlog.0 &&
+    grep -Eq "\- Object not found in TA secure storage, create it|\- Object found in TA secure storage, delete it" <<< "$OUTPUT" &&
 
-    grep -q "We're done, close and release TEE resources" screenlog.0
-} || {
-        cat -v screenlog.0
-        cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
+    grep -q "We're done, close and release TEE resources" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_serde.sh b/tests/test_serde.sh
index 7bc4351..e3a6889 100755
--- a/tests/test_serde.sh
+++ b/tests/test_serde.sh
@@ -23,24 +23,16 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/serde-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/serde-rs/host/target/$TARGET_HOST/release/serde-rs shared
+copy_ta_to_qemu ../examples/serde-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/serde-rs/host/target/$TARGET_HOST/release/serde-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./serde-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "serde-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-	grep -q "Success" screenlog.0 &&
-	grep -q "Point { x: 1, y: 2 }" screenlog.0 &&
+	grep -q "Success" <<< "$OUTPUT" &&
+	grep -q "Point { x: 1, y: 2 }" <<< "$OUTPUT" &&
 	grep -q "serialized = " /tmp/serial.log &&
 	grep -q "deserialized = " /tmp/serial.log
-} || {
-        cat -v screenlog.0
-        cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+} || print_detail_and_exit
diff --git a/tests/test_signature_verification.sh b/tests/test_signature_verification.sh
index eb3c92d..f7dd77a 100755
--- a/tests/test_signature_verification.sh
+++ b/tests/test_signature_verification.sh
@@ -23,23 +23,13 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/signature_verification-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/signature_verification-rs/host/target/$TARGET_HOST/release/signature_verification-rs shared
+copy_ta_to_qemu ../examples/signature_verification-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/signature_verification-rs/host/target/$TARGET_HOST/release/signature_verification-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./signature_verification-rs\n"
-# Additional 5 secs for the application to finish
-sleep 5
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "signature_verification-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_supp_plugin.sh b/tests/test_supp_plugin.sh
index 95294d8..4b91bd8 100755
--- a/tests/test_supp_plugin.sh
+++ b/tests/test_supp_plugin.sh
@@ -23,29 +23,21 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/supp_plugin-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/supp_plugin-rs/host/target/$TARGET_HOST/release/supp_plugin-rs shared
-cp ../examples/supp_plugin-rs/plugin/target/$TARGET_HOST/release/*.plugin.so shared
+copy_ta_to_qemu ../examples/supp_plugin-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/supp_plugin-rs/host/target/$TARGET_HOST/release/supp_plugin-rs
+copy_plugin_to_qemu ../examples/supp_plugin-rs/plugin/target/$TARGET_HOST/release/*.plugin.so
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "cp *.plugin.so /usr/lib/tee-supplicant/plugins/\n"
-run_in_qemu "kill \$(pidof tee-supplicant)\n"
-run_in_qemu "/usr/sbin/tee-supplicant &\n\n"
-run_in_qemu "./supp_plugin-rs\n"
-run_in_qemu "^C"
+run_in_qemu "kill \$(pidof tee-supplicant)"
+run_in_qemu "nohup /usr/sbin/tee-supplicant > /tmp/tee_supplicant.log 2>&1 &"
+OUTPUT=$(run_in_qemu "supp_plugin-rs && cat /tmp/tee_supplicant.log") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "send value" screenlog.0 &&
-    grep -q "invoke" screenlog.0 &&
-    grep -q "receive value" screenlog.0 &&
-    grep -q "invoke commmand finished" screenlog.0 &&
-    grep -q "Success" screenlog.0
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-    false
-}
-
-rm screenlog.0
\ No newline at end of file
+    grep -q "\*host\*: send value" <<< "$OUTPUT" &&
+    grep -q "\*host\*: invoke" <<< "$OUTPUT" &&
+    grep -q "Success" <<< "$OUTPUT"
+    grep -q "\*plugin\*: invoke" <<< "$OUTPUT" &&
+    grep -q "\*plugin\*: receive value" <<< "$OUTPUT" &&
+    grep -q "\*plugin\*: send value" <<< "$OUTPUT"
+} || print_detail_and_exit
diff --git a/tests/test_tcp_client.sh b/tests/test_tcp_client.sh
index 232159b..f275ec7 100755
--- a/tests/test_tcp_client.sh
+++ b/tests/test_tcp_client.sh
@@ -23,21 +23,8 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/tcp_client-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/tcp_client-rs/host/target/$TARGET_HOST/release/tcp_client-rs shared
+copy_ta_to_qemu ../examples/tcp_client-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/tcp_client-rs/host/target/$TARGET_HOST/release/tcp_client-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./tcp_client-rs\n"
-run_in_qemu "^C"
-
-# Script specific checks
-{
-	grep -q "Success" screenlog.0
-} || {
-	cat -v screenlog.0
-	cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+run_in_qemu "tcp_client-rs" || print_detail_and_exit
diff --git a/tests/test_time.sh b/tests/test_time.sh
index 2b8fd4f..f95ccf4 100755
--- a/tests/test_time.sh
+++ b/tests/test_time.sh
@@ -23,25 +23,17 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/time-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/time-rs/host/target/$TARGET_HOST/release/time-rs shared
+copy_ta_to_qemu ../examples/time-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/time-rs/host/target/$TARGET_HOST/release/time-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./time-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "time-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-    grep -q "Success" screenlog.0 &&
+    grep -q "Success" <<< "$OUTPUT" &&
     grep -q "\[+] Get REE time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log &&
     grep -q "\[+] Now wait 1 second in TEE" /tmp/serial.log &&
     grep -q "\[+] Get system time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log &&
     grep -q "\[+] After set the TA time 5 seconds ahead of system time, new TA time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log
-} || {
-    cat -v screenlog.0
-    cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+} || print_detail_and_exit
diff --git a/tests/test_tls_client.sh b/tests/test_tls_client.sh
index 895b3d1..b5f1ab3 100755
--- a/tests/test_tls_client.sh
+++ b/tests/test_tls_client.sh
@@ -24,21 +24,8 @@ NEED_EXPANDED_MEM=true
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/tls_client-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/tls_client-rs/host/target/$TARGET_HOST/release/tls_client-rs shared
+copy_ta_to_qemu ../examples/tls_client-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/tls_client-rs/host/target/$TARGET_HOST/release/tls_client-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./tls_client-rs\n"
-run_in_qemu "^C"
-
-# Script specific checks
-{
-	grep -q "Success" screenlog.0
-} || {
-	cat -v screenlog.0
-	cat -v /tmp/serial.log
-	false
-}
-
-rm screenlog.0
+run_in_qemu "tls_client-rs" || print_detail_and_exit
diff --git a/tests/test_tls_server.sh b/tests/test_tls_server.sh
index 6b2e556..1e6a5ed 100755
--- a/tests/test_tls_server.sh
+++ b/tests/test_tls_server.sh
@@ -23,32 +23,20 @@ NEED_EXPANDED_MEM=true
 # Include base script
 source setup.sh
 
-rm -f openssl.log
-
 # Copy TA and host binary
-cp ../examples/tls_server-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/tls_server-rs/host/target/$TARGET_HOST/release/tls_server-rs shared
-cp ../examples/tls_server-rs/ta/test-ca/ecdsa/ca.cert shared
+copy_ta_to_qemu ../examples/tls_server-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/tls_server-rs/host/target/$TARGET_HOST/release/tls_server-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./tls_server-rs\n"
+run_in_qemu "nohup tls_server-rs > /tmp/tls_server.log 2>&1 &"
+(sleep 5 && run_in_qemu "cat /tmp/tls_server.log" | grep -q "listening") || (echo " [TIMEOUT] Server failed to start." && print_detail_and_exit)
 # Outside the QEMU: connect the server using openssl, accept the self-signed CA cert
 # || true because we want to continue testing even if the connection fails, and check the log later
-echo "Q" | openssl s_client -connect 127.0.0.1:54433 -CAfile shared/ca.cert -debug > openssl.log 2>&1 || true
-run_in_qemu "^C"
+OPENSSL_OUTPUT=$(echo "Q" | openssl s_client -connect 127.0.0.1:54433 -CAfile ../examples/tls_server-rs/ta/test-ca/ecdsa/ca.cert -debug 2>&1) || true
+run_in_qemu "kill \$(pidof tls_server-rs)" || print_detail_and_exit
 
 # Script specific checks
 {
-	grep -q "Verification: OK" openssl.log &&
-	grep -q "close session" screenlog.0
-} || {
-	cat -v screenlog.0
-	cat -v /tmp/serial.log
-	cat -v openssl.log
-	false
-}
-
-rm screenlog.0
-
-rm -rf openssl.log
\ No newline at end of file
+	grep -q "Verification: OK" <<< "$OPENSSL_OUTPUT" &&
+	grep -v "SSL handshake has read 0 bytes " <<< "$OPENSSL_OUTPUT" # prevent openssl goes to http protocol
+} || print_detail_and_exit
diff --git a/tests/test_udp_socket.sh b/tests/test_udp_socket.sh
index 04483f4..ebdc7ae 100755
--- a/tests/test_udp_socket.sh
+++ b/tests/test_udp_socket.sh
@@ -23,21 +23,13 @@ set -xe
 source setup.sh
 
 # Copy TA and host binary
-cp ../examples/udp_socket-rs/ta/target/$TARGET_TA/release/*.ta shared
-cp ../examples/udp_socket-rs/host/target/$TARGET_HOST/release/udp_socket-rs shared
+copy_ta_to_qemu ../examples/udp_socket-rs/ta/target/$TARGET_TA/release/*.ta
+copy_ca_to_qemu ../examples/udp_socket-rs/host/target/$TARGET_HOST/release/udp_socket-rs
 
 # Run script specific commands in QEMU
-run_in_qemu "cp *.ta /lib/optee_armtz/\n"
-run_in_qemu "./udp_socket-rs\n"
-run_in_qemu "^C"
+OUTPUT=$(run_in_qemu "udp_socket-rs") || print_detail_and_exit
 
 # Script specific checks
 {
-	grep -q "Success" screenlog.0
-} || {
-	cat -v screenlog.0
-	cat -v /tmp/serial.log
-        false
-}
-
-rm screenlog.0
\ No newline at end of file
+	grep -q "Success" <<< "$OUTPUT"
+} || print_detail_and_exit


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org


(teaclave-trustzone-sdk) 01/02: ci: build qemu image with ssh enable

Posted by iv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ivila pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git

commit 02574745bc03de8f8549fcfba57f6ce1fe0d0960
Author: ivila <39...@qq.com>
AuthorDate: Thu Feb 5 16:07:53 2026 +0800

    ci: build qemu image with ssh enable
---
 .github/workflows/reuse_build_test_qemu_image.yml |  3 +
 .patches/test_qemu/README.md                      | 10 +++
 .patches/test_qemu/optee-build_enable_ssh.patch   | 77 +++++++++++++++++++++++
 3 files changed, 90 insertions(+)

diff --git a/.github/workflows/reuse_build_test_qemu_image.yml b/.github/workflows/reuse_build_test_qemu_image.yml
index 9f37815..08c6b09 100644
--- a/.github/workflows/reuse_build_test_qemu_image.yml
+++ b/.github/workflows/reuse_build_test_qemu_image.yml
@@ -116,6 +116,9 @@ jobs:
           (cd ${{ env.QEMUV8_BUILD_FOLDER }}/qemu && git apply $GITHUB_WORKSPACE/.patches/test_qemu/qemu-qemu_expand_secure_memory.patch)
           (cd ${{ env.QEMUV8_BUILD_FOLDER }}/trusted-firmware-a && git apply $GITHUB_WORKSPACE/.patches/test_qemu/arm-atf_expand_secure_memory.patch)
 
+      - name: Apply patches to enable ssh
+        run: |
+          (cd ${{ env.QEMUV8_BUILD_FOLDER }}/build && git apply $GITHUB_WORKSPACE/.patches/test_qemu/optee-build_enable_ssh.patch)
       # cd to the output folder first to avoid extra path in the tar file.
       - name: Build And Pack
         env:
diff --git a/.patches/test_qemu/README.md b/.patches/test_qemu/README.md
index 8a3794f..1f71444 100644
--- a/.patches/test_qemu/README.md
+++ b/.patches/test_qemu/README.md
@@ -26,3 +26,13 @@ Relevant Patch File:
     to match the QEMU memory expansion.
 3. optee-build_expand_memory.patch: Updates build configurations to reflect the
     expanded memory setup.
+
+## Patches for enabling ssh
+
+Our CI workflow automates command execution via SSH and handles CA/TA deployment
+using SCP, providing a seamless local-like interface for the QEMU image.
+
+Relevant Patch File:
+
+1. optee-build_enable_ssh.patch: update build configurations to enable the ssh
+    server.
diff --git a/.patches/test_qemu/optee-build_enable_ssh.patch b/.patches/test_qemu/optee-build_enable_ssh.patch
new file mode 100644
index 0000000..deed9c2
--- /dev/null
+++ b/.patches/test_qemu/optee-build_enable_ssh.patch
@@ -0,0 +1,77 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+diff --git a/br-ext/board/qemu/post-build.sh b/br-ext/board/qemu/post-build.sh
+index 5b4f8b5..fe65f11 100755
+--- a/br-ext/board/qemu/post-build.sh
++++ b/br-ext/board/qemu/post-build.sh
+@@ -7,6 +7,7 @@ TARGETDIR="$1"
+ VIRTFS_AUTOMOUNT="$2"
+ VIRTFS_MOUNTPOINT="$3"
+ PSS_AUTOMOUNT="$4"
++ENABLE_SSH="$5"
+ 
+ if [[ -z $TARGET_DIR ]]; then
+     echo "TARGET_DIR missing"
+@@ -28,6 +29,11 @@ if [[ -z $PSS_AUTOMOUNT ]]; then
+     exit 1
+ fi
+ 
++if [[ -z $ENABLE_SSH ]]; then
++    echo "ENABLE_SSH missing"
++    exit 1
++fi
++
+ 
+ if [[ $VIRTFS_AUTOMOUNT == "y" ]]; then
+     grep host "$TARGETDIR"/etc/fstab > /dev/null || \
+@@ -41,3 +47,10 @@ if [[ $PSS_AUTOMOUNT == "y" ]]; then
+     echo "secure /var/lib/tee 9p trans=virtio,version=9p2000.L,msize=65536,rw 0 0" >> "$TARGET_DIR"/etc/fstab
+     echo "[+] persistent secure storage mount added to fstab"
+ fi
++
++
++if [[ $ENABLE_SSH == "y" ]]; then
++    sed -i -e 's/#PermitEmptyPasswords no/PermitEmptyPasswords yes/' "$TARGET_DIR"/etc/ssh/sshd_config
++    sed -i -e 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' "$TARGET_DIR"/etc/ssh/sshd_config
++    echo "[+] ssh server allow root with no password"
++fi
+diff --git a/qemu_v8.mk b/qemu_v8.mk
+index 9c36c8a..8d553d3 100644
+--- a/qemu_v8.mk
++++ b/qemu_v8.mk
+@@ -7,6 +7,7 @@ COMPILE_NS_USER ?= 64
+ override COMPILE_NS_KERNEL := 64
+ COMPILE_S_USER ?= 64
+ COMPILE_S_KERNEL ?= 64
++ENABLE_SSH ?= y
+ 
+ ################################################################################
+ # If you change this, you MUST run `make arm-tf-clean` first before rebuilding
+@@ -15,7 +16,11 @@ TF_A_TRUSTED_BOARD_BOOT ?= n
+ 
+ BR2_ROOTFS_OVERLAY = $(ROOT)/build/br-ext/board/qemu/overlay
+ BR2_ROOTFS_POST_BUILD_SCRIPT = $(ROOT)/build/br-ext/board/qemu/post-build.sh
+-BR2_ROOTFS_POST_SCRIPT_ARGS = "$(QEMU_VIRTFS_AUTOMOUNT) $(QEMU_VIRTFS_MOUNTPOINT) $(QEMU_PSS_AUTOMOUNT)"
++BR2_ROOTFS_POST_SCRIPT_ARGS = "$(QEMU_VIRTFS_AUTOMOUNT) $(QEMU_VIRTFS_MOUNTPOINT) $(QEMU_PSS_AUTOMOUNT) $(ENABLE_SSH)"
++ifeq ($(ENABLE_SSH),y)
++BR2_PACKAGE_OPENSSH ?= y
++BR2_SYSTEM_DHCP ?= eth0
++endif
+ 
+ PLAT_QEMU ?= virt
+ ifeq ($(PLAT_QEMU),virt)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org