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