-
Notifications
You must be signed in to change notification settings - Fork 35
/
loop.sh
executable file
·103 lines (84 loc) · 2.35 KB
/
loop.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
#!/bin/bash
_sdl_prepared=$1; shift
_tmpdirname=$1; shift
_atf_ts_dir=$1; shift
_queue=$1; shift
_save_sdl_log=$1; shift
_save_sdl_core_dump=$1; shift
_test_id_file=$1; shift
_lockfile=.lock
_image_name=atf_worker
_container_name=$(basename $_tmpdirname)
####################################################################
# The following code has to be run in several different processes
# i.e. `screen -d -m 'script_to_run.sh'`
####################################################################
function docker_run {
docker run --rm \
--name $_container_name \
--cap-add NET_ADMIN \
--privileged \
-e LOCAL_USER_ID=`id -u $USER` \
-v $_atf_ts_dir:/home/developer/atf_ts \
-v $_tmpdirname:/home/developer/sdl \
-v $_sdl_prepared:/home/developer/sdl_ext \
$_image_name "$@"
}
function docker_stop {
docker stop $(docker ps -q -f "name=$_container_name")
for id in $container_ids;
do
docker stop $id
done
}
function pop {
local FILE=$1
local RES=1
if (set -o noclobber; echo "$$" > "$_lockfile") 2> /dev/null; then
trap 'rm -f "$_lockfile"; exit $?' TERM EXIT
local LINE=$(head -n 1 $FILE | awk '{print $1}')
if [ -n "$LINE" ]; then
sed -i '1d' $FILE
RES=0
if [ ! -f $_test_id_file ]; then echo 0 > $_test_id_file; fi
local CURRENT_ID=$(cat $_test_id_file)
let CURRENT_ID=CURRENT_ID+1
echo $CURRENT_ID > $_test_id_file
echo $CURRENT_ID $LINE
else
RES=2
fi
rm -f "$_lockfile"
trap - TERM EXIT
fi
return $RES
}
function int_handler() {
echo "Stopping docker containers"
# Stop handling sigint
trap - INT
rm -f $_lockfile
docker_stop
exit 0
}
function main {
trap 'int_handler' INT
while true; do
row=$(pop $_queue)
local res=$?
if [ $res == 1 ]; then
sleep 0.2;
continue;
elif [ $res == 2 ]; then
break;
fi
local script_num=$(echo $row | awk '{print $1}')
local script_name=$(echo $row | awk '{print $2}')
docker_run $script_name \
--sdl-log=$_save_sdl_log \
--sdl-core-dump=$_save_sdl_core_dump \
--test-id $script_num
sleep 0.1
done
}
main