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/udp_socket-rs/ta/target/aarch64-unknown-optee-trustzone/release/*.ta shared
29cp ../examples/udp_socket-rs/host/target/aarch64-unknown-linux-gnu/release/udp_socket-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 "./udp_socket-rs\n"
40sleep 5
41screen -S qemu_screen -p 0 -X stuff "^C"
42sleep 5
43
44{
45	grep -q "Success" screenlog.0
46} || {
47	cat -v screenlog.0
48	cat -v /tmp/serial.log
49        false
50}
51
52rm -rf screenlog.0
53rm -rf optee-qemuv8-3.14.0-ubuntu-20.04
54rm -rf shared
55