17ec681f3Smrg#!/bin/sh
27ec681f3Smrg
37ec681f3Smrgset -ex
47ec681f3Smrg
57ec681f3SmrgINSTALL=$(realpath -s "$PWD"/install)
67ec681f3SmrgMINIO_ARGS="--credentials=/tmp/.minio_credentials"
77ec681f3Smrg
87ec681f3SmrgRESULTS=$(realpath -s "$PWD"/results)
97ec681f3Smrgmkdir -p "$RESULTS"
107ec681f3Smrg
117ec681f3Smrg# Set up the driver environment.
127ec681f3Smrg# Modifiying here directly LD_LIBRARY_PATH may cause problems when
137ec681f3Smrg# using a command wrapper. Hence, we will just set it when running the
147ec681f3Smrg# command.
157ec681f3Smrgexport __LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INSTALL/lib/"
167ec681f3Smrg
177ec681f3Smrg# Sanity check to ensure that our environment is sufficient to make our tests
187ec681f3Smrg# run against the Mesa built by CI, rather than any installed distro version.
197ec681f3SmrgMESA_VERSION=$(head -1 "$INSTALL/VERSION" | sed 's/\./\\./g')
207ec681f3Smrg
217ec681f3Smrgprint_red() {
227ec681f3Smrg    RED='\033[0;31m'
237ec681f3Smrg    NC='\033[0m' # No Color
247ec681f3Smrg    printf "${RED}"
257ec681f3Smrg    "$@"
267ec681f3Smrg    printf "${NC}"
277ec681f3Smrg}
287ec681f3Smrg
297ec681f3Smrg# wrapper to supress +x to avoid spamming the log
307ec681f3Smrgquiet() {
317ec681f3Smrg    set +x
327ec681f3Smrg    "$@"
337ec681f3Smrg    set -x
347ec681f3Smrg}
357ec681f3Smrg
367ec681f3Smrgif [ "$VK_DRIVER" ]; then
377ec681f3Smrg
387ec681f3Smrg    ### VULKAN ###
397ec681f3Smrg
407ec681f3Smrg    # Set the Vulkan driver to use.
417ec681f3Smrg    export VK_ICD_FILENAMES="$INSTALL/share/vulkan/icd.d/${VK_DRIVER}_icd.x86_64.json"
427ec681f3Smrg
437ec681f3Smrg    if [ "x$PIGLIT_PROFILES" = "xreplay" ]; then
447ec681f3Smrg        # Set environment for Wine.
457ec681f3Smrg        export WINEDEBUG="-all"
467ec681f3Smrg        export WINEPREFIX="/dxvk-wine64"
477ec681f3Smrg        export WINEESYNC=1
487ec681f3Smrg
497ec681f3Smrg        # Set environment for DXVK.
507ec681f3Smrg        export DXVK_LOG_LEVEL="none"
517ec681f3Smrg        export DXVK_STATE_CACHE=0
527ec681f3Smrg
537ec681f3Smrg        # Set environment for gfxreconstruct executables.
547ec681f3Smrg        export PATH="/gfxreconstruct/build/bin:$PATH"
557ec681f3Smrg    fi
567ec681f3Smrg
577ec681f3Smrg    SANITY_MESA_VERSION_CMD="vulkaninfo"
587ec681f3Smrg
597ec681f3Smrg    HANG_DETECTION_CMD="/parallel-deqp-runner/build/bin/hang-detection"
607ec681f3Smrg
617ec681f3Smrg
627ec681f3Smrg    # Set up the Window System Interface (WSI)
637ec681f3Smrg
647ec681f3Smrg    if [ ${TEST_START_XORG:-0} -eq 1 ]; then
657ec681f3Smrg        "$INSTALL"/common/start-x.sh "$INSTALL"
667ec681f3Smrg        export DISPLAY=:0
677ec681f3Smrg    else
687ec681f3Smrg        # Run vulkan against the host's running X server (xvfb doesn't
697ec681f3Smrg        # have DRI3 support).
707ec681f3Smrg        # Set the DISPLAY env variable in each gitlab-runner's
717ec681f3Smrg        # configuration file:
727ec681f3Smrg        # https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section
737ec681f3Smrg        quiet printf "%s%s\n" "Running against the hosts' X server. " \
747ec681f3Smrg              "DISPLAY is \"$DISPLAY\"."
757ec681f3Smrg    fi
767ec681f3Smrgelse
777ec681f3Smrg
787ec681f3Smrg    ### GL/ES ###
797ec681f3Smrg
807ec681f3Smrg    if [ "x$PIGLIT_PROFILES" = "xreplay" ]; then
817ec681f3Smrg        # Set environment for apitrace executable.
827ec681f3Smrg        export PATH="/apitrace/build:$PATH"
837ec681f3Smrg
847ec681f3Smrg        # Our rootfs may not have "less", which apitrace uses during
857ec681f3Smrg        # apitrace dump
867ec681f3Smrg        export PAGER=cat
877ec681f3Smrg    fi
887ec681f3Smrg
897ec681f3Smrg    SANITY_MESA_VERSION_CMD="wflinfo"
907ec681f3Smrg
917ec681f3Smrg    HANG_DETECTION_CMD=""
927ec681f3Smrg
937ec681f3Smrg
947ec681f3Smrg    # Set up the platform windowing system.
957ec681f3Smrg
967ec681f3Smrg    if [ "x$EGL_PLATFORM" = "xsurfaceless" ]; then
977ec681f3Smrg
987ec681f3Smrg        # Use the surfaceless EGL platform.
997ec681f3Smrg        export DISPLAY=
1007ec681f3Smrg        export WAFFLE_PLATFORM="surfaceless_egl"
1017ec681f3Smrg
1027ec681f3Smrg        SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform surfaceless_egl --api gles2"
1037ec681f3Smrg
1047ec681f3Smrg        if [ "x$GALLIUM_DRIVER" = "xvirpipe" ]; then
1057ec681f3Smrg            # piglit is to use virpipe, and virgl_test_server llvmpipe
1067ec681f3Smrg            export GALLIUM_DRIVER="$GALLIUM_DRIVER"
1077ec681f3Smrg
1087ec681f3Smrg            LD_LIBRARY_PATH="$__LD_LIBRARY_PATH" \
1097ec681f3Smrg            GALLIUM_DRIVER=llvmpipe \
1107ec681f3Smrg            GALLIVM_PERF="nopt" \
1117ec681f3Smrg            VTEST_USE_EGL_SURFACELESS=1 \
1127ec681f3Smrg            VTEST_USE_GLES=1 \
1137ec681f3Smrg            virgl_test_server >"$RESULTS"/vtest-log.txt 2>&1 &
1147ec681f3Smrg
1157ec681f3Smrg            sleep 1
1167ec681f3Smrg        fi
1177ec681f3Smrg    elif [ "x$PIGLIT_PLATFORM" = "xgbm" ]; then
1187ec681f3Smrg        SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform gbm --api gl"
1197ec681f3Smrg    elif [ "x$PIGLIT_PLATFORM" = "xmixed_glx_egl" ]; then
1207ec681f3Smrg        # It is assumed that you have already brought up your X server before
1217ec681f3Smrg        # calling this script.
1227ec681f3Smrg        SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform glx --api gl"
1237ec681f3Smrg    else
1247ec681f3Smrg        SANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD --platform glx --api gl --profile core"
1257ec681f3Smrg        RUN_CMD_WRAPPER="xvfb-run --server-args=\"-noreset\" sh -c"
1267ec681f3Smrg    fi
1277ec681f3Smrgfi
1287ec681f3Smrg
1297ec681f3Smrgif [ "$ZINK_USE_LAVAPIPE" ]; then
1307ec681f3Smrg    export VK_ICD_FILENAMES="$INSTALL/share/vulkan/icd.d/lvp_icd.x86_64.json"
1317ec681f3Smrgfi
1327ec681f3Smrg
1337ec681f3Smrg# If the job is parallel at the  gitlab job level, will take the corresponding
1347ec681f3Smrg# fraction of the caselist.
1357ec681f3Smrgif [ -n "$CI_NODE_INDEX" ]; then
1367ec681f3Smrg
1377ec681f3Smrg    if [ "$PIGLIT_PROFILES" != "${PIGLIT_PROFILES% *}" ]; then
1387ec681f3Smrg        FAILURE_MESSAGE=$(printf "%s" "Can't parallelize piglit with multiple profiles")
1397ec681f3Smrg        quiet print_red printf "%s\n" "$FAILURE_MESSAGE"
1407ec681f3Smrg        exit 1
1417ec681f3Smrg    fi
1427ec681f3Smrg
1437ec681f3Smrg    USE_CASELIST=1
1447ec681f3Smrgfi
1457ec681f3Smrg
1467ec681f3Smrgreplay_minio_upload_images() {
1477ec681f3Smrg    find "$RESULTS/$__PREFIX" -type f -name "*.png" -printf "%P\n" \
1487ec681f3Smrg        | while read -r line; do
1497ec681f3Smrg
1507ec681f3Smrg        __TRACE="${line%-*-*}"
1517ec681f3Smrg        if grep -q "^$__PREFIX/$__TRACE: pass$" ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.orig"; then
1527ec681f3Smrg            if [ "x$CI_PROJECT_PATH" != "x$FDO_UPSTREAM_REPO" ]; then
1537ec681f3Smrg                continue
1547ec681f3Smrg            fi
1557ec681f3Smrg            __MINIO_PATH="$PIGLIT_REPLAY_REFERENCE_IMAGES_BASE"
1567ec681f3Smrg            __DESTINATION_FILE_PATH="${line##*-}"
1577ec681f3Smrg            if wget -q --method=HEAD "https://${__MINIO_PATH}/${__DESTINATION_FILE_PATH}" 2>/dev/null; then
1587ec681f3Smrg                continue
1597ec681f3Smrg            fi
1607ec681f3Smrg        else
1617ec681f3Smrg            __MINIO_PATH="$JOB_ARTIFACTS_BASE"
1627ec681f3Smrg            __DESTINATION_FILE_PATH="$__MINIO_TRACES_PREFIX/${line##*-}"
1637ec681f3Smrg        fi
1647ec681f3Smrg
1657ec681f3Smrg        ci-fairy minio cp $MINIO_ARGS "$RESULTS/$__PREFIX/$line" \
1667ec681f3Smrg            "minio://${__MINIO_PATH}/${__DESTINATION_FILE_PATH}"
1677ec681f3Smrg    done
1687ec681f3Smrg}
1697ec681f3Smrg
1707ec681f3SmrgSANITY_MESA_VERSION_CMD="$SANITY_MESA_VERSION_CMD | tee /tmp/version.txt | grep \"Mesa $MESA_VERSION\(\s\|$\)\""
1717ec681f3Smrg
1727ec681f3Smrgif [ -d results ]; then
1737ec681f3Smrg    cd results && rm -rf ..?* .[!.]* *
1747ec681f3Smrgfi
1757ec681f3Smrgcd /piglit
1767ec681f3Smrg
1777ec681f3Smrgif [ -n "$USE_CASELIST" ]; then
1787ec681f3Smrg    PIGLIT_TESTS=$(printf "%s" "$PIGLIT_TESTS")
1797ec681f3Smrg    PIGLIT_GENTESTS="./piglit print-cmd $PIGLIT_TESTS $PIGLIT_PROFILES --format \"{name}\" > /tmp/case-list.txt"
1807ec681f3Smrg    RUN_GENTESTS="export LD_LIBRARY_PATH=$__LD_LIBRARY_PATH; $PIGLIT_GENTESTS"
1817ec681f3Smrg
1827ec681f3Smrg    eval $RUN_GENTESTS
1837ec681f3Smrg
1847ec681f3Smrg    sed -ni $CI_NODE_INDEX~$CI_NODE_TOTAL"p" /tmp/case-list.txt
1857ec681f3Smrg
1867ec681f3Smrg    PIGLIT_TESTS="--test-list /tmp/case-list.txt"
1877ec681f3Smrgfi
1887ec681f3Smrg
1897ec681f3SmrgPIGLIT_OPTIONS=$(printf "%s" "$PIGLIT_OPTIONS")
1907ec681f3Smrg
1917ec681f3SmrgPIGLIT_TESTS=$(printf "%s" "$PIGLIT_TESTS")
1927ec681f3Smrg
1937ec681f3SmrgPIGLIT_CMD="./piglit run --timeout 300 -j${FDO_CI_CONCURRENT:-4} $PIGLIT_OPTIONS $PIGLIT_TESTS $PIGLIT_PROFILES "$(/usr/bin/printf "%q" "$RESULTS")
1947ec681f3Smrg
1957ec681f3SmrgRUN_CMD="export LD_LIBRARY_PATH=$__LD_LIBRARY_PATH; $SANITY_MESA_VERSION_CMD && $HANG_DETECTION_CMD $PIGLIT_CMD"
1967ec681f3Smrg
1977ec681f3Smrgif [ "$RUN_CMD_WRAPPER" ]; then
1987ec681f3Smrg    RUN_CMD="set +e; $RUN_CMD_WRAPPER "$(/usr/bin/printf "%q" "$RUN_CMD")"; set -e"
1997ec681f3Smrgfi
2007ec681f3Smrg
2017ec681f3SmrgFAILURE_MESSAGE=$(printf "%s" "Unexpected change in results:")
2027ec681f3Smrg
2037ec681f3Smrgif [ "x$PIGLIT_PROFILES" = "xreplay" ] \
2047ec681f3Smrg       && [ ${PIGLIT_REPLAY_UPLOAD_TO_MINIO:-0} -eq 1 ]; then
2057ec681f3Smrg    ci-fairy minio login $MINIO_ARGS $CI_JOB_JWT
2067ec681f3Smrgfi
2077ec681f3Smrg
2087ec681f3Smrgeval $RUN_CMD
2097ec681f3Smrg
2107ec681f3Smrgif [ $? -ne 0 ]; then
2117ec681f3Smrg    printf "%s\n" "Found $(cat /tmp/version.txt), expected $MESA_VERSION"
2127ec681f3Smrgfi
2137ec681f3Smrg
2147ec681f3SmrgARTIFACTS_BASE_URL="https://${CI_PROJECT_ROOT_NAMESPACE}.${CI_PAGES_DOMAIN}/-/${CI_PROJECT_NAME}/-/jobs/${CI_JOB_ID}/artifacts"
2157ec681f3Smrg
2167ec681f3Smrgif [ ${PIGLIT_JUNIT_RESULTS:-0} -eq 1 ]; then
2177ec681f3Smrg    ./piglit summary aggregate "$RESULTS" -o junit.xml
2187ec681f3Smrg    FAILURE_MESSAGE=$(printf "${FAILURE_MESSAGE}\n%s" "Check the JUnit report for failures at: ${ARTIFACTS_BASE_URL}/results/junit.xml")
2197ec681f3Smrgfi
2207ec681f3Smrg
2217ec681f3SmrgPIGLIT_RESULTS="${PIGLIT_RESULTS:-$PIGLIT_PROFILES}"
2227ec681f3SmrgRESULTSFILE="$RESULTS/$PIGLIT_RESULTS.txt"
2237ec681f3Smrgmkdir -p .gitlab-ci/piglit
2247ec681f3Smrg./piglit summary console "$RESULTS"/results.json.bz2 \
2257ec681f3Smrg    | tee ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.orig" \
2267ec681f3Smrg    | head -n -1 | grep -v ": pass" \
2277ec681f3Smrg    | sed '/^summary:/Q' \
2287ec681f3Smrg    > $RESULTSFILE
2297ec681f3Smrg
2307ec681f3Smrgif [ "x$PIGLIT_PROFILES" = "xreplay" ] \
2317ec681f3Smrg       && [ ${PIGLIT_REPLAY_UPLOAD_TO_MINIO:-0} -eq 1 ]; then
2327ec681f3Smrg
2337ec681f3Smrg    __PREFIX="trace/$PIGLIT_REPLAY_DEVICE_NAME"
2347ec681f3Smrg    __MINIO_PATH="$PIGLIT_REPLAY_ARTIFACTS_BASE_URL"
2357ec681f3Smrg    __MINIO_TRACES_PREFIX="traces"
2367ec681f3Smrg
2377ec681f3Smrg    if [ "x$PIGLIT_REPLAY_SUBCOMMAND" != "xprofile" ]; then
2387ec681f3Smrg        quiet replay_minio_upload_images
2397ec681f3Smrg    fi
2407ec681f3Smrgfi
2417ec681f3Smrg
2427ec681f3Smrgif [ -n "$USE_CASELIST" ]; then
2437ec681f3Smrg    # Just filter the expected results based on the tests that were actually
2447ec681f3Smrg    # executed, and switch to the version with no summary
2457ec681f3Smrg    cat ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.orig" | sed '/^summary:/Q' | rev \
2467ec681f3Smrg        | cut -f2- -d: | rev | sed "s/$/:/g" > /tmp/executed.txt
2477ec681f3Smrg
2487ec681f3Smrg    grep -F -f /tmp/executed.txt "$INSTALL/$PIGLIT_RESULTS.txt" \
2497ec681f3Smrg       > ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.baseline" || true
2507ec681f3Smrgelif [ -f "$INSTALL/$PIGLIT_RESULTS.txt" ]; then
2517ec681f3Smrg    cp "$INSTALL/$PIGLIT_RESULTS.txt" \
2527ec681f3Smrg       ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.baseline"
2537ec681f3Smrgelse
2547ec681f3Smrg    touch ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.baseline"
2557ec681f3Smrgfi
2567ec681f3Smrg
2577ec681f3Smrgif diff -q ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.baseline" $RESULTSFILE; then
2587ec681f3Smrg    exit 0
2597ec681f3Smrgfi
2607ec681f3Smrg
2617ec681f3Smrg./piglit summary html --exclude-details=pass \
2627ec681f3Smrg"$RESULTS"/summary "$RESULTS"/results.json.bz2
2637ec681f3Smrg
2647ec681f3Smrgif [ "x$PIGLIT_PROFILES" = "xreplay" ]; then
2657ec681f3Smrgfind "$RESULTS"/summary -type f -name "*.html" -print0 \
2667ec681f3Smrg        | xargs -0 sed -i 's%<img src="file://'"${RESULTS}"'.*-\([0-9a-f]*\)\.png%<img src="https://'"${JOB_ARTIFACTS_BASE}"'/traces/\1.png%g'
2677ec681f3Smrgfind "$RESULTS"/summary -type f -name "*.html" -print0 \
2687ec681f3Smrg        | xargs -0 sed -i 's%<img src="file://%<img src="https://'"${PIGLIT_REPLAY_REFERENCE_IMAGES_BASE}"'/%g'
2697ec681f3Smrgfi
2707ec681f3Smrg
2717ec681f3SmrgFAILURE_MESSAGE=$(printf "${FAILURE_MESSAGE}\n%s" "Check the HTML summary for problems at: ${ARTIFACTS_BASE_URL}/results/summary/problems.html")
2727ec681f3Smrg
2737ec681f3Smrgquiet print_red printf "%s\n" "$FAILURE_MESSAGE"
2747ec681f3Smrgquiet diff --color=always -u ".gitlab-ci/piglit/$PIGLIT_RESULTS.txt.baseline" $RESULTSFILE
2757ec681f3Smrgexit 1
276