blob: 0ff7e78fc41ff5a60d78f593bb4eab0815806858 [file] [log] [blame]
Gyorgy Szingba1095c2020-11-24 00:33:11 +01001#!/bin/bash
2#
Gyorgy Szing54071d92022-01-04 12:34:14 +01003# Copyright (c) 2020-2022, 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
21# Get root of TS repo.
22TS_ROOT=${TS_ROOT:-$(git rev-parse --show-toplevel)}
23
24# Number of threads to use in parallel
25NUMBER_OF_PROCESSORS=${NUMBER_OF_PROCESSORS:-$(( $(nproc) * 2 )) }
26
Gyorgy Szing54071d92022-01-04 12:34:14 +010027# Global exit code.
28exit_code=0
29
Gyorgy Szingba1095c2020-11-24 00:33:11 +010030# Convert test name to build directory
31function name-to-bdir() {
32 printf "./build-%s" "$1"
33}
34
35# Wrap cmake to allow verbose vs non-verbose mode
36function _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 Szing54071d92022-01-04 12:34:14 +010058 echo "########################## $COLOR_YELLOW {{config.name}} skipped $COLOR_RESET"
Gyorgy Szingba1095c2020-11-24 00:33:11 +010059 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 Szingb164e392021-09-04 01:51:57 +020068 if [ -n "$_ccache" ]
69 then
70 ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache
71 fi
72
Gyorgy Szing54071d92022-01-04 12:34:14 +010073 local retval=0
Gyorgy Szingba1095c2020-11-24 00:33:11 +010074
Gyorgy Szing54071d92022-01-04 12:34:14 +010075 # 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 Szingba1095c2020-11-24 00:33:11 +010077 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010078 if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose
Gyorgy Szingba1095c2020-11-24 00:33:11 +010079 then
Gyorgy Szing54071d92022-01-04 12:34:14 +010080 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 Szingba1095c2020-11-24 00:33:11 +010088 else
Gyorgy Szing54071d92022-01-04 12:34:14 +010089 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +010090 echo "For details see: $log_file"
91 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
92 fi
93 else
Gyorgy Szing54071d92022-01-04 12:34:14 +010094 retval=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +010095 echo "For details see: $log_file"
96 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
97 fi
98 echo "##################################################################"
Gyorgy Szing54071d92022-01-04 12:34:14 +010099 return $retval
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100100}
101
102{% endfor %}
103
104# Clean intermediate files
105do_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 Szing54071d92022-01-04 12:34:14 +0100111 rm -rf "$b_dir"
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100112 fi
113 {% endfor %}
114}
115
116# Print usage info
117do_help() {
118 cat <<END_HELP
119Build test runner
120=================
121
122Invocation::
123 ``$0 <command>``
124
125The file "user.env" is sourced from the current directory. Use it to set
126environment specific defaults. For config variables see the start of this script
127and any "$<XXXX>" in the "params" array of any command in test_data.yaml
128Some 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 Szingba1095c2020-11-24 00:33:11 +0100136
137Available 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 %}
146END_HELP
147}
148
149#################### Entry point ###################################
150
151OS_ID=$(uname -o )
152
153if [ -n $(which tput) -a -t ]
154then
Gyorgy Szing54071d92022-01-04 12:34:14 +0100155 COLOR_YELLOW=$(tput setaf 3)
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100156 COLOR_RESET=$(tput sgr0)
157 COLOR_RED=$(tput setaf 1)
158 COLOR_GREEN=$(tput setaf 2)
159else
Gyorgy Szing54071d92022-01-04 12:34:14 +0100160 COLOR_YELLOW=
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100161 COLOR_RESET=
162 COLOR_RED=
163 COLOR_GREEN=
164fi
165
Gyorgy Szingb164e392021-09-04 01:51:57 +0200166_ccache=$(which ccache)
167
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100168case $1 in
169 {% for config in data %}
170 {{config.name}})
Gyorgy Szing54071d92022-01-04 12:34:14 +0100171 {{config.name}} || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100172 ;;
173 {% endfor %}
174 clean)
Gyorgy Szing54071d92022-01-04 12:34:14 +0100175 do_clean || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100176 ;;
177 help)
178 do_help
179 ;;
180 "")
181 {% for config in data %}
Gyorgy Szing54071d92022-01-04 12:34:14 +0100182 {{config.name}} || exit_code=$?
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100183 {% endfor %}
184 ;;
185 *)
186 do_help
Gyorgy Szing54071d92022-01-04 12:34:14 +0100187 exit_code=1
Gyorgy Szingba1095c2020-11-24 00:33:11 +0100188 ;;
189esac
Gyorgy Szing54071d92022-01-04 12:34:14 +0100190
191exit $exit_code