-
Notifications
You must be signed in to change notification settings - Fork 35
/
start.sh
executable file
·401 lines (359 loc) · 11 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/env bash
ATF_PATH=$(cd "$(dirname "$0")" && pwd)
REPORT_FILE=Report.txt
REPORT_FILE_CONSOLE=Console.txt
DEBUG=false
LINE1=$(printf -- '=%.0s' {1..100})
LINE2=$(printf -- '-%.0s' {1..100})
JOBS=1
FORCE_PARALLELS=false
SAVE_SDL_LOG=yes
SAVE_SDL_CORE_DUMP=yes
COPY_TS=false
THIRD_PARTY="$THIRD_PARTY_INSTALL_PREFIX"
TMP_PATH=/tmp
# Color modifications
P="\033[0;32m" # GREEN
F="\033[0;31m" # RED
A="\033[0;35m" # MAGENTA
S="\033[0;33m" # YELLOW
B="\033[0;34m" # BLUE
N="\033[0m" # NONE
dbg() {
if [ $DEBUG = true ]; then echo "DEBUG: $@"; fi
}
log() {
echo -e "$@";
}
timestamp() {
echo $(date +%s)
}
seconds2time() {
T=$1
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
if [[ ${D} != 0 ]]
then
printf '%d days %02d:%02d:%02d' $D $H $M $S
else
printf '%02d:%02d:%02d' $H $M $S
fi
}
remove_color() {
sed -i "s/\x1b[^m]*m//g" $1
}
show_help() {
echo "Bash .lua test Script Runner"
echo
echo "Usage: start.sh TEST [OPTION]..."
echo
echo "TEST - test target, could be one of the following:"
echo " - test script"
echo " - test set"
echo " - folder with test scripts"
echo
echo "[OPTION] - one or more options:"
echo " --sdl-core - path to SDL binaries"
echo " --config - name of configuration"
echo " --sdl-src - path to SDL Core"
echo " --sdl-mobile-api - path to SDL MOBILE API"
echo " --sdl-hmi-api - path to SDL HMI API"
echo " --report - path to report and logs"
echo " --sdl-log [ACTION] - how to collect SDL logs"
echo " 'yes' - always save (default), 'no' - do not save, 'fail' - save if script failed or aborted"
echo " --sdl-core-dump [ACTION] - how to collect SDL core dumps"
echo " 'yes' - always save (default), 'no' - do not save, 'fail' - save if script failed or aborted"
echo " --parallels - force to use parallels mode"
echo " -j|--jobs n - number of jobs to start ATF in parallels"
echo " --third-party - path to SDL third party"
echo " --tmp - path to temporary folder used by parallels"
echo " --copy-atf-ts - force copying of ATF test scripts instead of creating symlinks"
echo
echo "In case if folder is specified as a test target:"
echo " - only scripts which name starts with number will be taken into account (e.g. 001, 002 etc.)"
echo " - if there are sub-folders scripts will be run recursively"
echo
echo "Besides execution of .lua scripts Script Runner also does auxiliary actions:"
echo " - clean up SDL and ATF folders before running of each script"
echo " - backup and restore SDL important files"
echo " - create report with all required logs for each script"
echo
exit 0
}
get_param_from_atf_config() {
for i in `sed s'/=/ /g' $1 | grep "$2 " | awk '{print $2}'`; do echo $i | sed 's/"//g'; done
}
parse_arguments() {
dbg "Func" "parse_arguments" "Enter"
if [ $# -eq 0 ]; then
show_help
fi
local ARGS=("$@")
local COUNTER=0
local NAMELESS_COUNTER=0
local NAMELESS_ARGS
while [ $COUNTER -lt $# ]
do
local ARG=${ARGS[$COUNTER]}
let COUNTER=COUNTER+1
local NEXT_ARG=${ARGS[$COUNTER]}
if [[ $SKIP_NEXT -eq 1 ]]; then
SKIP_NEXT=0
continue
fi
local ARG_KEY=""
local ARG_VAL=""
if [[ "$ARG" =~ ^\- ]]; then
# if the format is: -key=value
if [[ "$ARG" =~ \= ]]; then
ARG_VAL=$(echo "$ARG" | cut -d'=' -f2)
ARG_KEY=$(echo "$ARG" | cut -d'=' -f1)
SKIP_NEXT=0
# if the format is: -key value
elif [[ ! "$NEXT_ARG" =~ ^\- ]]; then
ARG_KEY="$ARG"
ARG_VAL="$NEXT_ARG"
SKIP_NEXT=1
# if the format is: -key (a boolean flag)
elif [[ "$NEXT_ARG" =~ ^\- ]] || [[ -z "$NEXT_ARG" ]]; then
ARG_KEY="$ARG"
ARG_VAL=""
SKIP_NEXT=0
fi
# if the format has not flag, just a value
else
ARG_KEY=""
ARG_VAL="$ARG"
SKIP_NEXT=0
fi
case "$ARG_KEY" in
--config)
CONFIG="$ARG_VAL"
;;
--sdl-core)
SDL_CORE="$ARG_VAL"
;;
--report)
REPORT_PATH="$ARG_VAL"
;;
--sdl-src)
SDL_SRC="$ARG_VAL"
;;
--sdl-mobile-api)
SDL_MOBILE_API="$ARG_VAL"
;;
--sdl-hmi-api)
SDL_HMI_API="$ARG_VAL"
;;
-j|--jobs)
JOBS="$ARG_VAL"
;;
--third-party)
THIRD_PARTY="$ARG_VAL"
;;
--parallels)
FORCE_PARALLELS=true
;;
--tmp)
TMP_PATH="$ARG_VAL"
;;
--sdl-log)
SAVE_SDL_LOG="$ARG_VAL"
;;
--sdl-core-dump)
SAVE_SDL_CORE_DUMP="$ARG_VAL"
;;
--copy-atf-ts)
COPY_TS=true
;;
-h|--help|-help|--h)
show_help
;;
--test-id)
TEST_ID="$ARG_VAL"
;;
-*|--*)
echo "Unknown option '$ARG_KEY'"
exit 1
;;
*)
let NAMELESS_COUNTER=NAMELESS_COUNTER+1
NAMELESS_ARGS[NAMELESS_COUNTER]="$ARG_VAL"
;;
esac
done
# handle nameless arguments
if [ ${#NAMELESS_ARGS[*]} -gt 0 ]; then
TEST_TARGET=${NAMELESS_ARGS[1]}
fi
dbg "Func" "parse_arguments" "Exit"
}
print_parameters() {
dbg "= Parameters ($1):"
dbg "TEST_TARGET: "$TEST_TARGET
dbg "REPORT_PATH: "$REPORT_PATH
dbg "SDL_PROCESS_NAME: "$SDL_PROCESS_NAME
dbg "SDL_CORE: "$SDL_CORE
dbg "SDL_SRC: "$SDL_SRC
dbg "SDL_MOBILE_API: "$SDL_MOBILE_API
dbg "SDL_HMI_API: "$SDL_HMI_API
dbg "IS_REMOTE_ENABLED: "$IS_REMOTE_ENABLED
dbg "SAVE_SDL_LOG: "$SAVE_SDL_LOG
dbg "SAVE_SDL_CORE_DUMP: "$SAVE_SDL_CORE_DUMP
}
check_environment() {
dbg "Func" "check_environment" "Enter"
local dirs=("test_scripts" "test_sets" "files" "user_modules")
for dir in ${dirs[@]}; do
if [ ! -d "$dir" ]; then
echo "Required folder '$dir' is not available"
exit 1
fi
done
dbg "Func" "check_environment" "Exit"
}
check_arguments() {
dbg "Func" "check_arguments" "Enter"
if [ -z $TEST_TARGET ]; then
echo "Test target was not specified"
exit 1
fi
if [ "${TEST_TARGET: -1}" = "/" ]; then
TEST_TARGET="${TEST_TARGET:0:-1}"
fi
if [ -n $JOBS ] && [ -z "${JOBS##*[!0-9]*}" ]; then
echo "Invalid number of jobs was specified within --jobs option"
exit 1
fi
if [ ! -d ${ATF_PATH}/modules/configuration/${CONFIG} ]; then
echo "Invalid configuration was specified within --config option"
exit 1
fi
if ( [ $FORCE_PARALLELS = true ] || [ $JOBS -gt 1 ] ) && [ -z "$(docker images | grep 'atf_worker')" ]; then
echo "Required docker image 'atf_worker' is not available"
exit 1
fi
if [ -z $SAVE_SDL_LOG ]; then
echo "ACTION was not specified within --sdl-log option"
exit 1
fi
if [ -z $SAVE_SDL_CORE_DUMP ]; then
echo "ACTION was not specified within --sdl-core-dump option"
exit 1
fi
dbg "Func" "check_arguments" "Exit"
}
set_param() {
local var=$1
local param=$2
local config=$3
local value=$(get_param_from_atf_config ${config} ${param})
if [ -z "${!var}" ] && [ -n "$value" ]; then declare -g -- "$var=$value"; fi
}
build_parameters() {
dbg "Func" "build_parameters" "Enter"
print_parameters "arguments"
# load parameters from specific config
if [ -n "$CONFIG" ]; then
local CONFIG_PATH=${ATF_PATH}/modules/configuration/${CONFIG}
set_param SDL_PROCESS_NAME "config.SDL" ${CONFIG_PATH}/base_config.lua
set_param REPORT_PATH "config.reportPath" ${CONFIG_PATH}/base_config.lua
set_param SDL_CORE "config.pathToSDL" ${CONFIG_PATH}/base_config.lua
set_param SDL_SRC "config.pathToSDLSource" ${CONFIG_PATH}/base_config.lua
set_param SDL_MOBILE_API "config.pathToSDLMobileInterface" ${CONFIG_PATH}/base_config.lua
set_param SDL_HMI_API "config.pathToSDLHMIInterface" ${CONFIG_PATH}/base_config.lua
set_param IS_REMOTE_ENABLED "config.remoteConnection.enabled" ${CONFIG_PATH}/connection_config.lua
print_parameters "specific config"
fi
# load parameters from base config
local CONFIG_PATH=${ATF_PATH}/modules/configuration
set_param SDL_PROCESS_NAME "config.SDL" ${CONFIG_PATH}/base_config.lua
set_param REPORT_PATH "config.reportPath" ${CONFIG_PATH}/base_config.lua
set_param SDL_CORE "config.pathToSDL" ${CONFIG_PATH}/base_config.lua
set_param SDL_SRC "config.pathToSDLSource" ${CONFIG_PATH}/base_config.lua
set_param SDL_MOBILE_API "config.pathToSDLMobileInterface" ${CONFIG_PATH}/base_config.lua
set_param SDL_HMI_API "config.pathToSDLHMIInterface" ${CONFIG_PATH}/base_config.lua
set_param IS_REMOTE_ENABLED "config.remoteConnection.enabled" ${CONFIG_PATH}/connection_config.lua
print_parameters "base config"
dbg "TEST_ID: "$TEST_ID
dbg "Func" "build_parameters" "Exit"
}
check_parameters() {
dbg "Func" "check_parameters" "Enter"
if [ -z $SDL_PROCESS_NAME ]; then
echo "SDL process name was not specified"
exit 1
fi
if [ -z $REPORT_PATH ]; then
echo "Report path was not specified"
exit 1
fi
if [ -z $SDL_CORE ]; then
echo "Path to SDL binaries was not specified"
exit 1
fi
if [ ! -d $SDL_SRC ]; then
echo "Invalid path to SDL source was specified: ${SDL_SRC}"
exit 1
fi
if [ ! -d $SDL_MOBILE_API ]; then
echo "Invalid path to MOBILE API was specified: ${SDL_MOBILE_API}"
exit 1
fi
if [ ! -d $SDL_HMI_API ]; then
echo "Invalid path to HMI API was specified: ${SDL_HMI_API}"
exit 1
fi
if [ ! -d $SDL_CORE ] && [ $IS_REMOTE_ENABLED = false ]; then
echo "Invalid path to SDL binaries was specified"
exit 1
fi
dbg "Func" "check_parameters" "Exit"
}
build_atf_options() {
dbg "Func" "build_atf_options" "Enter"
OPTIONS=""
if [ -n "$CONFIG" ]; then OPTIONS="$OPTIONS --config=${CONFIG}"; fi
if [ -n "$SDL_CORE" ]; then OPTIONS="$OPTIONS --sdl-core=${SDL_CORE}"; fi
if [ -n "$REPORT_PATH" ]; then OPTIONS="$OPTIONS --report-path=${REPORT_PATH}"; fi
if [ -n "$SDL_SRC" ]; then OPTIONS="$OPTIONS --sdl-src=${SDL_SRC}"; fi
if [ -n "$SDL_MOBILE_API" ]; then OPTIONS="$OPTIONS --sdl-mobile-api=${SDL_MOBILE_API}"; fi
if [ -n "$SDL_HMI_API" ]; then OPTIONS="$OPTIONS --sdl-hmi-api=${SDL_HMI_API}"; fi
if [ $IS_REMOTE_ENABLED = true ] && [ $SAVE_SDL_LOG = yes ]; then OPTIONS="$OPTIONS --storeFullSDLLogs"; fi
dbg "= OPTIONS:"$OPTIONS
dbg "Func" "build_atf_options" "Exit"
}
create_report_folder() {
dbg "Func" "create_report_folder" "Enter"
REPORT_PATH_TS=${REPORT_PATH}/$(date +"%Y-%m-%d_%H-%M-%S.%3N")
mkdir -p ${REPORT_PATH_TS}
mkdir -p /tmp/corefiles
dbg "Func" "create_report_folder" "Exit"
}
load_runner() {
dbg "Func" "load_runner" "Enter"
if [ $IS_REMOTE_ENABLED = true ]; then
dbg "= Mode: Remote"
source tools/runners/remote.sh
elif [ $JOBS -gt 1 ] || [ $FORCE_PARALLELS = true ]; then
dbg "= Mode: Parallels"
source tools/runners/parallels.sh
else
dbg "= Mode: Regular"
source tools/runners/common.sh
fi
dbg "Func" "load_runner" "Exit"
}
check_environment
parse_arguments "$@"
check_arguments
build_parameters
check_parameters
build_atf_options
create_report_folder
load_runner
StartUp
Run
TearDown