blob: 2a950272f920634d65c44f4fea225ca76e37c182 [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 Smith9326b362023-04-20 12:56:15 +020015DOCKER_IMG_TITAN="debian-bullseye-titan"
Oliver Smith0fa204e2021-08-12 15:16:11 +020016
Oliver Smithe3985642019-10-11 16:37:59 +020017check_usage() {
Oliver Smith6711b4f2023-03-06 11:20:15 +010018 local name="$(basename $0)"
Oliver Smithe3985642019-10-11 16:37:59 +020019 if [ -z "$PROJECT" ]; then
Oliver Smith6711b4f2023-03-06 11:20:15 +010020 echo "usage: $name PROJECT"
21 echo "examples:"
22 echo " * $name bsc"
23 echo " * $name bsc-sccplite"
24 echo " * $name hlr"
Oliver Smithe3985642019-10-11 16:37:59 +020025 exit 1
26 fi
27}
28
29# Returns the name of the testsuite binary
30get_testsuite_name() {
31 case "$PROJECT" in
32 bts-*) echo "BTS_Tests" ;;
33 mgw) echo "MGCP_Test" ;;
34 pcu-sns) echo "PCU_Tests" ;;
35 *) echo "${PROJECT_UPPER}_Tests" ;;
36 esac
37}
38
39get_testsuite_dir() {
40 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
41
42 case "$PROJECT" in
43 bts-*) echo "$hacks/bts" ;;
Oliver Smith6711b4f2023-03-06 11:20:15 +010044 bsc-*) echo "$hacks/bsc" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020045 pcu-sns) echo "$hacks/pcu" ;;
46 *) echo "$hacks/$PROJECT" ;;
47 esac
48}
49
50get_testsuite_config() {
51 case "$PROJECT" in
52 bts-gprs) echo "BTS_Tests_GPRS.cfg" ;;
53 bts-oml) echo "BTS_Tests_OML.cfg" ;;
54 pcu-sns) echo "PCU_Tests_SNS.cfg" ;;
55 *) echo "$(get_testsuite_name).cfg" ;;
56 esac
57}
58
Oliver Smith01a510a2020-03-18 15:46:41 +010059get_testsuite_dir_docker() {
60 local dp="${DIR_OSMODEV}/src/docker-playground"
61
62 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010063 bsc-*)
64 echo "$dp/ttcn3-bsc-test-$(echo "$PROJECT" | cut -d - -f 2-)"
65 ;;
66 *)
67 echo "$dp/ttcn3-$PROJECT-test"
68 ;;
Oliver Smith01a510a2020-03-18 15:46:41 +010069 esac
70}
71
Oliver Smithf3d71202022-10-18 15:43:31 +020072get_testsuite_image() {
73 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010074 bsc-*)
75 echo "$USER/ttcn3-bsc-test"
76 ;;
77 *)
78 echo "$USER/ttcn3-$PROJECT-test"
79 ;;
Oliver Smithf3d71202022-10-18 15:43:31 +020080 esac
81}
82
Oliver Smith01a510a2020-03-18 15:46:41 +010083# Programs that need to be built
Oliver Smithe3985642019-10-11 16:37:59 +020084get_programs() {
85 case "$PROJECT" in
Oliver Smith6711b4f2023-03-06 11:20:15 +010086 bsc|bsc-*) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020087 bts) echo "osmo-bsc osmo-bts-trx" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020088 msc) echo "osmo-stp osmo-msc" ;;
89 pcu-sns) echo "osmo-pcu" ;;
Oliver Smith855d66e2021-08-12 16:58:26 +020090 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020091 sgsn) echo "osmo-stp osmo-sgsn" ;;
Oliver Smith01401bc2019-11-28 12:19:28 +010092 sip) echo "osmo-sip-connector" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020093 *) echo "osmo-$PROJECT" ;;
94 esac
95}
96
Oliver Smithe3985642019-10-11 16:37:59 +020097# Return the git repository name, which has the source for a specific program.
98# $1: program name
99get_program_repo() {
100 case "$1" in
Oliver Smithe3985642019-10-11 16:37:59 +0200101 osmo-bts-*) echo "osmo-bts" ;;
Oliver Smithf03dfa32021-08-09 09:09:04 +0200102 osmo-pcap-*) echo "osmo-pcap" ;;
Oliver Smithe3985642019-10-11 16:37:59 +0200103 osmo-stp) echo "libosmo-sccp" ;;
Oliver Smithe3985642019-10-11 16:37:59 +0200104 *) echo "$1" ;;
105 esac
106}
107
108check_ttcn3_install() {
109 if ! command -v ttcn3_compiler > /dev/null; then
110 echo "ERROR: ttcn3_compiler is not installed."
111 echo "Install eclipse-titan from the Osmocom latest repository."
112 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
113 exit 1
114 fi
115}
116
Oliver Smithe3985642019-10-11 16:37:59 +0200117setup_dir_make() {
118 cd "$DIR_OSMODEV"
119
Oliver Smith0fa204e2021-08-12 15:16:11 +0200120 local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh"
121 docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD"
122
Oliver Smith10da26d2020-01-07 13:17:54 +0100123 ./gen_makefile.py \
Oliver Smith10da26d2020-01-07 13:17:54 +0100124 default.opts \
125 iu.opts \
126 no_systemd.opts \
127 no_doxygen.opts \
128 no_dahdi.opts \
129 no_optimization.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200130 ttcn3/ttcn3.opts \
Oliver Smithd3271062021-08-25 11:47:48 +0200131 werror.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200132 --docker-cmd "$docker_cmd" \
133 --make-dir "$DIR_MAKE" \
Oliver Smith7ece2492021-08-23 16:56:39 +0200134 --no-ldconfig \
Oliver Smith6c7fed82021-10-04 13:30:31 +0200135 --no-make-check \
136 --auto-distclean
Oliver Smithe3985642019-10-11 16:37:59 +0200137}
138
139# $1: name of repository (e.g. osmo-ttcn3-hacks)
140clone_repo() {
Oliver Smith5f611c72021-08-26 18:03:17 +0200141 if ! [ -e "$DIR_OSMODEV/ttcn3/make/.make.${1}.clone" ]; then
142 make -C "$DIR_MAKE" ".make.${1}.clone"
143 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200144}
145
Oliver Smith01a510a2020-03-18 15:46:41 +0100146# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200147check_dir_testsuite() {
148 local program
149 local config_testsuite
150 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100151 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200152
153 if ! [ -d "$dir_testsuite" ]; then
154 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
155 exit 1
156 fi
157
Oliver Smith01a510a2020-03-18 15:46:41 +0100158 if ! [ -d "$dir_testsuite_docker" ]; then
Oliver Smith78a1e052023-03-06 11:12:23 +0100159 echo "ERROR: could not find docker dir for project: $PROJECT: $dir_testsuite_docker"
160 echo "Adjust get_testsuite_dir_docker?"
Oliver Smith01a510a2020-03-18 15:46:41 +0100161 exit 1
162 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200163
Oliver Smith01a510a2020-03-18 15:46:41 +0100164 # Sanity check for jenkins.sh
165 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
166 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200167 exit 1
168 fi
169}
170
Oliver Smith1b471a92020-04-27 12:00:25 +0200171# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
172# inside the docker container
173prepare_local_bin() {
174 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200175 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith837d4d62023-04-17 14:20:34 +0200176 ${DIR_OSMODEV}/src/docker-playground/common/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200177 "
178
179 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200180 local script_path_localbin
181 local name_install="$(basename "$script")"
182
183 case "$name_install" in
184 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
185 esac
186
Oliver Smith0fa204e2021-08-12 15:16:11 +0200187 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200188 if [ -x "$script_path_localbin" ]; then
189 continue
190 fi
191
Oliver Smith7531cea2021-06-01 13:29:56 +0200192 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200193 done
194}
195
Oliver Smith0fa204e2021-08-12 15:16:11 +0200196prepare_docker_build_container() {
Oliver Smith3115b122023-04-20 13:10:30 +0200197 local dp="${DIR_OSMODEV}/src/docker-playground"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200198
Oliver Smith3115b122023-04-20 13:10:30 +0200199 if docker_image_exists "$USER/$DOCKER_IMG_BUILD"; then
Oliver Smith0fa204e2021-08-12 15:16:11 +0200200 return
201 fi
202
Oliver Smith3115b122023-04-20 13:10:30 +0200203 echo "Building docker image: $USER/$DOCKER_IMG_BUILD"
204 make -C "$dp/$DOCKER_IMG_BUILD"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200205}
206
Oliver Smithf3d71202022-10-18 15:43:31 +0200207prepare_docker_testsuite_container() {
Oliver Smith3115b122023-04-20 13:10:30 +0200208 local testsuite_image="$(get_testsuite_image)"
Oliver Smithf3d71202022-10-18 15:43:31 +0200209
Oliver Smith3115b122023-04-20 13:10:30 +0200210 if docker_image_exists "$testsuite_image"; then
Oliver Smithf3d71202022-10-18 15:43:31 +0200211 return
212 fi
213
Oliver Smith3115b122023-04-20 13:10:30 +0200214 if ! docker_image_exists "$USER/$DOCKER_IMG_TITAN"; then
215 echo "Building docker image: $USER/$DOCKER_IMG_TITAN"
216 local dp="${DIR_OSMODEV}/src/docker-playground"
217 make -C "$dp/$DOCKER_IMG_TITAN"
218 fi
219
220 echo "Building docker image: $testsuite_image"
221 local testsuite_dir="$(get_testsuite_dir_docker)"
222 make -C "$testsuite_dir"
Oliver Smithf3d71202022-10-18 15:43:31 +0200223}
224
Oliver Smithe3985642019-10-11 16:37:59 +0200225# Use osmo-dev to build one Osmocom program and its dependencies
226build_osmo_programs() {
227 local program
Oliver Smith8d8ddf42021-08-26 17:56:02 +0200228 local programs="$(get_programs)"
229 local make_args="-C $DIR_MAKE"
230
231 for program in $programs; do
232 local repo="$(get_program_repo "$program")"
233 make_args="$make_args $repo"
234 done
235
236 set -x
237 make $make_args
238 set +x
239
240 for program in $programs; do
241 local repo="$(get_program_repo "$program")"
242 local usr_local_bin="$DIR_USR_LOCAL/bin"
243
244 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
245 echo "ERROR: program was not installed properly: $program"
246 echo "Expected it to be in path: $PATH_dest"
247 exit 1
248 fi
249
250 local reference="$DIR_MAKE/.make.$repo.build"
251 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
252 echo "ERROR: $path is outdated!"
253 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs" \
254 "$program?"
255 exit 1
256 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200257 done
258}
259
Oliver Smith9326b362023-04-20 12:56:15 +0200260docker_image_exists() {
261 test -n "$(docker images -q "$1")"
262}
263
Oliver Smithe3985642019-10-11 16:37:59 +0200264build_testsuite() {
265 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200266
267 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
268 if ! [ -e "$deps_marker" ]; then
269 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
270 touch "$deps_marker"
271 fi
272
Oliver Smithf3d71202022-10-18 15:43:31 +0200273 # Build inside docker, so the resulting binary links against the
274 # libraries available in docker and not the ones from the host system,
275 # since we will run it inside docker later too.
276 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
277
Oliver Smithf44fd1b2023-03-06 11:24:08 +0100278 local testsuite_image="$(get_testsuite_image)"
279 echo "testsuite_image: $testsuite_image"
280
Oliver Smithba1cfcc2022-10-21 12:11:18 +0200281 # -t: add a tty, so we get color output from the compiler
Oliver Smithf3d71202022-10-18 15:43:31 +0200282 docker run \
283 --rm \
Oliver Smithba1cfcc2022-10-21 12:11:18 +0200284 -t \
Oliver Smithf3d71202022-10-18 15:43:31 +0200285 -v "$hacks:/osmo-ttcn3-hacks" \
Oliver Smithf44fd1b2023-03-06 11:24:08 +0100286 "$testsuite_image" \
Oliver Smithf3d71202022-10-18 15:43:31 +0200287 sh -exc "
288 cd /osmo-ttcn3-hacks/$(basename "$(get_testsuite_dir)");
289 ./gen_links.sh;
290 ./regen_makefile.sh;
291 make compile;
292 make -j"$JOBS"
293 "
Oliver Smithe3985642019-10-11 16:37:59 +0200294}
295
Oliver Smith01a510a2020-03-18 15:46:41 +0100296run_docker() {
297 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
298 local docker_dir="$(get_testsuite_dir_docker)"
299 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200300 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200301
Oliver Smith01a510a2020-03-18 15:46:41 +0100302 # Skip building docker containers if this already ran
303 if [ -e "$marker" ]; then
304 echo "NOTE: skipping docker container build, because marker exists: $marker"
305 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200306 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100307
308 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200309 export DOCKER_ARGS="\
310 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200311 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200312 -v $hacks:/osmo-ttcn3-hacks:ro \
313 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200314 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100315 ./jenkins.sh
316
317 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200318}
319
Oliver Smith01a510a2020-03-18 15:46:41 +0100320remove_old_logs() {
321 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200322}
323
324collect_logs() {
325 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100326 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200327
328 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200329 for log in *.merged; do
330 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100331 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200332 done
333
334 # Print log path
335 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100336 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200337 echo "---"
338}
339
Oliver Smithe3985642019-10-11 16:37:59 +0200340check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200341check_ttcn3_install
342setup_dir_make
343clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100344clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200345check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200346prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200347prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200348build_osmo_programs
Oliver Smithf3d71202022-10-18 15:43:31 +0200349prepare_docker_testsuite_container
Oliver Smithe3985642019-10-11 16:37:59 +0200350build_testsuite
351remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100352run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200353collect_logs