Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Gyorgy Szing | 7ddb28a | 2023-01-17 15:55:36 +0100 | [diff] [blame] | 3 | # Copyright (c) 2020-2023, Arm Limited and contributors. All rights reserved. |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Exit with error if any command fails |
| 9 | set -e |
| 10 | |
| 11 | # Read in user specific environment settings |
| 12 | if [ -e user.env ] |
| 13 | then |
| 14 | echo "Reding user specific settings from user.env" |
| 15 | source user.env |
| 16 | fi |
| 17 | |
| 18 | # Default to non-verbose mode. |
| 19 | VERBOSE=${VERBOSE:-0} |
| 20 | |
Imre Kis | f9dda4a | 2022-01-18 18:54:15 +0100 | [diff] [blame] | 21 | # Additional environment specific CMake flags |
| 22 | CMAKE_EXTRA_FLAGS=${CMAKE_EXTRA_FLAGS:-""} |
| 23 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 24 | # Get root of TS repo. |
| 25 | TS_ROOT=${TS_ROOT:-$(git rev-parse --show-toplevel)} |
| 26 | |
| 27 | # Number of threads to use in parallel |
| 28 | NUMBER_OF_PROCESSORS=${NUMBER_OF_PROCESSORS:-$(( $(nproc) * 2 )) } |
| 29 | |
Gyorgy Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 30 | # By default run as much as we can |
| 31 | FAIL_FAST=${FAIL_FAST:-0} |
| 32 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 33 | # Global exit code. |
| 34 | exit_code=0 |
| 35 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 36 | # List of supported tests. |
| 37 | test_list=( |
| 38 | {% for config in data %} |
| 39 | "{{config.name}}" |
| 40 | {% endfor %} |
| 41 | ) |
| 42 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 43 | # Convert test name to build directory |
| 44 | function name-to-bdir() { |
| 45 | printf "./build-%s" "$1" |
| 46 | } |
| 47 | |
| 48 | # Wrap cmake to allow verbose vs non-verbose mode |
| 49 | function _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 Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 71 | echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 72 | 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 Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 81 | if [ -n "$_ccache" ] |
| 82 | then |
| 83 | ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache |
| 84 | fi |
| 85 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 86 | local retval=0 |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 87 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 88 | # jinja2 is removing single newlines. Adding a comment stops this behavior. |
Imre Kis | f9dda4a | 2022-01-18 18:54:15 +0100 | [diff] [blame] | 89 | 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 90 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 91 | if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 92 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 93 | 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 101 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 102 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 103 | echo "For details see: $log_file" |
| 104 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 105 | fi |
| 106 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 107 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 108 | echo "For details see: $log_file" |
| 109 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 110 | fi |
| 111 | echo "##################################################################" |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 112 | return $retval |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | {% endfor %} |
| 116 | |
| 117 | # Clean intermediate files |
| 118 | do_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 Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 124 | rm -rf "$b_dir" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 125 | fi |
| 126 | {% endfor %} |
| 127 | } |
| 128 | |
| 129 | # Print usage info |
| 130 | do_help() { |
| 131 | cat <<END_HELP |
| 132 | Build test runner |
| 133 | ================= |
| 134 | |
| 135 | Invocation:: |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 136 | ``$0 [<options>] [<command>]`` |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 137 | |
| 138 | The file "user.env" is sourced from the current directory. Use it to set |
| 139 | environment specific defaults. For config variables see the start of this script |
| 140 | and any "$<XXXX>" in the "params" array of any command in test_data.yaml |
| 141 | Some variables to note |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 142 | - 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 Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 151 | - FAIL_FAST: <0/1> see -f |
| 152 | FAIL_FAST=$FAIL_FAST |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 153 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 154 | Options: |
Gyorgy Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 155 | -f|--fail-fast |
| 156 | - exit after the first test failure |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 157 | -p <regexp> |
| 158 | - filter out all test cases whose name is not matching regexp. |
| 159 | regexp is a regular expression understood by grep |
| 160 | Commands: |
| 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 168 | END_HELP |
| 169 | } |
| 170 | |
| 171 | #################### Entry point ################################### |
| 172 | |
| 173 | OS_ID=$(uname -o ) |
| 174 | |
| 175 | if [ -n $(which tput) -a -t ] |
| 176 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 177 | COLOR_YELLOW=$(tput setaf 3) |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 178 | COLOR_RESET=$(tput sgr0) |
| 179 | COLOR_RED=$(tput setaf 1) |
| 180 | COLOR_GREEN=$(tput setaf 2) |
| 181 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 182 | COLOR_YELLOW= |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 183 | COLOR_RESET= |
| 184 | COLOR_RED= |
| 185 | COLOR_GREEN= |
| 186 | fi |
| 187 | |
Gyorgy Szing | 7ddb28a | 2023-01-17 15:55:36 +0100 | [diff] [blame] | 188 | _ccache=$(which ccache 2>/dev/null) || true "never mind" |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 189 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 190 | process_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 Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 199 | [ "$FAIL_FAST" -ne 0 ] && break |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 200 | } |
| 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 Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 218 | [ "$FAIL_FAST" -ne 0 ] && break |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 219 | } |
| 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 | |
| 236 | while true |
| 237 | do |
| 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 Szing | e1ccb2d | 2023-03-21 03:05:23 +0100 | [diff] [blame^] | 259 | --f|--fail-fast) |
| 260 | FAIL_FAST=1 |
| 261 | ;; |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame] | 262 | *) |
| 263 | # parse commands |
| 264 | process_commands "$@" || exit_code=$? |
| 265 | break |
| 266 | ;; |
| 267 | esac |
| 268 | shift |
| 269 | done |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 270 | |
| 271 | exit $exit_code |