blob: 6d0f33f06d1a8415e255a82ede32e0ff19ab2394 [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 Szingba1095c2020-11-24 00:33:11 +010033# Convert test name to build directory
34function name-to-bdir() {
35 printf "./build-%s" "$1"
36}
37
38# Wrap cmake to allow verbose vs non-verbose mode
39function _cmake() {
40 log_file=$1
41 shift
42 if [ "$VERBOSE" != "0" ]
43 then
44 cmake "$@" 2>&1 | tee -a "$log_file"
45 return ${PIPESTATUS[0]}
46 else
47 cmake "$@" >>"$log_file" 2>&1
48 fi
49}
50
51{% for config in data %}
52# Run build test "{{config.name}}"
53{{config.name}}() {
54 echo "##################################################################"
55 echo "########################## {{config.name}} started."
56
57 {% if config.os_id is defined %}
58 if [ "$OS_ID" != "{{config.os_id}}" ]
59 then
60 echo "Test case is not supported on this host."
Gyorgy Szing54071d92022-01-04 12:34:14 +010061 echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET"
Gyorgy Szingba1095c2020-11-24 00:33:11 +010062 echo "##################################################################"
63 return
64 fi
65 {% endif %}
66 b_dir=$(name-to-bdir "{{config.name}}")
67 log_file=$b_dir/build.log
68 rm -rf "$b_dir"
69 mkdir -p "$b_dir"
70
Gyorgy Szingb164e392021-09-04 01:51:57 +020071 if [ -n "$_ccache" ]
72 then
73 ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache
74 fi
75
Gyorgy Szing54071d92022-01-04 12:34:14 +010076 local retval=0
Gyorgy Szingba1095c2020-11-24 00:33:11 +010077
Gyorgy Szing54071d92022-01-04 12:34:14 +010078 # jinja2 is removing single newlines. Adding a comment stops this behavior.
Imre Kisf9dda4a2022-01-18 18:54:15 +010079 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 +010080 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010081 if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose
Gyorgy Szingba1095c2020-11-24 00:33:11 +010082 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010083 if _cmake "$log_file" --install "$b_dir" --prefix ./install
84 then
85 echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET"
86 else
87 retval=$?
88 echo "For details see: $log_file"
89 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
90 fi
Gyorgy Szingba1095c2020-11-24 00:33:11 +010091 else
Gyorgy Szing54071d92022-01-04 12:34:14 +010092 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +010093 echo "For details see: $log_file"
94 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
95 fi
96 else
Gyorgy Szing54071d92022-01-04 12:34:14 +010097 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +010098 echo "For details see: $log_file"
99 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
100 fi
101 echo "##################################################################"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100102 return $retval
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100103}
104
105{% endfor %}
106
107# Clean intermediate files
108do_clean() {
109 {% for config in data %}
110 b_dir=$(name-to-bdir "{{config.name}}")
111 if [ -d "$b_dir" ]
112 then
113 echo "Removing $b_dir"
Gyorgy Szing54071d92022-01-04 12:34:14 +0100114 rm -rf "$b_dir"
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100115 fi
116 {% endfor %}
117}
118
119# Print usage info
120do_help() {
121 cat <<END_HELP
122Build test runner
123=================
124
125Invocation::
126 ``$0 <command>``
127
128The file "user.env" is sourced from the current directory. Use it to set
129environment specific defaults. For config variables see the start of this script
130and any "$<XXXX>" in the "params" array of any command in test_data.yaml
131Some variables to note
132 - VERBOSE : make the script output more info.
133 VERBOSE=$VERBOSE
134 - TS_ROOT : Root directory of the TS repo.
135 TS_ROOT=$TS_ROOT
136 - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting the number of
137 parallel processes during build
138 NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS
Imre Kisf9dda4a2022-01-18 18:54:15 +0100139 - CMAKE_EXTRA_FLAGS: additional environment specific CMake flags
140 CMAKE_EXTRA_FLAGS=-DNEWLIB_LIBC_PATH=/path/to/newlib
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100141
142Available commands:
143 "" - no command/default -> run all test cases
144 clean - remove build directories
145 help - print this text
146 <test case> - run a single build
147 available test cases:
148 {% for config in data %}
149 {{config.name}}
150 {% endfor %}
151END_HELP
152}
153
154#################### Entry point ###################################
155
156OS_ID=$(uname -o )
157
158if [ -n $(which tput) -a -t ]
159then
Gyorgy Szing54071d92022-01-04 12:34:14 +0100160 COLOR_YELLOW=$(tput setaf 3)
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100161 COLOR_RESET=$(tput sgr0)
162 COLOR_RED=$(tput setaf 1)
163 COLOR_GREEN=$(tput setaf 2)
164else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100165 COLOR_YELLOW=
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100166 COLOR_RESET=
167 COLOR_RED=
168 COLOR_GREEN=
169fi
170
Gyorgy Szing7ddb28a2023-01-17 15:55:36 +0100171_ccache=$(which ccache 2>/dev/null) || true "never mind"
Gyorgy Szingb164e392021-09-04 01:51:57 +0200172
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100173case $1 in
174 {% for config in data %}
175 {{config.name}})
Gyorgy Szing54071d92022-01-04 12:34:14 +0100176 {{config.name}} || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100177 ;;
178 {% endfor %}
179 clean)
Gyorgy Szing54071d92022-01-04 12:34:14 +0100180 do_clean || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100181 ;;
182 help)
183 do_help
184 ;;
185 "")
186 {% for config in data %}
Gyorgy Szing54071d92022-01-04 12:34:14 +0100187 {{config.name}} || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100188 {% endfor %}
189 ;;
190 *)
191 do_help
Gyorgy Szing54071d92022-01-04 12:34:14 +0100192 exit_code=1
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100193 ;;
194esac
Gyorgy Szing54071d92022-01-04 12:34:14 +0100195
196exit $exit_code