2023-05-21 06:47:05 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC2086 # we want word splitting
|
2022-02-09 04:48:39 +08:00
|
|
|
set -e
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2022-05-11 05:44:07 +08:00
|
|
|
# If run outside of a deqp-runner invoction (e.g. piglit trace replay), then act
|
|
|
|
# the same as the first thread in its threadpool.
|
|
|
|
THREAD=${DEQP_RUNNER_THREAD:-0}
|
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
#
|
|
|
|
# Helper to generate CIDs for virtio-vsock based communication with processes
|
|
|
|
# running inside crosvm guests.
|
|
|
|
#
|
|
|
|
# A CID is a 32-bit Context Identifier to be assigned to a crosvm instance
|
|
|
|
# and must be unique across the host system. For this purpose, let's take
|
2022-03-01 03:26:31 +08:00
|
|
|
# the least significant 25 bits from CI_JOB_ID as a base and generate a 7-bit
|
|
|
|
# prefix number to handle up to 128 concurrent crosvm instances per job runner.
|
2022-02-09 04:48:39 +08:00
|
|
|
#
|
|
|
|
# As a result, the following variables are set:
|
|
|
|
# - VSOCK_CID: the crosvm unique CID to be passed as a run argument
|
|
|
|
#
|
|
|
|
# - VSOCK_STDOUT, VSOCK_STDERR: the port numbers the guest should accept
|
|
|
|
# vsock connections on in order to transfer output messages
|
|
|
|
#
|
2022-05-12 01:13:23 +08:00
|
|
|
# - VM_TEMP_DIR: the temporary directory path used to pass additional
|
2022-02-09 04:48:39 +08:00
|
|
|
# context data towards the guest
|
|
|
|
#
|
|
|
|
set_vsock_context() {
|
|
|
|
[ -n "${CI_JOB_ID}" ] || {
|
|
|
|
echo "Missing or unset CI_JOB_ID env variable" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-05-12 01:13:23 +08:00
|
|
|
VM_TEMP_DIR="/tmp-vm.${THREAD}"
|
2022-05-11 05:48:28 +08:00
|
|
|
# Clear out any leftover files from a previous run.
|
|
|
|
rm -rf $VM_TEMP_DIR
|
2022-05-12 01:13:23 +08:00
|
|
|
mkdir $VM_TEMP_DIR || return 1
|
2022-02-09 04:48:39 +08:00
|
|
|
|
2023-05-21 06:47:05 +08:00
|
|
|
VSOCK_CID=$(((CI_JOB_ID & 0x1ffffff) | ((THREAD & 0x7f) << 25)))
|
2022-02-09 04:48:39 +08:00
|
|
|
VSOCK_STDOUT=5001
|
|
|
|
VSOCK_STDERR=5002
|
2022-03-01 03:26:31 +08:00
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
return 0
|
|
|
|
}
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2021-09-08 13:52:58 +08:00
|
|
|
# The dEQP binary needs to run from the directory it's in
|
2022-01-05 05:15:19 +08:00
|
|
|
if [ -n "${1##*.sh}" ] && [ -z "${1##*"deqp"*}" ]; then
|
2022-02-09 04:48:39 +08:00
|
|
|
DEQP_BIN_DIR=$(dirname "$1")
|
|
|
|
export DEQP_BIN_DIR
|
2021-09-08 13:52:58 +08:00
|
|
|
fi
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2022-05-11 05:48:28 +08:00
|
|
|
VM_SOCKET=crosvm-${THREAD}.sock
|
|
|
|
|
|
|
|
# Terminate any existing crosvm, if a previous invocation of this shell script
|
|
|
|
# was terminated due to timeouts. This "vm stop" may fail if the crosvm died
|
|
|
|
# without cleaning itself up.
|
|
|
|
if [ -e $VM_SOCKET ]; then
|
2022-09-06 22:48:04 +08:00
|
|
|
crosvm stop $VM_SOCKET || true
|
2022-05-11 05:48:28 +08:00
|
|
|
# Wait for socats from that invocation to drain
|
2022-09-06 22:48:04 +08:00
|
|
|
sleep 5
|
|
|
|
rm -rf $VM_SOCKET || true
|
2022-05-11 05:48:28 +08:00
|
|
|
fi
|
2022-02-09 04:48:39 +08:00
|
|
|
|
2022-05-11 05:48:28 +08:00
|
|
|
set_vsock_context || { echo "Could not generate crosvm vsock CID" >&2; exit 1; }
|
2022-02-09 04:48:39 +08:00
|
|
|
|
2022-01-15 05:43:08 +08:00
|
|
|
# Securely pass the current variables to the crosvm environment
|
|
|
|
echo "Variables passed through:"
|
2022-02-23 01:09:02 +08:00
|
|
|
SCRIPT_DIR=$(readlink -en "${0%/*}")
|
2022-05-12 01:13:23 +08:00
|
|
|
${SCRIPT_DIR}/common/generate-env.sh | tee ${VM_TEMP_DIR}/crosvm-env.sh
|
2023-05-21 06:47:05 +08:00
|
|
|
cp ${SCRIPT_DIR}/setup-test-env.sh ${VM_TEMP_DIR}/setup-test-env.sh
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
# Set the crosvm-script as the arguments of the current script
|
2023-03-03 21:20:19 +08:00
|
|
|
echo ". ${VM_TEMP_DIR}/setup-test-env.sh" > ${VM_TEMP_DIR}/crosvm-script.sh
|
|
|
|
echo "$@" >> ${VM_TEMP_DIR}/crosvm-script.sh
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2022-03-04 07:59:55 +08:00
|
|
|
# Setup networking
|
|
|
|
/usr/sbin/iptables-legacy -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
|
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
# Start background processes to receive output from guest
|
|
|
|
socat -u vsock-connect:${VSOCK_CID}:${VSOCK_STDERR},retry=200,interval=0.1 stderr &
|
|
|
|
socat -u vsock-connect:${VSOCK_CID}:${VSOCK_STDOUT},retry=200,interval=0.1 stdout &
|
2021-02-04 22:14:26 +08:00
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
# Prepare to start crosvm
|
|
|
|
unset DISPLAY
|
|
|
|
unset XDG_RUNTIME_DIR
|
|
|
|
|
|
|
|
CROSVM_KERN_ARGS="quiet console=null root=my_root rw rootfstype=virtiofs ip=192.168.30.2::192.168.30.1:255.255.255.0:crosvm:eth0"
|
2022-05-12 01:13:23 +08:00
|
|
|
CROSVM_KERN_ARGS="${CROSVM_KERN_ARGS} init=${SCRIPT_DIR}/crosvm-init.sh -- ${VSOCK_STDOUT} ${VSOCK_STDERR} ${VM_TEMP_DIR}"
|
2021-09-08 13:52:58 +08:00
|
|
|
|
2022-03-03 19:43:54 +08:00
|
|
|
[ "${CROSVM_GALLIUM_DRIVER}" = "llvmpipe" ] && \
|
|
|
|
CROSVM_LIBGL_ALWAYS_SOFTWARE=true || CROSVM_LIBGL_ALWAYS_SOFTWARE=false
|
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
set +e -x
|
2021-08-06 18:05:45 +08:00
|
|
|
|
2022-03-03 19:43:54 +08:00
|
|
|
# We aren't testing the host driver here, so we don't need to validate NIR on the host
|
|
|
|
NIR_DEBUG="novalidate" \
|
|
|
|
LIBGL_ALWAYS_SOFTWARE=${CROSVM_LIBGL_ALWAYS_SOFTWARE} \
|
|
|
|
GALLIUM_DRIVER=${CROSVM_GALLIUM_DRIVER} \
|
2021-10-25 15:29:07 +08:00
|
|
|
VK_ICD_FILENAMES=$CI_PROJECT_DIR/install/share/vulkan/icd.d/${CROSVM_VK_DRIVER}_icd.x86_64.json \
|
2022-09-20 08:16:23 +08:00
|
|
|
crosvm --no-syslog run \
|
2022-11-05 14:58:13 +08:00
|
|
|
--gpu "${CROSVM_GPU_ARGS}" --gpu-render-server "path=/usr/local/libexec/virgl_render_server" \
|
2023-03-04 02:38:34 +08:00
|
|
|
-m "${CROSVM_MEMORY:-4096}" -c "${CROSVM_CPU:-2}" --disable-sandbox \
|
2022-02-09 04:48:39 +08:00
|
|
|
--shared-dir /:my_root:type=fs:writeback=true:timeout=60:cache=always \
|
2023-05-07 21:36:51 +08:00
|
|
|
--net "host-ip=192.168.30.1,netmask=255.255.255.0,mac=AA:BB:CC:00:00:12" \
|
2022-05-11 05:48:28 +08:00
|
|
|
-s $VM_SOCKET \
|
2022-02-09 04:48:39 +08:00
|
|
|
--cid ${VSOCK_CID} -p "${CROSVM_KERN_ARGS}" \
|
2022-05-11 05:48:28 +08:00
|
|
|
/lava-files/${KERNEL_IMAGE_NAME:-bzImage} > ${VM_TEMP_DIR}/crosvm 2>&1
|
2022-02-09 04:48:39 +08:00
|
|
|
|
|
|
|
CROSVM_RET=$?
|
2022-03-04 07:59:55 +08:00
|
|
|
|
2022-02-09 04:48:39 +08:00
|
|
|
[ ${CROSVM_RET} -eq 0 ] && {
|
|
|
|
# The actual return code is the crosvm guest script's exit code
|
2022-05-12 01:13:23 +08:00
|
|
|
CROSVM_RET=$(cat ${VM_TEMP_DIR}/exit_code 2>/dev/null)
|
2022-02-09 04:48:39 +08:00
|
|
|
# Force error when the guest script's exit code is not available
|
|
|
|
CROSVM_RET=${CROSVM_RET:-1}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Show crosvm output on error to help with debugging
|
|
|
|
[ ${CROSVM_RET} -eq 0 ] || {
|
|
|
|
set +x
|
|
|
|
echo "Dumping crosvm output.." >&2
|
2022-05-12 01:13:23 +08:00
|
|
|
cat ${VM_TEMP_DIR}/crosvm >&2
|
2022-02-09 04:48:39 +08:00
|
|
|
set -x
|
|
|
|
}
|
|
|
|
|
|
|
|
exit ${CROSVM_RET}
|