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/aes-rs/ta/target/aarch64-unknown-optee-trustzone/release/*.ta shared
29cp ../examples/aes-rs/host/target/aarch64-unknown-linux-gnu/release/aes-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 "./aes-rs\n"
40sleep 5
41screen -S qemu_screen -p 0 -X stuff "^C"
42sleep 5
43
44{
45	grep -q "Prepare encode operation" screenlog.0 &&
46	grep -q "Load key in TA" screenlog.0 &&
47	grep -q "Reset ciphering operation in TA (provides the initial vector)" screenlog.0 &&
48	grep -q "Encode buffer from TA" screenlog.0 &&
49	grep -q "Prepare decode operation" screenlog.0 &&
50	grep -q "Clear text and decoded text match" screenlog.0
51} || {
52	cat -v screenlog.0
53	cat -v /tmp/serial.log
54	false
55}
56
57rm -rf screenlog.0
58rm -rf optee-qemuv8-3.14.0-ubuntu-20.04
59rm -rf shared
60