blob: 2cd18ca0a5957e5d6576132e836dcee8b1e3b9e5 [file] [log] [blame]
Milosz Wasilewski10438582020-12-03 11:36:21 +00001#!/bin/bash
2
Leonardo Sandoval9f159802021-01-20 16:47:25 -06003set -xe
Milosz Wasilewski10438582020-12-03 11:36:21 +00004
Leonardo Sandoval5a335662021-03-26 19:57:40 -06005# Wait for the LAVA job to finished
6# By default, timeout at 5400 secs (1.5 hours) and monitor every 60 seconds
7wait_lava_job() {
8 local id=$1
9 local timeout="${2:-5400}"
10 local interval="${3:-60}"
11
12 (( t = timeout ))
13
14 while ((t > 0)); do
15 sleep $interval
16 resilient_cmd lavacli jobs show $id | tee "${WORKSPACE}/lava-progress.show"
17 if grep 'state.*: Finished' "${WORKSPACE}/lava-progress.show"; then
18 echo finished
19 return
20 fi
21 ((t -= interval))
22 done
23 echo timeout
24}
25
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060026# Run the given command passed through parameters, if fails, try
27# at most more N-times with a pause of M-seconds until success.
28resilient_cmd() {
29 local cmd="$*"
30 local max_wait=10
31 local sleep_body=2
32 local iter=0
33
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060034 while true; do
35 if ${cmd}; then
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060036 break
37 fi
38
39 sleep ${sleep_body}
40
41 iter=$(( iter + 1 ))
42 if [ ${iter} -ge ${max_wait} ]; then
43 return 1
44 fi
45 done
46 return 0
47}
48
Milosz Wasilewski10438582020-12-03 11:36:21 +000049ls -l ${WORKSPACE}
50
Leonardo Sandoval9f159802021-01-20 16:47:25 -060051if [ -n "${QA_SERVER_VERSION}" ]; then
52 if [ -n "${GERRIT_CHANGE_NUMBER}" ] && [ -n "${GERRIT_PATCHSET_NUMBER}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000053 curl \
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030054 --fail \
Milosz Wasilewski10438582020-12-03 11:36:21 +000055 --retry 4 \
56 -X POST \
57 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
Milosz Wasilewski10438582020-12-03 11:36:21 +000058 ${QA_SERVER}/api/createbuild/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}
59 fi
60
61 TESTJOB_ID=$(curl \
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030062 --fail \
Milosz Wasilewski10438582020-12-03 11:36:21 +000063 --retry 4 \
64 -X POST \
65 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
66 --form backend=${LAVA_SERVER} \
67 --form definition=@artefacts/debug/job.yaml \
68 ${QA_SERVER}/api/submitjob/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}/${DEVICE_TYPE})
Leonardo Sandoval9f159802021-01-20 16:47:25 -060069
70 if [ -n "${TESTJOB_ID}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000071 echo "TEST JOB URL: ${QA_SERVER}/testjob/${TESTJOB_ID} TEST JOB ID: ${TESTJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060072
Leonardo Sandoval9f159802021-01-20 16:47:25 -060073
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060074 # The below loop with a sleep is intentional: LAVA could be under heavy load so previous job creation can
75 # take 'some' time to get the right numeric LAVA JOB ID
76 renumber='^[0-9]+$'
77 LAVAJOB_ID="null"
78 iter=0
Chris Kayf1b3da92022-09-08 13:15:16 +010079 max_tries=120 # run retries for an hour
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060080 while ! [[ $LAVAJOB_ID =~ $renumber ]]; do
81 if [ $iter -eq $max_tries ] ; then
82 LAVAJOB_ID=''
83 break
84 fi
Leonardo Sandoval8267f432021-05-07 10:02:00 -050085 sleep 30
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030086 LAVAJOB_ID=$(curl --fail --retry 4 ${QA_SERVER}/api/testjobs/${TESTJOB_ID}/?fields=job_id)
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060087
88 # Get the job_id value (whatever it is)
89 LAVAJOB_ID=$(echo ${LAVAJOB_ID} | jq '.job_id')
90 LAVAJOB_ID="${LAVAJOB_ID//\"/}"
91
92 iter=$(( iter + 1 ))
93 done
Leonardo Sandoval9f159802021-01-20 16:47:25 -060094
95 # check that rest query at least get non-empty value
96 if [ -n "${LAVAJOB_ID}" ]; then
97
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060098 echo "LAVA URL: https://${LAVA_SERVER}/scheduler/job/${LAVAJOB_ID} LAVA JOB ID: ${LAVAJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060099
Leonardo Sandoval73d301a2021-02-12 13:42:55 -0600100 resilient_cmd lavacli identities add --username ${LAVA_USER} --token ${LAVA_TOKEN} --uri "https://${LAVA_SERVER}/RPC2" default
Leonardo Sandovala8078d62021-02-11 16:29:25 -0600101
Arthur She2586b5c2021-05-11 21:00:20 -0700102 wait_status="$(wait_lava_job ${LAVAJOB_ID})"
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600103
104 # if timeout on waiting for LAVA to complete, create an 'artificial' lava.log indicating
105 # job ID and timeout seconds
Leonardo Sandoval5a335662021-03-26 19:57:40 -0600106 if [ "${wait_status}" == "timeout" ]; then
107 echo "Stopped monitoring LAVA JOB ${LAVAJOB_ID}, likely stuck or timeout too short?" > "${WORKSPACE}/lava.log"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500108 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600109 else
Arthur She5fc74272021-03-26 21:24:34 -0700110 # Retrieve the test job plain log which is a yaml format file from LAVA
111 resilient_cmd lavacli jobs logs --raw ${LAVAJOB_ID} > "${WORKSPACE}/lava-raw.log"
112
113 # Split the UART messages to the corresponding log files
Leonardo Sandovale9450132021-04-19 13:51:11 -0500114 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/log-splitter.py "${WORKSPACE}/lava-raw.log"
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600115
Leonardo Sandoval5cf68e22021-07-16 12:23:20 -0500116 # Take possible code coverage trace data from the LAVA log
117 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/feedback-trace-splitter.sh \
118 ${WORKSPACE}/trusted-firmware-a \
119 ${WORKSPACE} \
120 ${WORKSPACE}/artefacts/debug/ \
121 ${TF_GERRIT_REFSPEC}
122
123 # Generate Code Coverate Report in case there are traces available
124 if find covtrace-*.log; then
Leonardo Sandoval8750d372021-09-06 18:14:40 -0500125 git clone ${QA_TOOLS_REPO} ${WORKSPACE}/qa-tools
Leonardo Sandoval5cf68e22021-07-16 12:23:20 -0500126 cd ${WORKSPACE}/qa-tools/coverage-tool/coverage-reporting
127 ./branch_coverage.sh \
128 --config ${WORKSPACE}/config_file.json \
129 --workspace ${WORKSPACE}/trusted-firmware-a \
130 --outdir ${WORKSPACE}/trace_report
131 find ${WORKSPACE}/trace_report
132 fi
133
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600134 # Fetch and store LAVA job result (1 failure, 0 success)
Arthur She1671e482022-06-06 22:19:38 -0700135 resilient_cmd lavacli results ${LAVAJOB_ID} | tee "${WORKSPACE}/lava.results"
136 if grep -q '\[fail\]' "${WORKSPACE}/lava.results"; then
Leonardo Sandovale9450132021-04-19 13:51:11 -0500137 exit 1
Arthur She1671e482022-06-06 22:19:38 -0700138 else
139 exit 0
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600140 fi
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600141 fi
142 else
143 echo "LAVA Job ID could not be obtained"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500144 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600145 fi
Milosz Wasilewski10438582020-12-03 11:36:21 +0000146 fi
147fi