1 | #!/usr/bin/env bash
|
---|
2 | # shellcheck disable=SC1091 # The relative paths in this file only become valid at runtime.
|
---|
3 | # shellcheck disable=SC2086 # we want word splitting
|
---|
4 | set -e
|
---|
5 |
|
---|
6 | VSOCK_STDOUT=$1
|
---|
7 | VSOCK_STDERR=$2
|
---|
8 | VM_TEMP_DIR=$3
|
---|
9 |
|
---|
10 | mount -t proc none /proc
|
---|
11 | mount -t sysfs none /sys
|
---|
12 | mkdir -p /dev/pts
|
---|
13 | mount -t devpts devpts /dev/pts
|
---|
14 | mkdir /dev/shm
|
---|
15 | mount -t tmpfs -o noexec,nodev,nosuid tmpfs /dev/shm
|
---|
16 | mount -t tmpfs tmpfs /tmp
|
---|
17 |
|
---|
18 | . ${VM_TEMP_DIR}/crosvm-env.sh
|
---|
19 | . ${VM_TEMP_DIR}/setup-test-env.sh
|
---|
20 |
|
---|
21 | # .gitlab-ci.yml script variable is using relative paths to install directory,
|
---|
22 | # so change to that dir before running `crosvm-script`
|
---|
23 | cd "${CI_PROJECT_DIR}"
|
---|
24 |
|
---|
25 | # The exception is the dEQP binary, as it needs to run from its own directory
|
---|
26 | [ -z "${DEQP_BIN_DIR}" ] || cd "${DEQP_BIN_DIR}"
|
---|
27 |
|
---|
28 | # Use a FIFO to collect relevant error messages
|
---|
29 | STDERR_FIFO=/tmp/crosvm-stderr.fifo
|
---|
30 | mkfifo -m 600 ${STDERR_FIFO}
|
---|
31 |
|
---|
32 | dmesg --level crit,err,warn -w > ${STDERR_FIFO} &
|
---|
33 | DMESG_PID=$!
|
---|
34 |
|
---|
35 | # Transfer the errors and crosvm-script output via a pair of virtio-vsocks
|
---|
36 | socat -d -u pipe:${STDERR_FIFO} vsock-listen:${VSOCK_STDERR} &
|
---|
37 | socat -d -U vsock-listen:${VSOCK_STDOUT} \
|
---|
38 | system:"stdbuf -eL bash ${VM_TEMP_DIR}/crosvm-script.sh 2> ${STDERR_FIFO}; echo \$? > ${VM_TEMP_DIR}/exit_code",nofork
|
---|
39 |
|
---|
40 | kill ${DMESG_PID}
|
---|
41 | wait
|
---|
42 |
|
---|
43 | sync
|
---|
44 | poweroff -d -n -f || true
|
---|
45 |
|
---|
46 | sleep 1 # Just in case init would exit before the kernel shuts down the VM
|
---|