blob: 2cb4b3a4f2a3cd28299ef21b1920b9ecb87d3095 [file] [log] [blame]
Oliver Smithe3985642019-10-11 16:37:59 +02001#!/bin/sh -e
2PROJECT="$1"
3PROJECT_UPPER="$(echo "$PROJECT" | tr '[:lower:]' '[:upper:]')"
4DIR_OSMODEV="$(readlink -f "$(dirname $0)/..")"
5DIR_MAKE="${DIR_MAKE:-${DIR_OSMODEV}/ttcn3/make}"
6DIR_OUTPUT="${DIR_OUTPUT:-${DIR_OSMODEV}/ttcn3/out}"
Oliver Smith0fa204e2021-08-12 15:16:11 +02007DIR_USR_LOCAL="$DIR_OSMODEV/ttcn3/usr_local"
Oliver Smithe3985642019-10-11 16:37:59 +02008JOBS="${JOBS:-9}"
9
Oliver Smith0fa204e2021-08-12 15:16:11 +020010# Osmocom libraries and programs relevant for the current testsuite will be
11# built in this container. It must have all build dependencies available and
12# be based on the same distribution that master-* containers are based on, so
13# there are no incompatibilities with shared libraries.
14DOCKER_IMG_BUILD="debian-stretch-jenkins"
15
Oliver Smithe3985642019-10-11 16:37:59 +020016check_usage() {
17 if [ -z "$PROJECT" ]; then
18 echo "usage: $(basename $0) PROJECT"
19 echo "example: $(basename $0) hlr"
Oliver Smithe3985642019-10-11 16:37:59 +020020 exit 1
21 fi
22}
23
24# Returns the name of the testsuite binary
25get_testsuite_name() {
26 case "$PROJECT" in
27 bts-*) echo "BTS_Tests" ;;
28 mgw) echo "MGCP_Test" ;;
29 pcu-sns) echo "PCU_Tests" ;;
30 *) echo "${PROJECT_UPPER}_Tests" ;;
31 esac
32}
33
34get_testsuite_dir() {
35 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
36
37 case "$PROJECT" in
38 bts-*) echo "$hacks/bts" ;;
39 pcu-sns) echo "$hacks/pcu" ;;
40 *) echo "$hacks/$PROJECT" ;;
41 esac
42}
43
44get_testsuite_config() {
45 case "$PROJECT" in
46 bts-gprs) echo "BTS_Tests_GPRS.cfg" ;;
47 bts-oml) echo "BTS_Tests_OML.cfg" ;;
48 pcu-sns) echo "PCU_Tests_SNS.cfg" ;;
49 *) echo "$(get_testsuite_name).cfg" ;;
50 esac
51}
52
Oliver Smith01a510a2020-03-18 15:46:41 +010053get_testsuite_dir_docker() {
54 local dp="${DIR_OSMODEV}/src/docker-playground"
55
56 case "$PROJECT" in
57 *) echo "$dp/ttcn3-$PROJECT-test" ;;
58 esac
59}
60
61# Programs that need to be built
Oliver Smithe3985642019-10-11 16:37:59 +020062get_programs() {
63 case "$PROJECT" in
64 bsc) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020065 bts) echo "osmo-bsc osmo-bts-trx" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020066 msc) echo "osmo-stp osmo-msc" ;;
67 pcu-sns) echo "osmo-pcu" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020068 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020069 sgsn) echo "osmo-stp osmo-sgsn" ;;
Oliver Smith01401bc2019-11-28 12:19:28 +010070 sip) echo "osmo-sip-connector" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020071 *) echo "osmo-$PROJECT" ;;
72 esac
73}
74
Oliver Smithe3985642019-10-11 16:37:59 +020075# Return the git repository name, which has the source for a specific program.
76# $1: program name
77get_program_repo() {
78 case "$1" in
Oliver Smithe3985642019-10-11 16:37:59 +020079 osmo-bts-*) echo "osmo-bts" ;;
Oliver Smithf03dfa32021-08-09 09:09:04 +020080 osmo-pcap-*) echo "osmo-pcap" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020081 osmo-stp) echo "libosmo-sccp" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020082 *) echo "$1" ;;
83 esac
84}
85
86check_ttcn3_install() {
87 if ! command -v ttcn3_compiler > /dev/null; then
88 echo "ERROR: ttcn3_compiler is not installed."
89 echo "Install eclipse-titan from the Osmocom latest repository."
90 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
91 exit 1
92 fi
93}
94
Oliver Smithe3985642019-10-11 16:37:59 +020095setup_dir_make() {
96 cd "$DIR_OSMODEV"
97
Oliver Smith0fa204e2021-08-12 15:16:11 +020098 local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh"
99 docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD"
100
Oliver Smith10da26d2020-01-07 13:17:54 +0100101 ./gen_makefile.py \
Oliver Smith10da26d2020-01-07 13:17:54 +0100102 default.opts \
103 iu.opts \
104 no_systemd.opts \
105 no_doxygen.opts \
106 no_dahdi.opts \
107 no_optimization.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200108 ttcn3/ttcn3.opts \
Oliver Smithd3271062021-08-25 11:47:48 +0200109 werror.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200110 --docker-cmd "$docker_cmd" \
111 --make-dir "$DIR_MAKE" \
Oliver Smith7ece2492021-08-23 16:56:39 +0200112 --no-ldconfig \
113 --no-make-check
Oliver Smithe3985642019-10-11 16:37:59 +0200114}
115
116# $1: name of repository (e.g. osmo-ttcn3-hacks)
117clone_repo() {
Oliver Smith5f611c72021-08-26 18:03:17 +0200118 if ! [ -e "$DIR_OSMODEV/ttcn3/make/.make.${1}.clone" ]; then
119 make -C "$DIR_MAKE" ".make.${1}.clone"
120 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200121}
122
Oliver Smith01a510a2020-03-18 15:46:41 +0100123# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200124check_dir_testsuite() {
125 local program
126 local config_testsuite
127 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100128 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200129
130 if ! [ -d "$dir_testsuite" ]; then
131 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
132 exit 1
133 fi
134
Oliver Smith01a510a2020-03-18 15:46:41 +0100135 if ! [ -d "$dir_testsuite_docker" ]; then
136 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
137 exit 1
138 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200139
Oliver Smith01a510a2020-03-18 15:46:41 +0100140 # Sanity check for jenkins.sh
141 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
142 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200143 exit 1
144 fi
145}
146
Oliver Smith1b471a92020-04-27 12:00:25 +0200147# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
148# inside the docker container
149prepare_local_bin() {
150 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200151 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200152 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200153 "
154
155 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200156 local script_path_localbin
157 local name_install="$(basename "$script")"
158
159 case "$name_install" in
160 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
161 esac
162
Oliver Smith0fa204e2021-08-12 15:16:11 +0200163 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200164 if [ -x "$script_path_localbin" ]; then
165 continue
166 fi
167
Oliver Smith7531cea2021-06-01 13:29:56 +0200168 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200169 done
170}
171
Oliver Smith0fa204e2021-08-12 15:16:11 +0200172prepare_docker_build_container() {
173 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build"
174
175 if [ -e "$marker" ]; then
176 return
177 fi
178
179 make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD"
180 touch "$marker"
181}
182
Oliver Smithe3985642019-10-11 16:37:59 +0200183# Use osmo-dev to build one Osmocom program and its dependencies
184build_osmo_programs() {
185 local program
Oliver Smith8d8ddf42021-08-26 17:56:02 +0200186 local programs="$(get_programs)"
187 local make_args="-C $DIR_MAKE"
188
189 for program in $programs; do
190 local repo="$(get_program_repo "$program")"
191 make_args="$make_args $repo"
192 done
193
194 set -x
195 make $make_args
196 set +x
197
198 for program in $programs; do
199 local repo="$(get_program_repo "$program")"
200 local usr_local_bin="$DIR_USR_LOCAL/bin"
201
202 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
203 echo "ERROR: program was not installed properly: $program"
204 echo "Expected it to be in path: $PATH_dest"
205 exit 1
206 fi
207
208 local reference="$DIR_MAKE/.make.$repo.build"
209 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
210 echo "ERROR: $path is outdated!"
211 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs" \
212 "$program?"
213 exit 1
214 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200215 done
216}
217
218build_testsuite() {
219 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200220
221 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
222 if ! [ -e "$deps_marker" ]; then
223 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
224 touch "$deps_marker"
225 fi
226
Oliver Smithe3985642019-10-11 16:37:59 +0200227 ./gen_links.sh
228 ./regen_makefile.sh
229 make compile
230 make -j"$JOBS"
231}
232
Oliver Smith01a510a2020-03-18 15:46:41 +0100233run_docker() {
234 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
235 local docker_dir="$(get_testsuite_dir_docker)"
236 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200237 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200238
Oliver Smith01a510a2020-03-18 15:46:41 +0100239 # Skip building docker containers if this already ran
240 if [ -e "$marker" ]; then
241 echo "NOTE: skipping docker container build, because marker exists: $marker"
242 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200243 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100244
245 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200246 export DOCKER_ARGS="\
247 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200248 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200249 -v $hacks:/osmo-ttcn3-hacks:ro \
250 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200251 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100252 ./jenkins.sh
253
254 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200255}
256
Oliver Smith01a510a2020-03-18 15:46:41 +0100257remove_old_logs() {
258 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200259}
260
261collect_logs() {
262 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100263 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200264
265 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200266 for log in *.merged; do
267 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100268 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200269 done
270
271 # Print log path
272 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100273 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200274 echo "---"
275}
276
Oliver Smithe3985642019-10-11 16:37:59 +0200277check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200278check_ttcn3_install
279setup_dir_make
280clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100281clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200282check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200283prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200284prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200285build_osmo_programs
286build_testsuite
287remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100288run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200289collect_logs