1#!/usr/bin/env bash 2# shellcheck disable=SC2035 # FIXME glob 3# shellcheck disable=SC2086 # we want word splitting 4# shellcheck disable=SC1091 # paths only become valid at runtime 5 6. "${SCRIPTS_DIR}/setup-test-env.sh" 7 8section_start traces_prepare "traces: preparing test setup" 9 10set -ex 11 12# Our rootfs may not have "less", which apitrace uses during apitrace dump 13export PAGER=cat # FIXME: export everywhere 14 15INSTALL=$(realpath -s "$PWD"/install) 16S3_ARGS="--token-file ${S3_JWT_FILE}" 17 18export PIGLIT_REPLAY_DESCRIPTION_FILE="$INSTALL/$PIGLIT_TRACES_FILE" 19 20# FIXME: guess why /usr/local/bin is not included in all runners PATH. 21# Needed because yq and ci-fairy are installed there. 22PATH="/usr/local/bin:$PATH" 23 24if [ "$PIGLIT_REPLAY_SUBCOMMAND" = "profile" ]; then 25 yq -iY 'del(.traces[][] | select(.label[]? == "no-perf"))' \ 26 "$PIGLIT_REPLAY_DESCRIPTION_FILE" 27else 28 # keep the images for the later upload 29 export PIGLIT_REPLAY_EXTRA_ARGS="--keep-image ${PIGLIT_REPLAY_EXTRA_ARGS}" 30fi 31 32# Set up the environment. 33# Modifiying here directly LD_LIBRARY_PATH may cause problems when 34# using a command wrapper. Hence, we will just set it when running the 35# command. 36export __LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INSTALL/lib/" 37if [ -n "${VK_DRIVER}" ]; then 38 ARCH=$(uname -m) 39 export VK_DRIVER_FILES="$INSTALL/share/vulkan/icd.d/${VK_DRIVER}_icd.$ARCH.json" 40fi 41 42# Sanity check to ensure that our environment is sufficient to make our tests 43# run against the Mesa built by CI, rather than any installed distro version. 44MESA_VERSION=$(head -1 "$INSTALL/VERSION" | sed 's/\./\\./g') 45 46# wrapper to supress +x to avoid spamming the log 47quiet() { 48 set +x 49 "$@" 50 set -x 51} 52 53# Set environment for apitrace executable. 54export PATH="/apitrace/build:$PATH" 55 56echo "Version:" 57apitrace version 2>/dev/null || echo "apitrace not found (Linux)" 58 59SANITY_MESA_VERSION_CMD="wflinfo" 60 61HANG_DETECTION_CMD="" 62 63# Set up the platform windowing system. 64if [ "$EGL_PLATFORM" = "surfaceless" ]; then 65 # Use the surfaceless EGL platform. 66 export DISPLAY= 67 export WAFFLE_PLATFORM="surfaceless_egl" 68 69 SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform surfaceless_egl --api gles2" 70 71 if [ "$GALLIUM_DRIVER" = "virpipe" ]; then 72 # piglit is to use virpipe, and virgl_test_server llvmpipe 73 export GALLIUM_DRIVER="$GALLIUM_DRIVER" 74 75 LD_LIBRARY_PATH="$__LD_LIBRARY_PATH" \ 76 GALLIUM_DRIVER=llvmpipe \ 77 VTEST_USE_EGL_SURFACELESS=1 \ 78 VTEST_USE_GLES=1 \ 79 virgl_test_server >"$RESULTS_DIR"/vtest-log.txt 2>&1 & 80 81 sleep 1 82 fi 83elif [ "$PIGLIT_PLATFORM" = "gbm" ]; then 84 SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform gbm --api gl" 85elif [ "$PIGLIT_PLATFORM" = "mixed_glx_egl" ]; then 86 # It is assumed that you have already brought up your X server before 87 # calling this script. 88 SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform glx --api gl" 89else 90 SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform glx --api gl --profile core" 91 # copy-paste from init-stage2.sh, please update accordingly 92 { 93 WESTON_X11_SOCK="/tmp/.X11-unix/X0" 94 export WAYLAND_DISPLAY=wayland-0 95 export DISPLAY=:0 96 mkdir -p /tmp/.X11-unix 97 98 env \ 99 weston -Bheadless-backend.so --use-gl -Swayland-0 --xwayland --idle-time=0 & 100 101 while [ ! -S "$WESTON_X11_SOCK" ]; do sleep 1; done 102 } 103fi 104 105# If the job is parallel at the gitlab job level, will take the corresponding 106# fraction of the caselist. 107if [ -n "$CI_NODE_INDEX" ]; then 108 USE_CASELIST=1 109fi 110 111# shellcheck disable=SC2317 112replay_s3_upload_images() { 113 find "$RESULTS_DIR/$__PREFIX" -type f -name "*.png" -printf "%P\n" \ 114 | while read -r line; do 115 116 __TRACE="${line%-*-*}" 117 if grep -q "^$__PREFIX/$__TRACE: pass$" ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.orig"; then 118 if [ "x$CI_PROJECT_PATH" != "x$FDO_UPSTREAM_REPO" ]; then 119 continue 120 fi 121 __S3_PATH="$PIGLIT_REPLAY_REFERENCE_IMAGES_BASE" 122 __DESTINATION_FILE_PATH="${line##*-}" 123 if curl -L -s -I "https://${__S3_PATH}/${__DESTINATION_FILE_PATH}" | grep -q "content-type: application/octet-stream" 2>/dev/null; then 124 continue 125 fi 126 else 127 __S3_PATH="$JOB_ARTIFACTS_BASE" 128 __DESTINATION_FILE_PATH="$__S3_TRACES_PREFIX/${line##*-}" 129 fi 130 131 ci-fairy s3cp $S3_ARGS "$RESULTS_DIR/$__PREFIX/$line" \ 132 "https://${__S3_PATH}/${__DESTINATION_FILE_PATH}" 133 done 134} 135 136SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD | tee /tmp/version.txt | grep \"Mesa $MESA_VERSION\(\s\|$\)\"" 137 138cd $RESULTS_DIR && rm -rf ..?* .[!.]* * 139cd /piglit 140 141if [ -n "$USE_CASELIST" ]; then 142 PIGLIT_TESTS=$(printf "%s" "$PIGLIT_TESTS") 143 PIGLIT_GENTESTS="./piglit print-cmd $PIGLIT_TESTS replay --format \"{name}\" > /tmp/case-list.txt" 144 RUN_GENTESTS="export LD_LIBRARY_PATH=$__LD_LIBRARY_PATH; $PIGLIT_GENTESTS" 145 146 eval $RUN_GENTESTS 147 148 sed -ni $CI_NODE_INDEX~$CI_NODE_TOTAL"p" /tmp/case-list.txt 149 150 PIGLIT_TESTS="--test-list /tmp/case-list.txt" 151fi 152 153PIGLIT_OPTIONS=$(printf "%s" "$PIGLIT_OPTIONS") 154 155PIGLIT_TESTS=$(printf "%s" "$PIGLIT_TESTS") 156 157PIGLIT_CMD="./piglit run -l verbose --timeout 300 -j${FDO_CI_CONCURRENT:-4} $PIGLIT_OPTIONS $PIGLIT_TESTS replay "$(/usr/bin/printf "%q" "$RESULTS_DIR") 158 159RUN_CMD="export LD_LIBRARY_PATH=$__LD_LIBRARY_PATH; $SANITY_MESA_VERSION_CMD && $HANG_DETECTION_CMD $PIGLIT_CMD" 160 161# The replayer doesn't do any size or checksum verification for the traces in 162# the replayer db, so if we had to restart the system due to intermittent device 163# errors (or tried to cache replayer-db between runs, which would be nice to 164# have), you could get a corrupted local trace that would spuriously fail the 165# run. 166rm -rf replayer-db 167 168# ANGLE: download compiled ANGLE runtime and the compiled restricted traces (all-in-one package) 169if [ -n "$PIGLIT_REPLAY_ANGLE_TAG" ]; then 170 ARCH="amd64" 171 FILE="angle-bin-${ARCH}-${PIGLIT_REPLAY_ANGLE_TAG}.tar.zst" 172 ci-fairy s3cp $S3_ARGS "https://s3.freedesktop.org/mesa-tracie-private/${FILE}" "${FILE}" 173 mkdir -p replayer-db/angle 174 tar --zstd -xf ${FILE} -C replayer-db/angle/ 175fi 176 177PIGLIT_RESULTS="${PIGLIT_RESULTS:-replay}" 178RESULTSFILE="$RESULTS_DIR/$PIGLIT_RESULTS.txt" 179mkdir -p .gitlab-ci/piglit 180 181uncollapsed_section_switch traces "traces: run traces" 182 183if ! eval $RUN_CMD; 184then 185 error "Found $(cat /tmp/version.txt), expected $MESA_VERSION" 186fi 187 188 189./piglit summary aggregate "$RESULTS_DIR" -o junit.xml 190 191{ set +x; } 2>/dev/null 192./piglit summary console "$RESULTS_DIR"/results.json.bz2 \ 193 | tee ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.orig" \ 194 | head -n -1 | grep -v ": pass" \ 195 | sed '/^summary:/Q' \ 196 > $RESULTSFILE 197 198if [ -s $RESULTSFILE ]; then 199 error "Failures in traces:" 200 cat $RESULTSFILE 201 echo "Review the image changes and get the new checksums at: ${ARTIFACTS_BASE_URL}/results/summary/problems.html" 202 echo "If the new traces look correct to you, you can update the checksums" 203 echo "locally by running:" 204 echo " ./bin/ci/update_traces_checksum.sh" 205 echo "and resubmit this merge request." 206fi 207 208section_switch test_post_process "traces: post-processing test results" 209 210__PREFIX="trace/$PIGLIT_REPLAY_DEVICE_NAME" 211__S3_PATH="$PIGLIT_REPLAY_ARTIFACTS_BASE_URL" 212__S3_TRACES_PREFIX="traces" 213 214set -x 215 216if [ "$PIGLIT_REPLAY_SUBCOMMAND" != "profile" ]; then 217 quiet replay_s3_upload_images 218fi 219 220 221if [ ! -s $RESULTSFILE ]; then 222 rm -rf "${RESULTS_DIR:?}/${__PREFIX}" 223 { set +x; } 2>/dev/null 224 section_end test_post_process 225 exit 0 226fi 227 228./piglit summary html --exclude-details=pass \ 229"$RESULTS_DIR"/summary "$RESULTS_DIR"/results.json.bz2 230 231find "$RESULTS_DIR"/summary -type f -name "*.html" -print0 \ 232 | xargs -0 sed -i 's%<img src="file://'"${RESULTS}"'.*-\([0-9a-f]*\)\.png%<img src="https://'"${JOB_ARTIFACTS_BASE}"'/traces/\1.png%g' 233find "$RESULTS_DIR"/summary -type f -name "*.html" -print0 \ 234 | xargs -0 sed -i 's%<img src="file://%<img src="https://'"${PIGLIT_REPLAY_REFERENCE_IMAGES_BASE}"'/%g' 235 236section_end test_post_process 237 238exit 1 239