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/time-rs/ta/target/aarch64-unknown-optee-trustzone/release/*.ta shared
29cp ../examples/time-rs/host/target/aarch64-unknown-linux-gnu/release/time-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 "./time-rs\n"
40sleep 5
41screen -S qemu_screen -p 0 -X stuff "^C"
42sleep 5
43
44{
45	grep -q "Success" screenlog.0 &&
46	grep -q "\[+] Get REE time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log &&
47	grep -q "\[+] Now wait 1 second in TEE" /tmp/serial.log &&
48	grep -q "\[+] Get system time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log &&
49	grep -q "\[+] After set the TA time 5 seconds ahead of system time, new TA time (second: [0-9]*, millisecond: [0-9]*)" /tmp/serial.log
50} || {
51	cat -v screenlog.0
52	cat -v /tmp/serial.log
53        false
54}
55
56rm -rf screenlog.0
57rm -rf optee-qemuv8-3.14.0-ubuntu-20.04
58rm -rf shared
59