blob: 50b7debd3833da0758f1f8fae748b43b09497453 [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 Szing54071d92022-01-04 12:34:14 +010030# Global exit code.
31exit_code=0
32
Gyorgy Szingf24a03a2023-03-21 03:00:40 +010033# List of supported tests.
34test_list=(
35{% for config in data %}
36 "{{config.name}}"
37{% endfor %}
38)
39
Gyorgy Szingba1095c2020-11-24 00:33:11 +010040# Convert test name to build directory
41function name-to-bdir() {
42 printf "./build-%s" "$1"
43}
44
45# Wrap cmake to allow verbose vs non-verbose mode
46function _cmake() {
47 log_file=$1
48 shift
49 if [ "$VERBOSE" != "0" ]
50 then
51 cmake "$@" 2>&1 | tee -a "$log_file"
52 return ${PIPESTATUS[0]}
53 else
54 cmake "$@" >>"$log_file" 2>&1
55 fi
56}
57
58{% for config in data %}
59# Run build test "{{config.name}}"
60{{config.name}}() {
61 echo "##################################################################"
62 echo "########################## {{config.name}} started."
63
64 {% if config.os_id is defined %}
65 if [ "$OS_ID" != "{{config.os_id}}" ]
66 then
67 echo "Test case is not supported on this host."
Gyorgy Szing54071d92022-01-04 12:34:14 +010068 echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET"
Gyorgy Szingba1095c2020-11-24 00:33:11 +010069 echo "##################################################################"
70 return
71 fi
72 {% endif %}
73 b_dir=$(name-to-bdir "{{config.name}}")
74 log_file=$b_dir/build.log
75 rm -rf "$b_dir"
76 mkdir -p "$b_dir"
77
Gyorgy Szingb164e392021-09-04 01:51:57 +020078 if [ -n "$_ccache" ]
79 then
80 ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache
81 fi
82
Gyorgy Szing54071d92022-01-04 12:34:14 +010083 local retval=0
Gyorgy Szingba1095c2020-11-24 00:33:11 +010084
Gyorgy Szing54071d92022-01-04 12:34:14 +010085 # jinja2 is removing single newlines. Adding a comment stops this behavior.
Imre Kisf9dda4a2022-01-18 18:54:15 +010086 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 +010087 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010088 if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose
Gyorgy Szingba1095c2020-11-24 00:33:11 +010089 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010090 if _cmake "$log_file" --install "$b_dir" --prefix ./install
91 then
92 echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET"
93 else
94 retval=$?
95 echo "For details see: $log_file"
96 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
97 fi
Gyorgy Szingba1095c2020-11-24 00:33:11 +010098 else
Gyorgy Szing54071d92022-01-04 12:34:14 +010099 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100100 echo "For details see: $log_file"
101 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
102 fi
103 else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100104 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100105 echo "For details see: $log_file"
106 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
107 fi
108 echo "##################################################################"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100109 return $retval
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100110}
111
112{% endfor %}
113
114# Clean intermediate files
115do_clean() {
116 {% for config in data %}
117 b_dir=$(name-to-bdir "{{config.name}}")
118 if [ -d "$b_dir" ]
119 then
120 echo "Removing $b_dir"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100121 rm -rf "$b_dir"
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100122 fi
123 {% endfor %}
124}
125
126# Print usage info
127do_help() {
128 cat <<END_HELP
129Build test runner
130=================
131
132Invocation::
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100133 ``$0 [<options>] [<command>]``
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100134
135The file "user.env" is sourced from the current directory. Use it to set
136environment specific defaults. For config variables see the start of this script
137and any "$<XXXX>" in the "params" array of any command in test_data.yaml
138Some variables to note
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100139 - VERBOSE : <0/1> make the script output more info.
140 VERBOSE=$VERBOSE
141 - TS_ROOT : Root directory of the TS repo.
142 TS_ROOT=$TS_ROOT
143 - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting
144 the number of parallel processes during build
145 NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS
146 - CMAKE_EXTRA_FLAGS: additional environment specific CMake flags
147 CMAKE_EXTRA_FLAGS=-DNEWLIB_LIBC_PATH=/path/to/newlib
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100148
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100149Options:
150 -p <regexp>
151 - filter out all test cases whose name is not matching regexp.
152 regexp is a regular expression understood by grep
153Commands:
154 "" - no command/default -> run all test cases
155 clean - remove build directories
156 help - print this text
157 <test case> - run the specified test. This can be specified multiple times
158 to allow running a list of tests.
159 available test cases $([ -n "$pattern" ] && echo "( matching '$pattern' )"):
160 $(echo "${test_list[@]}" | sed "s/ /\n /g")
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100161END_HELP
162}
163
164#################### Entry point ###################################
165
166OS_ID=$(uname -o )
167
168if [ -n $(which tput) -a -t ]
169then
Gyorgy Szing54071d92022-01-04 12:34:14 +0100170 COLOR_YELLOW=$(tput setaf 3)
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100171 COLOR_RESET=$(tput sgr0)
172 COLOR_RED=$(tput setaf 1)
173 COLOR_GREEN=$(tput setaf 2)
174else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100175 COLOR_YELLOW=
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100176 COLOR_RESET=
177 COLOR_RED=
178 COLOR_GREEN=
179fi
180
Gyorgy Szing7ddb28a2023-01-17 15:55:36 +0100181_ccache=$(which ccache 2>/dev/null) || true "never mind"
Gyorgy Szingb164e392021-09-04 01:51:57 +0200182
Gyorgy Szingf24a03a2023-03-21 03:00:40 +0100183process_commands() {
184 local exit_code=0
185 while true
186 do
187 case $1 in
188 {% for config in data %}
189 {{config.name}})
190 {{config.name}} || {
191 exit_code=$?
192 }
193 ;;
194 {% endfor %}
195 clean)
196 do_clean || {
197 exit_code=$?
198 break
199 }
200 ;;
201 help)
202 do_help
203 break
204 ;;
205 "")
206 for _test in "${test_list[@]}"
207 do
208 "$_test" || {
209 exit_code=$?
210 }
211 done
212 break
213 ;;
214 *)
215 echo "${COLOR_RED}Error: invalid command: $1 $COLOR_RESET"
216 do_help
217 exit_code=1
218 break
219 ;;
220 esac
221 shift
222 [ 0 -eq $# ] && break
223 done
224 return $exit_code
225}
226
227while true
228do
229 # parse options
230 case $1 in
231 -p)
232 shift
233 pattern=$1
234 if [ -z "$pattern" ]
235 then
236 echo "${COLOR_RED}Error: missing argument <search regexp>. $COLOR_RESET"
237 exit_code=1
238 break
239 else
240 readarray -t test_list < <(printf "%s\n" "${test_list[@]}" | grep -- "$pattern")
241 {% raw %}
242 [ 0 -eq ${#test_list[@]} ] && {
243 {% endraw %}
244 echo "${COLOR_RED}Error: -p <regexp> matches no tests. $COLOR_RESET"
245 exit_code=1
246 break
247 }
248 fi
249 ;;
250 *)
251 # parse commands
252 process_commands "$@" || exit_code=$?
253 break
254 ;;
255 esac
256 shift
257done
Gyorgy Szing54071d92022-01-04 12:34:14 +0100258
259exit $exit_code