1#!/bin/bash
2
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements.  See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership.  The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License.  You may obtain a copy of the License at
10#
11#   http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied.  See the License for the
17# specific language governing permissions and limitations
18# under the License.
19
20set -xe
21
22rm -rf screenlog.0
23rm -rf optee-qemuv8-3.14.0-ubuntu-20.04
24rm -rf shared
25
26curl http://mesalock-linux.org/assets/optee-qemuv8-3.14.0-ubuntu-20.04.tar.gz | tar zxv
27mkdir shared
28cp ../examples/secure_storage-rs/ta/target/aarch64-unknown-optee-trustzone/release/*.ta shared
29cp ../examples/secure_storage-rs/host/target/aarch64-unknown-linux-gnu/release/secure_storage-rs shared
30
31screen -L -d -m -S qemu_screen ./optee-qemuv8.sh
32sleep 30
33screen -S qemu_screen -p 0 -X stuff "root\n"
34sleep 5
35screen -S qemu_screen -p 0 -X stuff "mkdir shared && mount -t 9p -o trans=virtio host shared && cd shared\n"
36sleep 5
37screen -S qemu_screen -p 0 -X stuff "cp *.ta /lib/optee_armtz/\n"
38sleep 5
39screen -S qemu_screen -p 0 -X stuff "./secure_storage-rs\n"
40sleep 5
41screen -S qemu_screen -p 0 -X stuff "^C"
42sleep 5
43
44{
45	grep -q "Test on object \"object#1\"" screenlog.0 &&
46	grep -q "\- Create and load object in the TA secure storage" screenlog.0 &&
47	grep -q "\- Read back the object" screenlog.0 &&
48	grep -q "\- Content read-out correctly" screenlog.0 &&
49	grep -q "\- Delete the object" screenlog.0 &&
50
51	grep -q "Test on object \"object#2\"" screenlog.0 &&
52	#miss the read correctly output
53	grep -Eq "\- Object not found in TA secure storage, create it|\- Object found in TA secure storage, delete it" screenlog.0 &&
54
55	grep -q "We're done, close and release TEE resources" screenlog.0
56} || {
57        cat -v screenlog.0
58        cat -v /tmp/serial.log
59        false
60}
61
62rm -rf screenlog.0
63rm -rf optee-qemuv8-3.14.0-ubuntu-20.04
64rm -rf shared
65