summaryrefslogtreecommitdiffstats
path: root/ttcn3/suites/ttcn3_bts_tests/scripts/run_ttcn3_docker.sh
blob: daac3e09b9b47298c6b2490fb06f3a591e9870b7 (plain)
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
#!/bin/sh
set -x

RUNDIR="$1"
JUNIT_TTCN3_DST_FILE="$2"
BSC_RSL_ADDR="$3"
L2_SOCKET_PATH="$4"
PCU_SOCKET_PATH="$5"

# Absolute path to this script
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in
SCRIPTPATH=$(dirname "$SCRIPT")

VOL_BASE_DIR="$RUNDIR/logs"
rm -rf "$VOL_BASE_DIR"
mkdir -p "$VOL_BASE_DIR"

if [ "x$BUILD_TAG" = "x" ]; then
	BUILD_TAG=nonjenkins
fi

REPO_USER="registry.sysmocom.de"
SUITE_NAME="ttcn3-bts-test"
NET_NAME=$SUITE_NAME
DOCKER_NAME="$BUILD_TAG-$SUITE_NAME"

network_create() {
	NET=$1
	echo Creating network $NET_NAME
	docker network create --subnet $NET $NET_NAME
}

network_remove() {
	echo Removing network $NET_NAME
	docker network remove $NET_NAME
}

child_ps=0
forward_kill() {
	sig="$1"
	echo "Caught signal SIG$sig!"
	if [ "$child_ps" != "0" ]; then
		echo "Killing $child_ps with SIG$sig!"
		docker kill ${DOCKER_NAME}
	fi
	exit 130
}
forward_kill_int() {
	forward_kill "INT"
}
forward_kill_term() {
	forward_kill "TERM"
}
# Don't use 'set -e', otherwise traps are not triggered!
trap forward_kill_int INT
trap forward_kill_term TERM

network_create 172.18.9.0/24

mkdir $VOL_BASE_DIR/bts-tester
echo "SCRIPTPATH=$SCRIPTPATH PWD=$PWD"
cp $RUNDIR/BTS_Tests.cfg $VOL_BASE_DIR/bts-tester/

echo Starting container with BTS testsuite
docker kill ${DOCKER_NAME}
if [ "x$PCU_SOCKET_PATH" != "x" ]; then
	MOUNT_PCU_SOCKET_OPT="--mount type=bind,source=$(dirname "$PCU_SOCKET_PATH"),destination=/data/unix_pcu"
else
	MOUNT_PCU_SOCKET_OPT=""
fi
docker run	--rm \
		--network $NET_NAME --ip 172.18.9.10 \
		-p ${BSC_RSL_ADDR}:3003:3003 \
		-e "TTCN3_PCAP_PATH=/data" \
		--mount type=bind,source=$VOL_BASE_DIR/bts-tester,destination=/data \
		--mount type=bind,source="$(dirname "$L2_SOCKET_PATH")",destination=/data/unix_l2 \
		$MOUNT_PCU_SOCKET_OPT \
		--name ${DOCKER_NAME} \
		$REPO_USER/${SUITE_NAME} &
child_ps=$!
echo "$$: waiting for $child_ps"
wait "$child_ps"
child_exit_code="$?"
echo "ttcn3 docker exited with code $child_exit_code"

network_remove

echo "Copying TTCN3 junit file to $JUNIT_TTCN3_DST_FILE"
cp $VOL_BASE_DIR/bts-tester/junit-xml-*.log $JUNIT_TTCN3_DST_FILE
sed -i "s#classname='BTS_Tests'#classname='$(basename $JUNIT_TTCN3_DST_FILE)'#g" $JUNIT_TTCN3_DST_FILE

exit $child_exit_code