-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.sh
executable file
·178 lines (150 loc) · 4.08 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
# Copyright 2019-2020 Unai Martinez-Corral <[email protected]>
#
# Licensed 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 -e
cd $(dirname $0)
export DOCKER_BUILDKIT=1
. ./utils.sh
TEST_RELEASE="v0.0.11-v7.1+dfsg-2--bpo11+3"
if [ -n "$1" ]; then
TEST_RELEASE="$1"
fi
echo "TEST_RELEASE: $TEST_RELEASE"
do_register () {
case "$QUS_JOB" in
[a-z]*)
print_start "Register qemu-user binfmt interpreters with register.sh"
sudo QEMU_BIN_DIR=$QEMU_BIN_DIR ./register.sh $@
;;
*)
print_start "Register qemu-user binfmt interpreters with aptman/qus:register"
QEMU_BIN_DIR=${QEMU_BIN_DIR:-/usr/bin}
docker run --rm --privileged \
-e "QEMU_BIN_DIR=$QEMU_BIN_DIR" \
-v "$QEMU_BIN_DIR:$QEMU_BIN_DIR" \
aptman/qus:register $@
esac
list
}
list () {
print_start "List binfmt interpreters"
sudo ./register.sh -l -- -t
}
get_static () {
print_start "Get qemu-aarch64-static"
if [ "$#" != "0" ]; then
dir="-C $1"
subin="$(command -v sudo)"
fi
curl -fsSL https://github.com/dbhi/qus/releases/download/$TEST_RELEASE/qemu-aarch64-static_amd64.tgz | $subin tar xvzf - $dir
}
apt_install () {
print_start "sudo apt-get install $@"
sudo apt update -y
sudo apt install -y $@
}
do_test () {
cmd="docker run --rm -tv $(pwd):/src $2 qus/test bash -c"
printf "$ANSI_BLUE> Test direct and explicit execution in a docker container$ANSI_NOCOLOR\n"
printf 'DIRECT: '; $cmd "/src/main"
printf 'EXPLICIT: '; $cmd "command -v $1 >/dev/null 2>&1 && $1 /src/main || echo '$1 not available'"
}
qus_test () {
if [ "$(docker images -q qus/test 2> /dev/null)" == "" ]; then
img="arm64v8/ubuntu:bionic"
print_start "Pull docker image $img and tag it as qus/test"
docker pull "$img"
docker tag "$img" qus/test
fi
if [ "$#" != "0" ]; then
q="$(basename $1)"
v="$(dirname $1)"
if [ "$v" = "." ]; then v="$(pwd)"; fi
do_test $q "-v=$v/$q:/usr/bin/$q"
else
do_test "qemu-aarch64-static"
fi
}
curl -fsSL https://github.com/dbhi/qus/releases/download/$TEST_RELEASE/test-aarch64 -o main
chmod +x main
case "$QUS_JOB" in
[fF])
get_static /usr/bin
do_register -s -- -p aarch64
qus_test
;;
[cC])
get_static
QEMU_BIN_DIR=$(pwd) do_register -s -- -p aarch64
qus_test
;;
[vV])
do_register -s -- aarch64
get_static
qus_test qemu-aarch64-static
;;
[iI])
do_register -s -- aarch64
print_start "Build arm64v8 docker image containing qemu-aarch64-static"
get_static
docker build -t qus/test . -f-<<EOF
FROM arm64v8/ubuntu:bionic
COPY ./qemu-aarch64-static /usr/bin
EOF
rm -rf qemu-aarch64-static
qus_test
;;
[dD])
do_register -- aarch64
print_start "Build amd64 docker image containing qemu-user"
docker build -t qus/test -<<EOF
FROM amd64/ubuntu:bionic
RUN apt update && apt install -y qemu-user
EOF
do_test qemu-aarch64
;;
s)
apt_install qemu-user-static
list
qus_test /usr/bin/qemu-aarch64-static
;;
[rR])
apt_install qemu-user-static
list
do_register -- -r
do_register -s -- -p aarch64
qus_test
;;
n)
apt_install qemu-user-binfmt
list
print_start "Test direct and explicit native execution"
printf 'DIRECT: '; ./main
printf 'EXPLICIT: '; qemu-aarch64 ./main
;;
[hH])
exit 1
# register -- -p
#
# pull_tmp "ubuntu:18.04"
# q="qemu-aarch64"
# #test $q -v=/usr/bin/$q:/usr/bin/$q
# do_test $q
;;
*)
print_start "Register and load qemu-aarch64-static with/from aptman/qus"
docker run --rm --privileged aptman/qus -s -- -p aarch64
qus_test
;;
esac