This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-jsc.sh
executable file
·289 lines (256 loc) · 7.24 KB
/
test-jsc.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#! /bin/bash
# Runs JSC tests using an external buildroot toolchain
#
# Usage:
# test-jsc.sh [ --? | -h | --help ]
# [ --version]
# [ --timeout "..." ]
# [ --release | --debug ]
# [ --filter "..." ]
# [ --vms "..." ]
# [ --port "..." ]
# webkit-directory
# buildroot-path
#
PROGRAM=$(basename "$0")
VERSION=1.0
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# shellcheck source=./common.sh
source "${DIR}/common.sh"
usage()
{
cat <<EOF
Usage:
$PROGRAM
[ -h | --help | --? ] Show help and exit
[ --version ] Show version and exit
[ --timeout N ] Set timeout per test (default: set by run-javascriptcore-tests)
[ --release | --debug | --ra ] JSC test mode (default: release)
[ --vms N ] Number of vms to start for testing
[ --filter REGEX ] Filter for tests, passed unmodified to run-javascriptcore-tests
[ --port P ] Starting port for VMs (ports [P, P+N-1] need to be free
webkit-directory Directory with WebKit checkout
buildroot-directory Directory with Buildroot install
EOF
}
TIMEOUT=
N=
P=
MODEFLAG=
FILTER=
while test $# -gt 0
do
case $1 in
--version )
version "${PROGRAM}" "${VERSION}"
exit 0
;;
--help | -h | '--?' )
usage_and_exit 0
;;
--timeout )
shift
TIMEOUT=$1
;;
--release )
if [ -n "$MODEFLAG" ]; then
error "only one of --release, --debug, --ra allows"
fi
MODEFLAG=--release
;;
--debug )
if [ -n "$MODEFLAG" ]; then
error "only one of --release, --debug, --ra allows"
fi
MODEFLAG=--debug
;;
--ra )
if [ -n "$MODEFLAG" ]; then
error "only one of --release, --debug, --ra allows"
fi
MODEFLAG=--ra
;;
--vms )
shift
N=$1
;;
--port )
shift
P=$1
;;
--filter )
shift
FILTER=$1
;;
-*)
error "Unrecognized option: $1"
;;
*)
break
;;
esac
shift
done
# Argument and flag option checks
if [ -z "${P}" ]; then
error "need --port"
fi
if [ -z "${N}" ]; then
error "need --vms"
fi
if [ "$#" != "2" ]; then
error "expected two arguments, got $#"
fi
WEBKIT_PATH=$(realpath "$1")
BRPATH=$(realpath "$2")
FFLAG=()
if [[ -n "${FILTER}" ]]; then
FFLAG=(--filter "${FILTER}")
fi
# Tests a JSC installation using qemu-system
#
# To test we need to
# 1. Start N instances of qemu-system in the background and keep their PIDs
# 1.1 Copy the HDD image N times
# 1.2 Find N free ports
# 1.3 Start each of the qemu-system with a different HDD image on a different port
#
# 2. Create a remotes file with information from each machine
# 3. Run run-javascriptcore-tests passing in the remotes file
# 4. Kill each of the qemu-systems and remove the HDDs
TESTTMP_PATH="$(mktemp -d)"
QEMUIMG_PATH=$(find "${BRPATH}" -path "${BRPATH}"/build -prune -o -type f -name qemu-img -print)
QEMU_PATH=$(find "${BRPATH}" -path "${BRPATH}"/build -prune -o -type f -name 'qemu-system-*' -print)
ARCH=${QEMU_PATH##*-} # trim everything until the last - (dash)
HDD_PATH="${BRPATH}/images/rootfs.qcow2"
REMOTES_PATH="$(mktemp)"
if [[ "${ARCH}" != "arm" ]] && [[ "${ARCH}" != "mipsel" ]]; then
error "unrecognized arch: ${ARCH}"
fi
progress "Using emulator binary ${QEMU_PATH} for the ${ARCH} architecture"
declare -a IMAGES
declare -a PORTS
declare -a PIDS
# Assign image paths for each worker
setup_images() {
for i in $(seq 1 "${N}")
do
local p
p="${TESTTMP_PATH}/rootfs-${i}.qcow2"
progress "Creating image for machine ${i} at ${p}"
"${QEMUIMG_PATH}" create -q -f qcow2 -b "${HDD_PATH}" "${p}"
IMAGES[${i}]=$p
done
}
# Assign free port numbers for each worker
setup_ports() {
for i in $(seq 1 "${N}")
do
local port
port=$(( P + i ))
if lsof -i -P -n | grep LISTEN | grep -q ":${port}"; then
error "Port ${port} is not free to use"
fi
PORTS[${i}]="${port}"
done
}
setup_images
setup_ports
# Start qemu-system and store pids in PIDS array
for i in $(seq 1 "${N}")
do
if [[ "${ARCH}" == "arm" ]]; then
${QEMU_PATH} -M vexpress-a9 \
-smp 4 \
-m 1G \
-kernel "${BRPATH}/images/zImage" \
-dtb "${BRPATH}/images/vexpress-v2p-ca9.dtb" \
-append "console=ttyAMA0,115200 rootwait root=/dev/mmcblk0" \
-net nic,model=lan9118 \
-nographic \
-serial none \
-monitor none \
-net user,hostfwd=tcp::${PORTS[${i}]}-:22 \
-drive format=qcow2,if=sd,file="${IMAGES[${i}]}" &
elif [[ "${ARCH}" == "mipsel" ]]; then
${QEMU_PATH} -M malta \
-m 1G \
-kernel "${BRPATH}/images/vmlinux" \
-append "nokaslr root=/dev/hda" \
-net nic \
-nographic \
-serial none \
-monitor none \
-net user,hostfwd=tcp::${PORTS[${i}]}-:22 \
-drive format=qcow2,file="${IMAGES[${i}]}" &
fi
PIDS[${i}]=$!
progress "Starting virtual machine with pid ${PIDS[${i}]} listening to ssh on port ${PORTS[${i}]}"
done
# Wait until we can communicate with the machines
progress "Waiting for machines to boot..."
sleep 5
for i in $(seq 1 "$N"); do
progress "Trying to reach machine ${i}"
port=${PORTS[${i}]}
retries=3
while [[ $retries -gt 0 ]]
do
if ! ssh -p "$port" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no jsc@localhost true; then
progress "FAILED ${i}"
retries=$(( retries - 1 ))
sleep 20
else
progress "SUCCESS ${i}"
break
fi
done
if [[ $retries == 0 ]]; then
for k in $(seq 1 "$N"); do
kill ${PIDS[${k}]}
done
error "can't reach machine $i"
fi
done
# Create json file with information about remotes
progress "Creating remotes file $REMOTES_PATH"
echo '{"remotes": [' >> "$REMOTES_PATH"
for i in $(seq 1 "$N"); do
{
echo -n '{"name": "virtual'
echo -n "${i}"
echo -n '", "address": "jsc@localhost:'
echo -n ${PORTS[${i}]}
echo -n '", "remoteDirectory": "/home/jsc"}'
if [[ "$i" != "$N" ]]; then
echo ','
fi
} >> "$REMOTES_PATH"
done
echo '] }' >> "$REMOTES_PATH"
progress "running tests with output redirected to stdout"
# Setup cross-ldd
TOOLCHAINFILE=$(findtoolchainfile "${BRPATH}")
if [[ -z "${TOOLCHAINFILE}" ]]; then
error "no toolchain file available"
fi
ENVVARS=$(mktemp)
"${DIR}/ldd-scripts/cmake-toolchain-vars" --prefix=XLDD_ "${TOOLCHAINFILE}" > "${ENVVARS}"
source "${ENVVARS}"
rm "${ENVVARS}"
export PATH=${DIR}/ldd-scripts:${PATH}
# Run tests through run-javascriptcore-tests
if [ -n "${TIMEOUT}" ]; then
export JSCTEST_timeout="${TIMEOUT}"
fi
"${WEBKIT_PATH}"/Tools/Scripts/run-javascriptcore-tests --ldd "${DIR}/ldd-scripts/xldd-wrapper" --no-build --no-fail-fast "${MODEFLAG}" --memory-limited --remote-config-file "${REMOTES_PATH}" --no-testmasm --no-testair --no-testb3 --no-testdfg --no-testapi --jsc-only "${FFLAG[@]}" 2>&1
# Killall qemu systems and clean up HDDs
for i in $(seq 1 "${N}"); do
progress "Cleaning up machine ${i}"
kill ${PIDS[${i}]}
done
progress "Removing temporary remotes file ${REMOTES_PATH}"
rm "${REMOTES_PATH}"
progress "Removing temporary path ${TESTTMP_PATH}"
rm -R "${TESTTMP_PATH}"
progress "Testing finished successfully"