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 | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 30 | # Global exit code. |
| 31 | exit_code=0 |
| 32 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame^] | 33 | # List of supported tests. |
| 34 | test_list=( |
| 35 | {% for config in data %} |
| 36 | "{{config.name}}" |
| 37 | {% endfor %} |
| 38 | ) |
| 39 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 40 | # Convert test name to build directory |
| 41 | function name-to-bdir() { |
| 42 | printf "./build-%s" "$1" |
| 43 | } |
| 44 | |
| 45 | # Wrap cmake to allow verbose vs non-verbose mode |
| 46 | function _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 Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 68 | echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 69 | 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 Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 78 | if [ -n "$_ccache" ] |
| 79 | then |
| 80 | ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache |
| 81 | fi |
| 82 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 83 | local retval=0 |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 84 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 85 | # jinja2 is removing single newlines. Adding a comment stops this behavior. |
Imre Kis | f9dda4a | 2022-01-18 18:54:15 +0100 | [diff] [blame] | 86 | 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] | 87 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 88 | if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 89 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 90 | 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 98 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 99 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 100 | echo "For details see: $log_file" |
| 101 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 102 | fi |
| 103 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 104 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 105 | echo "For details see: $log_file" |
| 106 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 107 | fi |
| 108 | echo "##################################################################" |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 109 | return $retval |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | {% endfor %} |
| 113 | |
| 114 | # Clean intermediate files |
| 115 | do_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 Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 121 | rm -rf "$b_dir" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 122 | fi |
| 123 | {% endfor %} |
| 124 | } |
| 125 | |
| 126 | # Print usage info |
| 127 | do_help() { |
| 128 | cat <<END_HELP |
| 129 | Build test runner |
| 130 | ================= |
| 131 | |
| 132 | Invocation:: |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame^] | 133 | ``$0 [<options>] [<command>]`` |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 134 | |
| 135 | The file "user.env" is sourced from the current directory. Use it to set |
| 136 | environment specific defaults. For config variables see the start of this script |
| 137 | and any "$<XXXX>" in the "params" array of any command in test_data.yaml |
| 138 | Some variables to note |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame^] | 139 | - 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 148 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame^] | 149 | Options: |
| 150 | -p <regexp> |
| 151 | - filter out all test cases whose name is not matching regexp. |
| 152 | regexp is a regular expression understood by grep |
| 153 | Commands: |
| 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 Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 161 | END_HELP |
| 162 | } |
| 163 | |
| 164 | #################### Entry point ################################### |
| 165 | |
| 166 | OS_ID=$(uname -o ) |
| 167 | |
| 168 | if [ -n $(which tput) -a -t ] |
| 169 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 170 | COLOR_YELLOW=$(tput setaf 3) |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 171 | COLOR_RESET=$(tput sgr0) |
| 172 | COLOR_RED=$(tput setaf 1) |
| 173 | COLOR_GREEN=$(tput setaf 2) |
| 174 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 175 | COLOR_YELLOW= |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 176 | COLOR_RESET= |
| 177 | COLOR_RED= |
| 178 | COLOR_GREEN= |
| 179 | fi |
| 180 | |
Gyorgy Szing | 7ddb28a | 2023-01-17 15:55:36 +0100 | [diff] [blame] | 181 | _ccache=$(which ccache 2>/dev/null) || true "never mind" |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 182 | |
Gyorgy Szing | f24a03a | 2023-03-21 03:00:40 +0100 | [diff] [blame^] | 183 | process_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 | |
| 227 | while true |
| 228 | do |
| 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 |
| 257 | done |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame] | 258 | |
| 259 | exit $exit_code |