1#!/bin/sh 2 3set -e 4 5# If run outside of a deqp-runner invoction (e.g. piglit trace replay), then act 6# the same as the first thread in its threadpool. 7THREAD=${DEQP_RUNNER_THREAD:-0} 8 9# 10# Helper to generate CIDs for virtio-vsock based communication with processes 11# running inside crosvm guests. 12# 13# A CID is a 32-bit Context Identifier to be assigned to a crosvm instance 14# and must be unique across the host system. For this purpose, let's take 15# the least significant 25 bits from CI_JOB_ID as a base and generate a 7-bit 16# prefix number to handle up to 128 concurrent crosvm instances per job runner. 17# 18# As a result, the following variables are set: 19# - VSOCK_CID: the crosvm unique CID to be passed as a run argument 20# 21# - VSOCK_STDOUT, VSOCK_STDERR: the port numbers the guest should accept 22# vsock connections on in order to transfer output messages 23# 24# - VM_TEMP_DIR: the temporary directory path used to pass additional 25# context data towards the guest 26# 27set_vsock_context() { 28 [ -n "${CI_JOB_ID}" ] || { 29 echo "Missing or unset CI_JOB_ID env variable" >&2 30 exit 1 31 } 32 33 VM_TEMP_DIR="/tmp-vm.${THREAD}" 34 # Clear out any leftover files from a previous run. 35 rm -rf $VM_TEMP_DIR 36 mkdir $VM_TEMP_DIR || return 1 37 38 VSOCK_CID=$(((CI_JOB_ID & 0x1ffffff) | ((${THREAD} & 0x7f) << 25))) 39 VSOCK_STDOUT=5001 40 VSOCK_STDERR=5002 41 42 return 0 43} 44 45# The dEQP binary needs to run from the directory it's in 46if [ -n "${1##*.sh}" ] && [ -z "${1##*"deqp"*}" ]; then 47 DEQP_BIN_DIR=$(dirname "$1") 48 export DEQP_BIN_DIR 49fi 50 51VM_SOCKET=crosvm-${THREAD}.sock 52 53# Terminate any existing crosvm, if a previous invocation of this shell script 54# was terminated due to timeouts. This "vm stop" may fail if the crosvm died 55# without cleaning itself up. 56if [ -e $VM_SOCKET ]; then 57 crosvm stop $VM_SOCKET || rm -rf $VM_SOCKET 58 # Wait for socats from that invocation to drain 59 sleep 5 60fi 61 62set_vsock_context || { echo "Could not generate crosvm vsock CID" >&2; exit 1; } 63 64# Securely pass the current variables to the crosvm environment 65echo "Variables passed through:" 66SCRIPT_DIR=$(readlink -en "${0%/*}") 67${SCRIPT_DIR}/common/generate-env.sh | tee ${VM_TEMP_DIR}/crosvm-env.sh 68 69# Set the crosvm-script as the arguments of the current script 70echo "$@" > ${VM_TEMP_DIR}/crosvm-script.sh 71 72# Setup networking 73/usr/sbin/iptables-legacy -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE 74echo 1 > /proc/sys/net/ipv4/ip_forward 75 76# Start background processes to receive output from guest 77socat -u vsock-connect:${VSOCK_CID}:${VSOCK_STDERR},retry=200,interval=0.1 stderr & 78socat -u vsock-connect:${VSOCK_CID}:${VSOCK_STDOUT},retry=200,interval=0.1 stdout & 79 80# Prepare to start crosvm 81unset DISPLAY 82unset XDG_RUNTIME_DIR 83 84CROSVM_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" 85CROSVM_KERN_ARGS="${CROSVM_KERN_ARGS} init=${SCRIPT_DIR}/crosvm-init.sh -- ${VSOCK_STDOUT} ${VSOCK_STDERR} ${VM_TEMP_DIR}" 86 87[ "${CROSVM_GALLIUM_DRIVER}" = "llvmpipe" ] && \ 88 CROSVM_LIBGL_ALWAYS_SOFTWARE=true || CROSVM_LIBGL_ALWAYS_SOFTWARE=false 89 90set +e -x 91 92# We aren't testing the host driver here, so we don't need to validate NIR on the host 93NIR_DEBUG="novalidate" \ 94LIBGL_ALWAYS_SOFTWARE=${CROSVM_LIBGL_ALWAYS_SOFTWARE} \ 95GALLIUM_DRIVER=${CROSVM_GALLIUM_DRIVER} \ 96crosvm run \ 97 --gpu "${CROSVM_GPU_ARGS}" -m 4096 -c 2 --disable-sandbox \ 98 --shared-dir /:my_root:type=fs:writeback=true:timeout=60:cache=always \ 99 --host_ip "192.168.30.1" --netmask "255.255.255.0" --mac "AA:BB:CC:00:00:12" \ 100 -s $VM_SOCKET \ 101 --cid ${VSOCK_CID} -p "${CROSVM_KERN_ARGS}" \ 102 /lava-files/${KERNEL_IMAGE_NAME:-bzImage} > ${VM_TEMP_DIR}/crosvm 2>&1 103 104CROSVM_RET=$? 105 106[ ${CROSVM_RET} -eq 0 ] && { 107 # The actual return code is the crosvm guest script's exit code 108 CROSVM_RET=$(cat ${VM_TEMP_DIR}/exit_code 2>/dev/null) 109 # Force error when the guest script's exit code is not available 110 CROSVM_RET=${CROSVM_RET:-1} 111} 112 113# Show crosvm output on error to help with debugging 114[ ${CROSVM_RET} -eq 0 ] || { 115 set +x 116 echo "Dumping crosvm output.." >&2 117 cat ${VM_TEMP_DIR}/crosvm >&2 118 set -x 119} 120 121exit ${CROSVM_RET} 122