blob: 32dd819160c4aedd815504a87f955c9d27777387 [file] [log] [blame]
Gyorgy Szingba1095c2020-11-24 00:33:11 +01001#!/bin/bash
2#
Gyorgy Szing7ddb28a2023-01-17 15:55:36 +01003# Copyright (c) 2020-2023, Arm Limited and contributors. All rights reserved.
Gyorgy Szingba1095c2020-11-24 00:33:11 +01004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Exit with error if any command fails
9set -e
10
11# Read in user specific environment settings
12if [ -e user.env ]
13then
14 echo "Reding user specific settings from user.env"
15 source user.env
16fi
17
18# Default to non-verbose mode.
19VERBOSE=${VERBOSE:-0}
20
Imre Kisf9dda4a2022-01-18 18:54:15 +010021# Additional environment specific CMake flags
22CMAKE_EXTRA_FLAGS=${CMAKE_EXTRA_FLAGS:-""}
23
Gyorgy Szingba1095c2020-11-24 00:33:11 +010024# Get root of TS repo.
25TS_ROOT=${TS_ROOT:-$(git rev-parse --show-toplevel)}
26
27# Number of threads to use in parallel
28NUMBER_OF_PROCESSORS=${NUMBER_OF_PROCESSORS:-$(( $(nproc) * 2 )) }
29
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +010030# By default run as much as we can
31FAIL_FAST=${FAIL_FAST:-0}
32
Gyorgy Szing54071d92022-01-04 12:34:14 +010033# Global exit code.
34exit_code=0
35
Gyorgy Szingf24a03a2023-03-21 03:00:40 +010036# List of supported tests.
37test_list=(
38{% for config in data %}
39 "{{config.name}}"
40{% endfor %}
41)
42
Gyorgy Szingba1095c2020-11-24 00:33:11 +010043# Convert test name to build directory
44function name-to-bdir() {
45 printf "./build-%s" "$1"
46}
47
48# Wrap cmake to allow verbose vs non-verbose mode
49function _cmake() {
50 log_file=$1
51 shift
52 if [ "$VERBOSE" != "0" ]
53 then
54 cmake "$@" 2>&1 | tee -a "$log_file"
55 return ${PIPESTATUS[0]}
56 else
57 cmake "$@" >>"$log_file" 2>&1
58 fi
59}
60
61{% for config in data %}
62# Run build test "{{config.name}}"
63{{config.name}}() {
64 echo "##################################################################"
65 echo "########################## {{config.name}} started."
66
67 {% if config.os_id is defined %}
68 if [ "$OS_ID" != "{{config.os_id}}" ]
69 then
70 echo "Test case is not supported on this host."
Gyorgy Szing54071d92022-01-04 12:34:14 +010071 echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET"
Gyorgy Szingba1095c2020-11-24 00:33:11 +010072 echo "##################################################################"
73 return
74 fi
75 {% endif %}
76 b_dir=$(name-to-bdir "{{config.name}}")
77 log_file=$b_dir/build.log
78 rm -rf "$b_dir"
79 mkdir -p "$b_dir"
80
Gyorgy Szingb164e392021-09-04 01:51:57 +020081 if [ -n "$_ccache" ]
82 then
83 ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache
84 fi
85
Gyorgy Szing54071d92022-01-04 12:34:14 +010086 local retval=0
Gyorgy Szingba1095c2020-11-24 00:33:11 +010087
Gyorgy Szing54071d92022-01-04 12:34:14 +010088 # jinja2 is removing single newlines. Adding a comment stops this behavior.
Imre Kisf9dda4a2022-01-18 18:54:15 +010089 if _cmake "$log_file" -S {{config.src}} -B "$b_dir" $ccache_option {% for param in config.params %} "{{param}}" {% endfor %} ${CMAKE_EXTRA_FLAGS} #keep newline
Gyorgy Szingba1095c2020-11-24 00:33:11 +010090 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010091 if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose
Gyorgy Szingba1095c2020-11-24 00:33:11 +010092 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010093 if _cmake "$log_file" --install "$b_dir" --prefix ./install
94 then
95 echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET"
96 else
97 retval=$?
98 echo "For details see: $log_file"
99 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
100 fi
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100101 else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100102 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100103 echo "For details see: $log_file"
104 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
105 fi
106 else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100107 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100108 echo "For details see: $log_file"
109 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
110 fi
111 echo "##################################################################"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100112 return $retval
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100113}
114
115{% endfor %}
116
117# Clean intermediate files
118do_clean() {
119 {% for config in data %}
120 b_dir=$(name-to-bdir "{{config.name}}")
121 if [ -d "$b_dir" ]
122 then
123 echo "Removing $b_dir"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100124 rm -rf "$b_dir"
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100125 fi
126 {% endfor %}
127}
128
129# Print usage info
130do_help() {
131 cat <<END_HELP
132Build test runner
133=================
134
135Invocation::
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100136 ``$0 [<options>] [<command>]``
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100137
138The file "user.env" is sourced from the current directory. Use it to set
139environment specific defaults. For config variables see the start of this script
140and any "$<XXXX>" in the "params" array of any command in test_data.yaml
141Some variables to note
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100142 - VERBOSE : <0/1> make the script output more info.
143 VERBOSE=$VERBOSE
144 - TS_ROOT : Root directory of the TS repo.
145 TS_ROOT=$TS_ROOT
146 - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting
147 the number of parallel processes during build
148 NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS
149 - CMAKE_EXTRA_FLAGS: additional environment specific CMake flags
150 CMAKE_EXTRA_FLAGS=-DNEWLIB_LIBC_PATH=/path/to/newlib
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +0100151 - FAIL_FAST: <0/1> see -f
152 FAIL_FAST=$FAIL_FAST
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100153
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100154Options:
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +0100155 -f|--fail-fast
156 - exit after the first test failure
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100157 -p <regexp>
158 - filter out all test cases whose name is not matching regexp.
159 regexp is a regular expression understood by grep
160Commands:
161 "" - no command/default -> run all test cases
162 clean - remove build directories
163 help - print this text
164 <test case> - run the specified test. This can be specified multiple times
165 to allow running a list of tests.
166 available test cases $([ -n "$pattern" ] && echo "( matching '$pattern' )"):
167 $(echo "${test_list[@]}" | sed "s/ /\n /g")
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100168END_HELP
169}
170
171#################### Entry point ###################################
172
173OS_ID=$(uname -o )
174
175if [ -n $(which tput) -a -t ]
176then
Gyorgy Szing54071d92022-01-04 12:34:14 +0100177 COLOR_YELLOW=$(tput setaf 3)
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100178 COLOR_RESET=$(tput sgr0)
179 COLOR_RED=$(tput setaf 1)
180 COLOR_GREEN=$(tput setaf 2)
181else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100182 COLOR_YELLOW=
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100183 COLOR_RESET=
184 COLOR_RED=
185 COLOR_GREEN=
186fi
187
Gyorgy Szing7ddb28a2023-01-17 15:55:36 +0100188_ccache=$(which ccache 2>/dev/null) || true "never mind"
Gyorgy Szingb164e392021-09-04 01:51:57 +0200189
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100190process_commands() {
191 local exit_code=0
192 while true
193 do
194 case $1 in
195 {% for config in data %}
196 {{config.name}})
197 {{config.name}} || {
198 exit_code=$?
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +0100199 [ "$FAIL_FAST" -ne 0 ] && break
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100200 }
201 ;;
202 {% endfor %}
203 clean)
204 do_clean || {
205 exit_code=$?
206 break
207 }
208 ;;
209 help)
210 do_help
211 break
212 ;;
213 "")
214 for _test in "${test_list[@]}"
215 do
216 "$_test" || {
217 exit_code=$?
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +0100218 [ "$FAIL_FAST" -ne 0 ] && break
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100219 }
220 done
221 break
222 ;;
223 *)
224 echo "${COLOR_RED}Error: invalid command: $1 $COLOR_RESET"
225 do_help
226 exit_code=1
227 break
228 ;;
229 esac
230 shift
231 [ 0 -eq $# ] && break
232 done
233 return $exit_code
234}
235
236while true
237do
238 # parse options
239 case $1 in
240 -p)
241 shift
242 pattern=$1
243 if [ -z "$pattern" ]
244 then
245 echo "${COLOR_RED}Error: missing argument <search regexp>. $COLOR_RESET"
246 exit_code=1
247 break
248 else
249 readarray -t test_list < <(printf "%s\n" "${test_list[@]}" | grep -- "$pattern")
250 {% raw %}
251 [ 0 -eq ${#test_list[@]} ] && {
252 {% endraw %}
253 echo "${COLOR_RED}Error: -p <regexp> matches no tests. $COLOR_RESET"
254 exit_code=1
255 break
256 }
257 fi
258 ;;
Gyorgy Szinge1ccb2d2023-03-21 03:05:23 +0100259 --f|--fail-fast)
260 FAIL_FAST=1
261 ;;
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100262 *)
263 # parse commands
264 process_commands "$@" || exit_code=$?
265 break
266 ;;
267 esac
268 shift
269done
Gyorgy Szing54071d92022-01-04 12:34:14 +0100270
271exit $exit_code