blob: 898664d04756231d5db417460c9c3bfc1e696419 [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.
Oliver Smithd88ae262022-05-03 12:53:25 +020014DOCKER_IMG_BUILD="debian-bullseye-build"
Oliver Smith0fa204e2021-08-12 15:16:11 +020015
Oliver Smithe3985642019-10-11 16:37:59 +020016check_usage() {
Oliver Smith6711b4f2023-03-06 11:20:15 +010017 local name="$(basename $0)"
Oliver Smithe3985642019-10-11 16:37:59 +020018 if [ -z "$PROJECT" ]; then
Oliver Smith6711b4f2023-03-06 11:20:15 +010019 echo "usage: $name PROJECT"
20 echo "examples:"
21 echo " * $name bsc"
22 echo " * $name bsc-sccplite"
23 echo " * $name hlr"
Oliver Smithe3985642019-10-11 16:37:59 +020024 exit 1
25 fi
26}
27
28# Returns the name of the testsuite binary
29get_testsuite_name() {
30 case "$PROJECT" in
31 bts-*) echo "BTS_Tests" ;;
32 mgw) echo "MGCP_Test" ;;
33 pcu-sns) echo "PCU_Tests" ;;
34 *) echo "${PROJECT_UPPER}_Tests" ;;
35 esac
36}
37
38get_testsuite_dir() {
39 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
40
41 case "$PROJECT" in
42 bts-*) echo "$hacks/bts" ;;
Oliver Smith6711b4f2023-03-06 11:20:15 +010043 bsc-*) echo "$hacks/bsc" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020044 pcu-sns) echo "$hacks/pcu" ;;
45 *) echo "$hacks/$PROJECT" ;;
46 esac
47}
48
49get_testsuite_config() {
50 case "$PROJECT" in
51 bts-gprs) echo "BTS_Tests_GPRS.cfg" ;;
52 bts-oml) echo "BTS_Tests_OML.cfg" ;;
53 pcu-sns) echo "PCU_Tests_SNS.cfg" ;;
54 *) echo "$(get_testsuite_name).cfg" ;;
55 esac
56}
57
Oliver Smith01a510a2020-03-18 15:46:41 +010058get_testsuite_dir_docker() {
59 local dp="${DIR_OSMODEV}/src/docker-playground"
60
61 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010062 bsc-*)
63 echo "$dp/ttcn3-bsc-test-$(echo "$PROJECT" | cut -d - -f 2-)"
64 ;;
65 *)
66 echo "$dp/ttcn3-$PROJECT-test"
67 ;;
Oliver Smith01a510a2020-03-18 15:46:41 +010068 esac
69}
70
Oliver Smithf3d71202022-10-18 15:43:31 +020071get_testsuite_image() {
72 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010073 bsc-*)
74 echo "$USER/ttcn3-bsc-test"
75 ;;
76 *)
77 echo "$USER/ttcn3-$PROJECT-test"
78 ;;
Oliver Smithf3d71202022-10-18 15:43:31 +020079 esac
80}
81
Oliver Smith01a510a2020-03-18 15:46:41 +010082# Programs that need to be built
Oliver Smithe3985642019-10-11 16:37:59 +020083get_programs() {
84 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010085 bsc|bsc-*) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020086 bts) echo "osmo-bsc osmo-bts-trx" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020087 msc) echo "osmo-stp osmo-msc" ;;
88 pcu-sns) echo "osmo-pcu" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020089 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020090 sgsn) echo "osmo-stp osmo-sgsn" ;;
Oliver Smith01401bc2019-11-28 12:19:28 +010091 sip) echo "osmo-sip-connector" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020092 *) echo "osmo-$PROJECT" ;;
93 esac
94}
95
Oliver Smithe3985642019-10-11 16:37:59 +020096# Return the git repository name, which has the source for a specific program.
97# $1: program name
98get_program_repo() {
99 case "$1" in
Oliver Smithe3985642019-10-11 16:37:59 +0200100 osmo-bts-*) echo "osmo-bts" ;;
Oliver Smithf03dfa32021-08-09 09:09:04 +0200101 osmo-pcap-*) echo "osmo-pcap" ;;
Oliver Smithe3985642019-10-11 16:37:59 +0200102 osmo-stp) echo "libosmo-sccp" ;;
Oliver Smithe3985642019-10-11 16:37:59 +0200103 *) echo "$1" ;;
104 esac
105}
106
107check_ttcn3_install() {
108 if ! command -v ttcn3_compiler > /dev/null; then
109 echo "ERROR: ttcn3_compiler is not installed."
110 echo "Install eclipse-titan from the Osmocom latest repository."
111 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
112 exit 1
113 fi
114}
115
Oliver Smithe3985642019-10-11 16:37:59 +0200116setup_dir_make() {
117 cd "$DIR_OSMODEV"
118
Oliver Smith0fa204e2021-08-12 15:16:11 +0200119 local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh"
120 docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD"
121
Oliver Smith10da26d2020-01-07 13:17:54 +0100122 ./gen_makefile.py \
Oliver Smith10da26d2020-01-07 13:17:54 +0100123 default.opts \
124 iu.opts \
125 no_systemd.opts \
126 no_doxygen.opts \
127 no_dahdi.opts \
128 no_optimization.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200129 ttcn3/ttcn3.opts \
Oliver Smithd3271062021-08-25 11:47:48 +0200130 werror.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200131 --docker-cmd "$docker_cmd" \
132 --make-dir "$DIR_MAKE" \
Oliver Smith7ece2492021-08-23 16:56:39 +0200133 --no-ldconfig \
Oliver Smith6c7fed82021-10-04 13:30:31 +0200134 --no-make-check \
135 --auto-distclean
Oliver Smithe3985642019-10-11 16:37:59 +0200136}
137
138# $1: name of repository (e.g. osmo-ttcn3-hacks)
139clone_repo() {
Oliver Smith5f611c72021-08-26 18:03:17 +0200140 if ! [ -e "$DIR_OSMODEV/ttcn3/make/.make.${1}.clone" ]; then
141 make -C "$DIR_MAKE" ".make.${1}.clone"
142 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200143}
144
Oliver Smith01a510a2020-03-18 15:46:41 +0100145# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200146check_dir_testsuite() {
147 local program
148 local config_testsuite
149 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100150 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200151
152 if ! [ -d "$dir_testsuite" ]; then
153 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
154 exit 1
155 fi
156
Oliver Smith01a510a2020-03-18 15:46:41 +0100157 if ! [ -d "$dir_testsuite_docker" ]; then
Oliver Smith78a1e052023-03-06 11:12:23 +0100158 echo "ERROR: could not find docker dir for project: $PROJECT: $dir_testsuite_docker"
159 echo "Adjust get_testsuite_dir_docker?"
Oliver Smith01a510a2020-03-18 15:46:41 +0100160 exit 1
161 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200162
Oliver Smith01a510a2020-03-18 15:46:41 +0100163 # Sanity check for jenkins.sh
164 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
165 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200166 exit 1
167 fi
168}
169
Oliver Smith1b471a92020-04-27 12:00:25 +0200170# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
171# inside the docker container
172prepare_local_bin() {
173 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200174 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith202dcd82022-05-03 11:09:45 +0200175 ${DIR_OSMODEV}/src/docker-playground/debian-bullseye-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200176 "
177
178 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200179 local script_path_localbin
180 local name_install="$(basename "$script")"
181
182 case "$name_install" in
183 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
184 esac
185
Oliver Smith0fa204e2021-08-12 15:16:11 +0200186 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200187 if [ -x "$script_path_localbin" ]; then
188 continue
189 fi
190
Oliver Smith7531cea2021-06-01 13:29:56 +0200191 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200192 done
193}
194
Oliver Smith0fa204e2021-08-12 15:16:11 +0200195prepare_docker_build_container() {
196 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build"
197
198 if [ -e "$marker" ]; then
199 return
200 fi
201
202 make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD"
203 touch "$marker"
204}
205
Oliver Smithf3d71202022-10-18 15:43:31 +0200206prepare_docker_testsuite_container() {
207 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build-testsuite"
208
209 if [ -e "$marker" ]; then
210 return
211 fi
212
213 make -C "$(get_testsuite_dir_docker)"
214 touch "$marker"
215}
216
Oliver Smithe3985642019-10-11 16:37:59 +0200217# Use osmo-dev to build one Osmocom program and its dependencies
218build_osmo_programs() {
219 local program
Oliver Smith8d8ddf42021-08-26 17:56:02 +0200220 local programs="$(get_programs)"
221 local make_args="-C $DIR_MAKE"
222
223 for program in $programs; do
224 local repo="$(get_program_repo "$program")"
225 make_args="$make_args $repo"
226 done
227
228 set -x
229 make $make_args
230 set +x
231
232 for program in $programs; do
233 local repo="$(get_program_repo "$program")"
234 local usr_local_bin="$DIR_USR_LOCAL/bin"
235
236 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
237 echo "ERROR: program was not installed properly: $program"
238 echo "Expected it to be in path: $PATH_dest"
239 exit 1
240 fi
241
242 local reference="$DIR_MAKE/.make.$repo.build"
243 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
244 echo "ERROR: $path is outdated!"
245 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs" \
246 "$program?"
247 exit 1
248 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200249 done
250}
251
252build_testsuite() {
253 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200254
255 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
256 if ! [ -e "$deps_marker" ]; then
257 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
258 touch "$deps_marker"
259 fi
260
Oliver Smithf3d71202022-10-18 15:43:31 +0200261 # Build inside docker, so the resulting binary links against the
262 # libraries available in docker and not the ones from the host system,
263 # since we will run it inside docker later too.
264 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
265
Oliver Smithf44fd1b2023-03-06 11:24:08 +0100266 local testsuite_image="$(get_testsuite_image)"
267 echo "testsuite_image: $testsuite_image"
268
Oliver Smithba1cfcc2022-10-21 12:11:18 +0200269 # -t: add a tty, so we get color output from the compiler
Oliver Smithf3d71202022-10-18 15:43:31 +0200270 docker run \
271 --rm \
Oliver Smithba1cfcc2022-10-21 12:11:18 +0200272 -t \
Oliver Smithf3d71202022-10-18 15:43:31 +0200273 -v "$hacks:/osmo-ttcn3-hacks" \
Oliver Smithf44fd1b2023-03-06 11:24:08 +0100274 "$testsuite_image" \
Oliver Smithf3d71202022-10-18 15:43:31 +0200275 sh -exc "
276 cd /osmo-ttcn3-hacks/$(basename "$(get_testsuite_dir)");
277 ./gen_links.sh;
278 ./regen_makefile.sh;
279 make compile;
280 make -j"$JOBS"
281 "
Oliver Smithe3985642019-10-11 16:37:59 +0200282}
283
Oliver Smith01a510a2020-03-18 15:46:41 +0100284run_docker() {
285 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
286 local docker_dir="$(get_testsuite_dir_docker)"
287 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200288 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200289
Oliver Smith01a510a2020-03-18 15:46:41 +0100290 # Skip building docker containers if this already ran
291 if [ -e "$marker" ]; then
292 echo "NOTE: skipping docker container build, because marker exists: $marker"
293 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200294 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100295
296 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200297 export DOCKER_ARGS="\
298 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200299 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200300 -v $hacks:/osmo-ttcn3-hacks:ro \
301 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200302 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100303 ./jenkins.sh
304
305 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200306}
307
Oliver Smith01a510a2020-03-18 15:46:41 +0100308remove_old_logs() {
309 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200310}
311
312collect_logs() {
313 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100314 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200315
316 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200317 for log in *.merged; do
318 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100319 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200320 done
321
322 # Print log path
323 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100324 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200325 echo "---"
326}
327
Oliver Smithe3985642019-10-11 16:37:59 +0200328check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200329check_ttcn3_install
330setup_dir_make
331clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100332clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200333check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200334prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200335prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200336build_osmo_programs
Oliver Smithf3d71202022-10-18 15:43:31 +0200337prepare_docker_testsuite_container
Oliver Smithe3985642019-10-11 16:37:59 +0200338build_testsuite
339remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100340run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200341collect_logs