xref: /linux/drivers/gpu/drm/ci/lava-submit.sh (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1550b8265SVignesh Raman#!/usr/bin/env bash
20119c894STomeu Vizoso# SPDX-License-Identifier: MIT
3550b8265SVignesh Raman# shellcheck disable=SC2086 # we want word splitting
4550b8265SVignesh Raman# shellcheck disable=SC1091 # paths only become valid at runtime
50119c894STomeu Vizoso
6550b8265SVignesh Raman# If we run in the fork (not from mesa or Marge-bot), reuse mainline kernel and rootfs, if exist.
7550b8265SVignesh Raman_check_artifact_path() {
8550b8265SVignesh Raman	_url="https://${1}/${2}"
9550b8265SVignesh Raman	if curl -s -o /dev/null -I -L -f --retry 4 --retry-delay 15 "${_url}"; then
10550b8265SVignesh Raman		echo -n "${_url}"
110119c894STomeu Vizoso	fi
12550b8265SVignesh Raman}
13550b8265SVignesh Raman
14550b8265SVignesh Ramanget_path_to_artifact() {
15550b8265SVignesh Raman	_mainline_artifact="$(_check_artifact_path ${BASE_SYSTEM_MAINLINE_HOST_PATH} ${1})"
16550b8265SVignesh Raman	if [ -n "${_mainline_artifact}" ]; then
17550b8265SVignesh Raman		echo -n "${_mainline_artifact}"
18550b8265SVignesh Raman		return
19550b8265SVignesh Raman	fi
20550b8265SVignesh Raman	_fork_artifact="$(_check_artifact_path ${BASE_SYSTEM_FORK_HOST_PATH} ${1})"
21550b8265SVignesh Raman	if [ -n "${_fork_artifact}" ]; then
22550b8265SVignesh Raman		echo -n "${_fork_artifact}"
23550b8265SVignesh Raman		return
24550b8265SVignesh Raman	fi
25550b8265SVignesh Raman	set +x
26550b8265SVignesh Raman	error "Sorry, I couldn't find a viable built path for ${1} in either mainline or a fork." >&2
27550b8265SVignesh Raman	echo "" >&2
28550b8265SVignesh Raman	echo "If you're working on CI, this probably means that you're missing a dependency:" >&2
29550b8265SVignesh Raman	echo "this job ran ahead of the job which was supposed to upload that artifact." >&2
30550b8265SVignesh Raman	echo "" >&2
31550b8265SVignesh Raman	echo "If you aren't working on CI, please ping @mesa/ci-helpers to see if we can help." >&2
32550b8265SVignesh Raman	echo "" >&2
33550b8265SVignesh Raman	echo "This job is going to fail, because I can't find the resources I need. Sorry." >&2
34550b8265SVignesh Raman	set -x
35550b8265SVignesh Raman	exit 1
36550b8265SVignesh Raman}
37550b8265SVignesh Raman
38550b8265SVignesh Raman. "${SCRIPTS_DIR}/setup-test-env.sh"
39550b8265SVignesh Raman
40550b8265SVignesh Ramansection_start prepare_rootfs "Preparing root filesystem"
41550b8265SVignesh Raman
42550b8265SVignesh Ramanset -ex
43550b8265SVignesh Raman
44550b8265SVignesh RamanROOTFS_URL="$(get_path_to_artifact lava-rootfs.tar.zst)"
45550b8265SVignesh Raman[ $? != 1 ] || exit 1
46550b8265SVignesh Raman
470119c894STomeu Vizosorm -rf results
480119c894STomeu Vizosomkdir -p results/job-rootfs-overlay/
490119c894STomeu Vizoso
500119c894STomeu Vizosoartifacts/ci-common/export-gitlab-job-env-for-dut.sh \
51a8bd38e0SVignesh Raman    > results/job-rootfs-overlay/set-job-env-vars.sh
52a8bd38e0SVignesh Ramancp artifacts/ci-common/init-*.sh results/job-rootfs-overlay/
530119c894STomeu Vizosocp "$SCRIPTS_DIR"/setup-test-env.sh results/job-rootfs-overlay/
540119c894STomeu Vizoso
550119c894STomeu Vizosotar zcf job-rootfs-overlay.tar.gz -C results/job-rootfs-overlay/ .
560119c894STomeu Vizosoci-fairy s3cp --token-file "${S3_JWT_FILE}" job-rootfs-overlay.tar.gz "https://${JOB_ROOTFS_OVERLAY_PATH}"
57*07a5ebfeSVignesh Raman
580119c894STomeu Vizoso# Prepare env vars for upload.
59550b8265SVignesh Ramansection_switch variables "Environment variables passed through to device:"
60550b8265SVignesh Ramancat results/job-rootfs-overlay/set-job-env-vars.sh
61550b8265SVignesh Raman
62550b8265SVignesh Ramansection_switch lava_submit "Submitting job for scheduling"
63550b8265SVignesh Raman
64550b8265SVignesh Ramantouch results/lava.log
650119c894STomeu Vizosotail -f results/lava.log &
660119c894STomeu Vizoso# Ensure that we are printing the commands that are being executed,
670119c894STomeu Vizoso# making it easier to debug the job in case it fails.
68550b8265SVignesh Ramanset -x
69550b8265SVignesh RamanPYTHONPATH=artifacts/ artifacts/lava/lava_job_submitter.py \
70550b8265SVignesh Raman	--farm "${FARM}" \
71550b8265SVignesh Raman	--device-type "${DEVICE_TYPE}" \
720119c894STomeu Vizoso	--boot-method "${BOOT_METHOD}" \
730119c894STomeu Vizoso	--job-timeout-min $((CI_JOB_TIMEOUT/60 - 5)) \
74550b8265SVignesh Raman	--dump-yaml \
752b126e06SHelen Koike	--pipeline-info "$CI_JOB_NAME: $CI_PIPELINE_URL on $CI_COMMIT_REF_NAME ${CI_NODE_INDEX}/${CI_NODE_TOTAL}" \
76550b8265SVignesh Raman	--rootfs-url "${ROOTFS_URL}" \
770119c894STomeu Vizoso	--kernel-url-prefix "https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}" \
780119c894STomeu Vizoso	--kernel-external "${EXTERNAL_KERNEL_TAG}" \
79cc806b74SVignesh Raman	--first-stage-init artifacts/ci-common/init-stage1.sh \
800119c894STomeu Vizoso	--dtb-filename "${DTB}" \
810119c894STomeu Vizoso	--jwt-file "${S3_JWT_FILE}" \
820119c894STomeu Vizoso	--kernel-image-name "${KERNEL_IMAGE_NAME}" \
830119c894STomeu Vizoso	--kernel-image-type "${KERNEL_IMAGE_TYPE}" \
840119c894STomeu Vizoso	--visibility-group "${VISIBILITY_GROUP}" \
850119c894STomeu Vizoso	--lava-tags "${LAVA_TAGS}" \
860119c894STomeu Vizoso	--mesa-job-name "$CI_JOB_NAME" \
87550b8265SVignesh Raman	--structured-log-file "results/lava_job_detail.json" \
88550b8265SVignesh Raman	--ssh-client-image "${LAVA_SSH_CLIENT_IMAGE}" \
89550b8265SVignesh Raman	--project-name "${CI_PROJECT_NAME}" \
90550b8265SVignesh Raman	--starting-section "${CURRENT_SECTION}" \
91550b8265SVignesh Raman	--job-submitted-at "${CI_JOB_STARTED_AT}" \
92550b8265SVignesh Raman	- append-overlay \
93550b8265SVignesh Raman		--name=kernel-build \
94550b8265SVignesh Raman		--url="${FDO_HTTP_CACHE_URI:-}https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/kernel-files.tar.zst" \
95550b8265SVignesh Raman		--compression=zstd \
96550b8265SVignesh Raman		--path="${CI_PROJECT_DIR}" \
97550b8265SVignesh Raman		--format=tar \
98550b8265SVignesh Raman	- append-overlay \
99550b8265SVignesh Raman		--name=job-overlay \
100550b8265SVignesh Raman		--url="https://${JOB_ROOTFS_OVERLAY_PATH}" \
101550b8265SVignesh Raman		--compression=gz \
102550b8265SVignesh Raman		--path="/" \
1030119c894STomeu Vizoso		--format=tar \
104	- submit \
105	>> results/lava.log
106