blob: 32d5e83e3b7f78d147d95a7df9d3057bec4fe20d [file] [log] [blame]
Gyorgy Szingba1095c2020-11-24 00:33:11 +01001#!/bin/bash
2#
3# Copyright (c) 2020, Arm Limited and contributors. All rights reserved.
4#
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
65 _cmake "$log_file" -S {{config.src}} -B "$b_dir" {% for param in config.params %} "{{param}}" {%endfor%} || {
66
67 echo "For details see: $log_file"
68 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
69 return
70 }
71
72 if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS}
73 then
74 if _cmake "$log_file" --install "$b_dir" --prefix ./install
75 then
76 echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET"
77 else
78 echo "For details see: $log_file"
79 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
80 fi
81 else
82 echo "For details see: $log_file"
83 echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET"
84 fi
85 echo "##################################################################"
86}
87
88{% endfor %}
89
90# Clean intermediate files
91do_clean() {
92 {% for config in data %}
93 b_dir=$(name-to-bdir "{{config.name}}")
94 if [ -d "$b_dir" ]
95 then
96 echo "Removing $b_dir"
97 rm -rf "$b_dir" || true
98 fi
99 {% endfor %}
100}
101
102# Print usage info
103do_help() {
104 cat <<END_HELP
105Build test runner
106=================
107
108Invocation::
109 ``$0 <command>``
110
111The file "user.env" is sourced from the current directory. Use it to set
112environment specific defaults. For config variables see the start of this script
113and any "$<XXXX>" in the "params" array of any command in test_data.yaml
114Some variables to note
115 - VERBOSE : make the script output more info.
116 VERBOSE=$VERBOSE
117 - TS_ROOT : Root directory of the TS repo.
118 TS_ROOT=$TS_ROOT
119 - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting the number of
120 parallel processes during build
121 NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS
122 - SP_DEV_KIT_DIR : location of OP-TEE OS SPDEVKIT export.
123 SP_DEV_KIT_DIR=$SP_DEV_KIT_DIR
124
125Available commands:
126 "" - no command/default -> run all test cases
127 clean - remove build directories
128 help - print this text
129 <test case> - run a single build
130 available test cases:
131 {% for config in data %}
132 {{config.name}}
133 {% endfor %}
134END_HELP
135}
136
137#################### Entry point ###################################
138
139OS_ID=$(uname -o )
140
141if [ -n $(which tput) -a -t ]
142then
143 COLOR_YELOW=$(tput setaf 3)
144 COLOR_RESET=$(tput sgr0)
145 COLOR_RED=$(tput setaf 1)
146 COLOR_GREEN=$(tput setaf 2)
147else
148 COLOR_YELOW=
149 COLOR_RESET=
150 COLOR_RED=
151 COLOR_GREEN=
152fi
153
154case $1 in
155 {% for config in data %}
156 {{config.name}})
157 {{config.name}}
158 ;;
159 {% endfor %}
160 clean)
161 do_clean
162 ;;
163 help)
164 do_help
165 ;;
166 "")
167 {% for config in data %}
168 {{config.name}}
169 {% endfor %}
170 ;;
171 *)
172 do_help
173 ;;
174esac