blob: 6ca6e344fb6680016d2ab4d72d8b769104cba65e [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
Paul Sokolovskya153b602022-10-12 20:50:05 +030018 # finished
19 return 0
Leonardo Sandoval5a335662021-03-26 19:57:40 -060020 fi
21 ((t -= interval))
22 done
Paul Sokolovskya153b602022-10-12 20:50:05 +030023 # timeout
24 return 1
Leonardo Sandoval5a335662021-03-26 19:57:40 -060025}
26
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060027# Run the given command passed through parameters, if fails, try
28# at most more N-times with a pause of M-seconds until success.
29resilient_cmd() {
30 local cmd="$*"
31 local max_wait=10
32 local sleep_body=2
33 local iter=0
34
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060035 while true; do
36 if ${cmd}; then
Leonardo Sandovaleb94e912021-01-29 12:23:59 -060037 break
38 fi
39
40 sleep ${sleep_body}
41
42 iter=$(( iter + 1 ))
43 if [ ${iter} -ge ${max_wait} ]; then
44 return 1
45 fi
46 done
47 return 0
48}
49
Milosz Wasilewski10438582020-12-03 11:36:21 +000050ls -l ${WORKSPACE}
51
Leonardo Sandoval9f159802021-01-20 16:47:25 -060052if [ -n "${QA_SERVER_VERSION}" ]; then
53 if [ -n "${GERRIT_CHANGE_NUMBER}" ] && [ -n "${GERRIT_PATCHSET_NUMBER}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000054 curl \
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030055 --fail \
Milosz Wasilewski10438582020-12-03 11:36:21 +000056 --retry 4 \
57 -X POST \
58 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
Milosz Wasilewski10438582020-12-03 11:36:21 +000059 ${QA_SERVER}/api/createbuild/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}
60 fi
61
62 TESTJOB_ID=$(curl \
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030063 --fail \
Milosz Wasilewski10438582020-12-03 11:36:21 +000064 --retry 4 \
65 -X POST \
66 --header "Auth-Token: ${QA_REPORTS_TOKEN}" \
67 --form backend=${LAVA_SERVER} \
Chris Kayf6ff4672022-11-03 13:09:44 +000068 --form definition=@artefacts-lava/job.yaml \
Milosz Wasilewski10438582020-12-03 11:36:21 +000069 ${QA_SERVER}/api/submitjob/${QA_SERVER_TEAM}/${QA_SERVER_PROJECT}/${QA_SERVER_VERSION}/${DEVICE_TYPE})
Leonardo Sandoval9f159802021-01-20 16:47:25 -060070
Arthur She2770cee2022-09-14 15:12:18 -070071 # SQUAD will send 400, curl error code 22, on bad test definition
72 if [ "$?" = "22" ]; then
73 echo "Bad test definition!!"
74 exit 1
75 fi
76
Leonardo Sandoval9f159802021-01-20 16:47:25 -060077 if [ -n "${TESTJOB_ID}" ]; then
Milosz Wasilewski10438582020-12-03 11:36:21 +000078 echo "TEST JOB URL: ${QA_SERVER}/testjob/${TESTJOB_ID} TEST JOB ID: ${TESTJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060079
Leonardo Sandoval9f159802021-01-20 16:47:25 -060080
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060081 # The below loop with a sleep is intentional: LAVA could be under heavy load so previous job creation can
82 # take 'some' time to get the right numeric LAVA JOB ID
83 renumber='^[0-9]+$'
84 LAVAJOB_ID="null"
85 iter=0
Chris Kayf1b3da92022-09-08 13:15:16 +010086 max_tries=120 # run retries for an hour
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060087 while ! [[ $LAVAJOB_ID =~ $renumber ]]; do
88 if [ $iter -eq $max_tries ] ; then
89 LAVAJOB_ID=''
90 break
91 fi
Leonardo Sandoval8267f432021-05-07 10:02:00 -050092 sleep 30
Paul Sokolovskya3ac1262022-07-08 16:03:48 +030093 LAVAJOB_ID=$(curl --fail --retry 4 ${QA_SERVER}/api/testjobs/${TESTJOB_ID}/?fields=job_id)
Leonardo Sandoval73d301a2021-02-12 13:42:55 -060094
95 # Get the job_id value (whatever it is)
96 LAVAJOB_ID=$(echo ${LAVAJOB_ID} | jq '.job_id')
97 LAVAJOB_ID="${LAVAJOB_ID//\"/}"
98
99 iter=$(( iter + 1 ))
100 done
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600101
102 # check that rest query at least get non-empty value
103 if [ -n "${LAVAJOB_ID}" ]; then
104
Leonardo Sandoval73d301a2021-02-12 13:42:55 -0600105 echo "LAVA URL: https://${LAVA_SERVER}/scheduler/job/${LAVAJOB_ID} LAVA JOB ID: ${LAVAJOB_ID}"
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600106
Leonardo Sandoval73d301a2021-02-12 13:42:55 -0600107 resilient_cmd lavacli identities add --username ${LAVA_USER} --token ${LAVA_TOKEN} --uri "https://${LAVA_SERVER}/RPC2" default
Leonardo Sandovala8078d62021-02-11 16:29:25 -0600108
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600109 # if timeout on waiting for LAVA to complete, create an 'artificial' lava.log indicating
110 # job ID and timeout seconds
Paul Sokolovskyebaf7482022-10-13 02:05:38 +0300111 if ! wait_lava_job ${LAVAJOB_ID}; then
Paul Sokolovskya153b602022-10-12 20:50:05 +0300112 echo "Stopped monitoring LAVA JOB ${LAVAJOB_ID}, likely stuck or timeout too short?" | tee "${WORKSPACE}/lava.log"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500113 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600114 else
Arthur She5fc74272021-03-26 21:24:34 -0700115 # Retrieve the test job plain log which is a yaml format file from LAVA
116 resilient_cmd lavacli jobs logs --raw ${LAVAJOB_ID} > "${WORKSPACE}/lava-raw.log"
117
118 # Split the UART messages to the corresponding log files
Leonardo Sandovale9450132021-04-19 13:51:11 -0500119 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/log-splitter.py "${WORKSPACE}/lava-raw.log"
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600120
Leonardo Sandoval5cf68e22021-07-16 12:23:20 -0500121 # Take possible code coverage trace data from the LAVA log
122 ${WORKSPACE}/tf-a-job-configs/tf-a-builder/feedback-trace-splitter.sh \
123 ${WORKSPACE}/trusted-firmware-a \
124 ${WORKSPACE} \
Chris Kayf6ff4672022-11-03 13:09:44 +0000125 ${WORKSPACE}/artefacts-lava/ \
Leonardo Sandoval5cf68e22021-07-16 12:23:20 -0500126 ${TF_GERRIT_REFSPEC}
127
128 # Generate Code Coverate Report in case there are traces available
129 if find covtrace-*.log; then
Leonardo Sandoval8750d372021-09-06 18:14:40 -0500130 git clone ${QA_TOOLS_REPO} ${WORKSPACE}/qa-tools
Leonardo Sandoval5cf68e22021-07-16 12:23:20 -0500131 cd ${WORKSPACE}/qa-tools/coverage-tool/coverage-reporting
132 ./branch_coverage.sh \
133 --config ${WORKSPACE}/config_file.json \
134 --workspace ${WORKSPACE}/trusted-firmware-a \
135 --outdir ${WORKSPACE}/trace_report
136 find ${WORKSPACE}/trace_report
137 fi
138
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600139 # Fetch and store LAVA job result (1 failure, 0 success)
Arthur She1671e482022-06-06 22:19:38 -0700140 resilient_cmd lavacli results ${LAVAJOB_ID} | tee "${WORKSPACE}/lava.results"
141 if grep -q '\[fail\]' "${WORKSPACE}/lava.results"; then
Leonardo Sandovale9450132021-04-19 13:51:11 -0500142 exit 1
Arthur She1671e482022-06-06 22:19:38 -0700143 else
144 exit 0
Leonardo Sandoval6ed62092021-03-09 09:32:05 -0600145 fi
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600146 fi
147 else
148 echo "LAVA Job ID could not be obtained"
Leonardo Sandovale9450132021-04-19 13:51:11 -0500149 exit 1
Leonardo Sandoval9f159802021-01-20 16:47:25 -0600150 fi
Milosz Wasilewski10438582020-12-03 11:36:21 +0000151 fi
152fi