Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 3 | # Copyright (c) 2020-2022, 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 | |
| 21 | # Get root of TS repo. |
| 22 | TS_ROOT=${TS_ROOT:-$(git rev-parse --show-toplevel)} |
| 23 | |
| 24 | # Number of threads to use in parallel |
| 25 | NUMBER_OF_PROCESSORS=${NUMBER_OF_PROCESSORS:-$(( $(nproc) * 2 )) } |
| 26 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 27 | # Global exit code. |
| 28 | exit_code=0 |
| 29 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 30 | # Convert test name to build directory |
| 31 | function name-to-bdir() { |
| 32 | printf "./build-%s" "$1" |
| 33 | } |
| 34 | |
| 35 | # Wrap cmake to allow verbose vs non-verbose mode |
| 36 | function _cmake() { |
| 37 | log_file=$1 |
| 38 | shift |
| 39 | if [ "$VERBOSE" != "0" ] |
| 40 | then |
| 41 | cmake "$@" 2>&1 | tee -a "$log_file" |
| 42 | return ${PIPESTATUS[0]} |
| 43 | else |
| 44 | cmake "$@" >>"$log_file" 2>&1 |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | {% for config in data %} |
| 49 | # Run build test "{{config.name}}" |
| 50 | {{config.name}}() { |
| 51 | echo "##################################################################" |
| 52 | echo "########################## {{config.name}} started." |
| 53 | |
| 54 | {% if config.os_id is defined %} |
| 55 | if [ "$OS_ID" != "{{config.os_id}}" ] |
| 56 | then |
| 57 | echo "Test case is not supported on this host." |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 58 | echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 59 | echo "##################################################################" |
| 60 | return |
| 61 | fi |
| 62 | {% endif %} |
| 63 | b_dir=$(name-to-bdir "{{config.name}}") |
| 64 | log_file=$b_dir/build.log |
| 65 | rm -rf "$b_dir" |
| 66 | mkdir -p "$b_dir" |
| 67 | |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 68 | if [ -n "$_ccache" ] |
| 69 | then |
| 70 | ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache |
| 71 | fi |
| 72 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 73 | local retval=0 |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 74 | |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 75 | # jinja2 is removing single newlines. Adding a comment stops this behavior. |
| 76 | if _cmake "$log_file" -S {{config.src}} -B "$b_dir" $ccache_option {% for param in config.params %} "{{param}}" {% endfor %} #keep newline |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 77 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 78 | if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 79 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 80 | if _cmake "$log_file" --install "$b_dir" --prefix ./install |
| 81 | then |
| 82 | echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET" |
| 83 | else |
| 84 | retval=$? |
| 85 | echo "For details see: $log_file" |
| 86 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 87 | fi |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 88 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 89 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 90 | echo "For details see: $log_file" |
| 91 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 92 | fi |
| 93 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 94 | retval=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 95 | echo "For details see: $log_file" |
| 96 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 97 | fi |
| 98 | echo "##################################################################" |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 99 | return $retval |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | {% endfor %} |
| 103 | |
| 104 | # Clean intermediate files |
| 105 | do_clean() { |
| 106 | {% for config in data %} |
| 107 | b_dir=$(name-to-bdir "{{config.name}}") |
| 108 | if [ -d "$b_dir" ] |
| 109 | then |
| 110 | echo "Removing $b_dir" |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 111 | rm -rf "$b_dir" |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 112 | fi |
| 113 | {% endfor %} |
| 114 | } |
| 115 | |
| 116 | # Print usage info |
| 117 | do_help() { |
| 118 | cat <<END_HELP |
| 119 | Build test runner |
| 120 | ================= |
| 121 | |
| 122 | Invocation:: |
| 123 | ``$0 <command>`` |
| 124 | |
| 125 | The file "user.env" is sourced from the current directory. Use it to set |
| 126 | environment specific defaults. For config variables see the start of this script |
| 127 | and any "$<XXXX>" in the "params" array of any command in test_data.yaml |
| 128 | Some variables to note |
| 129 | - VERBOSE : make the script output more info. |
| 130 | VERBOSE=$VERBOSE |
| 131 | - TS_ROOT : Root directory of the TS repo. |
| 132 | TS_ROOT=$TS_ROOT |
| 133 | - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting the number of |
| 134 | parallel processes during build |
| 135 | NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 136 | |
| 137 | Available commands: |
| 138 | "" - no command/default -> run all test cases |
| 139 | clean - remove build directories |
| 140 | help - print this text |
| 141 | <test case> - run a single build |
| 142 | available test cases: |
| 143 | {% for config in data %} |
| 144 | {{config.name}} |
| 145 | {% endfor %} |
| 146 | END_HELP |
| 147 | } |
| 148 | |
| 149 | #################### Entry point ################################### |
| 150 | |
| 151 | OS_ID=$(uname -o ) |
| 152 | |
| 153 | if [ -n $(which tput) -a -t ] |
| 154 | then |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 155 | COLOR_YELLOW=$(tput setaf 3) |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 156 | COLOR_RESET=$(tput sgr0) |
| 157 | COLOR_RED=$(tput setaf 1) |
| 158 | COLOR_GREEN=$(tput setaf 2) |
| 159 | else |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 160 | COLOR_YELLOW= |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 161 | COLOR_RESET= |
| 162 | COLOR_RED= |
| 163 | COLOR_GREEN= |
| 164 | fi |
| 165 | |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 166 | _ccache=$(which ccache) |
| 167 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 168 | case $1 in |
| 169 | {% for config in data %} |
| 170 | {{config.name}}) |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 171 | {{config.name}} || exit_code=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 172 | ;; |
| 173 | {% endfor %} |
| 174 | clean) |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 175 | do_clean || exit_code=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 176 | ;; |
| 177 | help) |
| 178 | do_help |
| 179 | ;; |
| 180 | "") |
| 181 | {% for config in data %} |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 182 | {{config.name}} || exit_code=$? |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 183 | {% endfor %} |
| 184 | ;; |
| 185 | *) |
| 186 | do_help |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 187 | exit_code=1 |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 188 | ;; |
| 189 | esac |
Gyorgy Szing | 54071d9 | 2022-01-04 12:34:14 +0100 | [diff] [blame^] | 190 | |
| 191 | exit $exit_code |