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.
Similar changes on master branch: [1].

[1] apache@b05173f

Signed-off-by: Yuan Zhuang <[email protected]>
  • Loading branch information
DemesneGH committed May 9, 2024
1 parent d1c94b1 commit 07801e8
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 275 deletions.
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
29 changes: 9 additions & 20 deletions tests/test_aes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@

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 &&
Expand All @@ -54,6 +45,4 @@ sleep 5
false
}

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

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
Expand All @@ -50,6 +41,4 @@ sleep 5
false
}

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

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 &&
Expand All @@ -57,6 +48,4 @@ sleep 5
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
29 changes: 9 additions & 20 deletions tests/test_diffie_hellman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@

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/diffie_hellman-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/diffie_hellman-rs/host/target/aarch64-unknown-linux-gnu/release/diffie_hellman-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 "./diffie_hellman-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 "./diffie_hellman-rs\n"
run_in_qemu "^C"

# Script specific checks
{
grep -q "get key [0|1] pair as public: \[.*], private: \[.*]" screenlog.0 &&
grep -q "Derived share key as \[.*]" screenlog.0 &&
Expand All @@ -51,6 +42,4 @@ sleep 5
false
}

rm -rf screenlog.0
rm -rf optee-qemuv8-3.20.0-ubuntu-20.04
rm -rf shared
rm screenlog.0
29 changes: 9 additions & 20 deletions tests/test_digest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@

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/digest-rs/ta/target/aarch64-unknown-linux-gnu/release/*.ta shared
cp ../examples/digest-rs/host/target/aarch64-unknown-linux-gnu/release/digest-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 "./digest-rs message1 message2\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 "./digest-rs message1 message2\n"
run_in_qemu "^C"

# Script specific checks
{
grep -q "Get message hash as:" screenlog.0 &&
grep -q "Success" screenlog.0
Expand All @@ -50,6 +41,4 @@ sleep 5
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 07801e8

Please sign in to comment.