Skip to content

Commit

Permalink
Simplify test scripts
Browse files Browse the repository at this point in the history
- Use the OP-TEE 4.2.0 prebuilt images and avoid multiple downloads;
- Add `tests/setup.sh` for common operations;
- Add `error_handling` test in qemu ci;
- unify scripts' indentation.

Similar changes on master branch: [1].

[1] apache@b05173f

Signed-off-by: Yuan Zhuang <[email protected]>
  • Loading branch information
DemesneGH committed May 10, 2024
1 parent 869f57c commit 9cc63e4
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 371 deletions.
1 change: 1 addition & 0 deletions ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ pushd ../tests
./test_time.sh
./test_signature_verification.sh
./test_supp_plugin.sh
./test_error_handling.sh

popd
13 changes: 13 additions & 0 deletions ci/qemu-check.exp
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,17 @@ expect {
}
}

expect "# "
info "Running error_handling-rs...\n"
send -- "error_handling-rs\r"
expect {
"Test passed" {
info "Test success\n"
}
timeout {
info "!!! Timeout: Test failed\n"
exit 1
}
}

info "Test Rust application finished\n"
2 changes: 2 additions & 0 deletions examples/error_handling-rs/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ fn test_error_handling() {
// Test repeated error invocation also returns the requested error.
let e = session.invoke_command(Command::ReturnGenericError as u32, &mut operation).expect_err("generic error");
assert_eq!(e.kind(), ErrorKind::Generic);

println!("Test passed");
}
23 changes: 23 additions & 0 deletions tests/cleanup_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# 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.

set -xe

rm -rf screenlog.0 shared
rm -rf optee-qemuv8-*
6 changes: 2 additions & 4 deletions tests/optee-qemuv8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# specific language governing permissions and limitations
# under the License.

cd optee-qemuv8-3.20.0-ubuntu-20.04 && ./qemu-system-aarch64 \
cd $1 && ./qemu-system-aarch64 \
-nodefaults \
-nographic \
-serial stdio -serial file:/tmp/serial.log \
Expand All @@ -30,6 +30,4 @@ cd optee-qemuv8-3.20.0-ubuntu-20.04 && ./qemu-system-aarch64 \
-append 'console=ttyAMA0,38400 keep_bootcon root=/dev/vda2' \
-kernel Image -no-acpi \
-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 \
-device virtio-net-device,netdev=vmnic
-device virtio-9p-device,fsdev=fsdev0,mount_tag=host
62 changes: 62 additions & 0 deletions tests/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# 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.

set -xe

# Default value for NEED_EXPANDED_MEM
: ${NEED_EXPANDED_MEM:=false}

# Define IMG_VERSION
IMG_VERSION="optee-qemuv8-4.2.0-ubuntu-24.04"

# Set IMG based on NEED_EXPANDED_MEM
if [ "$NEED_EXPANDED_MEM" = true ]; then
IMG="${IMG_VERSION}-expand-ta-memory"
else
IMG="$IMG_VERSION"
fi

# 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
run_in_qemu() {
screen -S qemu_screen -p 0 -X stuff "$1\n"
sleep 5
}

# Check if the image file exists locally
if [ ! -d "${IMG}" ]; then
echo "Image file '${IMG}' not found locally. Downloading from network."
download_image
else
echo "Image file '${IMG}' found locally."
fi

mkdir -p shared

# 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"
39 changes: 14 additions & 25 deletions tests/test_acipher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@

set -xe

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
# Include base script
source setup.sh

curl https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/optee-qemuv8-3.20.0-ubuntu-20.04.tar.gz | tar zxv
mkdir shared
# Copy TA and host binary
cp ../examples/acipher-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/acipher-rs/host/target/aarch64-unknown-linux-gnu/release/acipher-rs shared

screen -L -d -m -S qemu_screen ./optee-qemuv8.sh
sleep 30
screen -S qemu_screen -p 0 -X stuff "root\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "mkdir shared && mount -t 9p -o trans=virtio host shared && cd shared\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "cp *.ta /lib/optee_armtz/\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "./acipher-rs 256 teststring\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "^C"
sleep 5
# 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"

# 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
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
cat -v screenlog.0
cat -v /tmp/serial.log
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
47 changes: 18 additions & 29 deletions tests/test_aes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,30 @@

set -xe

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
# Include base script
source setup.sh

curl https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/optee-qemuv8-3.20.0-ubuntu-20.04.tar.gz | tar zxv
mkdir shared
# Copy TA and host binary
cp ../examples/aes-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/aes-rs/host/target/aarch64-unknown-linux-gnu/release/aes-rs shared

screen -L -d -m -S qemu_screen ./optee-qemuv8.sh
sleep 30
screen -S qemu_screen -p 0 -X stuff "root\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "mkdir shared && mount -t 9p -o trans=virtio host shared && cd shared\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "cp *.ta /lib/optee_armtz/\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "./aes-rs\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "^C"
sleep 5
# 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"

# 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
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
cat -v screenlog.0
cat -v /tmp/serial.log
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
37 changes: 13 additions & 24 deletions tests/test_authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@

set -xe

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
# Include base script
source setup.sh

curl https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/optee-qemuv8-3.20.0-ubuntu-20.04.tar.gz | tar zxv
mkdir shared
# Copy TA and host binary
cp ../examples/authentication-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/authentication-rs/host/target/aarch64-unknown-linux-gnu/release/authentication-rs shared

screen -L -d -m -S qemu_screen ./optee-qemuv8.sh
sleep 30
screen -S qemu_screen -p 0 -X stuff "root\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "mkdir shared && mount -t 9p -o trans=virtio host shared && cd shared\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "cp *.ta /lib/optee_armtz/\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "./authentication-rs\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "^C"
sleep 5
# 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"

# Script specific checks
{
grep -q "Clear text and decoded text match" screenlog.0 &&
grep -q "Success" screenlog.0
grep -q "Clear text and decoded text match" screenlog.0 &&
grep -q "Success" screenlog.0
} || {
cat -v screenlog.0
cat -v /tmp/serial.log
cat -v screenlog.0
cat -v /tmp/serial.log
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
51 changes: 20 additions & 31 deletions tests/test_big_int.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,33 @@

set -xe

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
# Include base script
source setup.sh

curl https://nightlies.apache.org/teaclave/teaclave-trustzone-sdk/optee-qemuv8-3.20.0-ubuntu-20.04.tar.gz | tar zxv
mkdir shared
# Copy TA and host binary
cp ../examples/big_int-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/big_int-rs/host/target/aarch64-unknown-linux-gnu/release/big_int-rs shared

screen -L -d -m -S qemu_screen ./optee-qemuv8.sh
sleep 30
screen -S qemu_screen -p 0 -X stuff "root\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "mkdir shared && mount -t 9p -o trans=virtio host shared && cd shared\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "cp *.ta /lib/optee_armtz/\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "./big_int-rs\n"
sleep 5
screen -S qemu_screen -p 0 -X stuff "^C"
sleep 5
# 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"

# 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
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
cat -v screenlog.0
cat -v /tmp/serial.log
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
Loading

0 comments on commit 9cc63e4

Please sign in to comment.