blob: ab82fc7bde7d0526769995d597bbf10e7ebd03ba [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 \
Oliver Smith6c7fed82021-10-04 13:30:31 +0200113 --no-make-check \
114 --auto-distclean
Oliver Smithe3985642019-10-11 16:37:59 +0200115}
116
117# $1: name of repository (e.g. osmo-ttcn3-hacks)
118clone_repo() {
Oliver Smith5f611c72021-08-26 18:03:17 +0200119 if ! [ -e "$DIR_OSMODEV/ttcn3/make/.make.${1}.clone" ]; then
120 make -C "$DIR_MAKE" ".make.${1}.clone"
121 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200122}
123
Oliver Smith01a510a2020-03-18 15:46:41 +0100124# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200125check_dir_testsuite() {
126 local program
127 local config_testsuite
128 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100129 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200130
131 if ! [ -d "$dir_testsuite" ]; then
132 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
133 exit 1
134 fi
135
Oliver Smith01a510a2020-03-18 15:46:41 +0100136 if ! [ -d "$dir_testsuite_docker" ]; then
137 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
138 exit 1
139 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200140
Oliver Smith01a510a2020-03-18 15:46:41 +0100141 # Sanity check for jenkins.sh
142 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
143 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200144 exit 1
145 fi
146}
147
Oliver Smith1b471a92020-04-27 12:00:25 +0200148# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
149# inside the docker container
150prepare_local_bin() {
151 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200152 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200153 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200154 "
155
156 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200157 local script_path_localbin
158 local name_install="$(basename "$script")"
159
160 case "$name_install" in
161 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
162 esac
163
Oliver Smith0fa204e2021-08-12 15:16:11 +0200164 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200165 if [ -x "$script_path_localbin" ]; then
166 continue
167 fi
168
Oliver Smith7531cea2021-06-01 13:29:56 +0200169 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200170 done
171}
172
Oliver Smith0fa204e2021-08-12 15:16:11 +0200173prepare_docker_build_container() {
174 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build"
175
176 if [ -e "$marker" ]; then
177 return
178 fi
179
180 make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD"
181 touch "$marker"
182}
183
Oliver Smithe3985642019-10-11 16:37:59 +0200184# Use osmo-dev to build one Osmocom program and its dependencies
185build_osmo_programs() {
186 local program
Oliver Smith8d8ddf42021-08-26 17:56:02 +0200187 local programs="$(get_programs)"
188 local make_args="-C $DIR_MAKE"
189
190 for program in $programs; do
191 local repo="$(get_program_repo "$program")"
192 make_args="$make_args $repo"
193 done
194
195 set -x
196 make $make_args
197 set +x
198
199 for program in $programs; do
200 local repo="$(get_program_repo "$program")"
201 local usr_local_bin="$DIR_USR_LOCAL/bin"
202
203 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
204 echo "ERROR: program was not installed properly: $program"
205 echo "Expected it to be in path: $PATH_dest"
206 exit 1
207 fi
208
209 local reference="$DIR_MAKE/.make.$repo.build"
210 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
211 echo "ERROR: $path is outdated!"
212 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs" \
213 "$program?"
214 exit 1
215 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200216 done
217}
218
219build_testsuite() {
220 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200221
222 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
223 if ! [ -e "$deps_marker" ]; then
224 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
225 touch "$deps_marker"
226 fi
227
Oliver Smithe3985642019-10-11 16:37:59 +0200228 ./gen_links.sh
229 ./regen_makefile.sh
230 make compile
231 make -j"$JOBS"
232}
233
Oliver Smith01a510a2020-03-18 15:46:41 +0100234run_docker() {
235 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
236 local docker_dir="$(get_testsuite_dir_docker)"
237 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200238 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200239
Oliver Smith01a510a2020-03-18 15:46:41 +0100240 # Skip building docker containers if this already ran
241 if [ -e "$marker" ]; then
242 echo "NOTE: skipping docker container build, because marker exists: $marker"
243 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200244 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100245
246 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200247 export DOCKER_ARGS="\
248 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200249 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200250 -v $hacks:/osmo-ttcn3-hacks:ro \
251 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200252 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100253 ./jenkins.sh
254
255 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200256}
257
Oliver Smith01a510a2020-03-18 15:46:41 +0100258remove_old_logs() {
259 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200260}
261
262collect_logs() {
263 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100264 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200265
266 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200267 for log in *.merged; do
268 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100269 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200270 done
271
272 # Print log path
273 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100274 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200275 echo "---"
276}
277
Oliver Smithe3985642019-10-11 16:37:59 +0200278check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200279check_ttcn3_install
280setup_dir_make
281clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100282clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200283check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200284prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200285prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200286build_osmo_programs
287build_testsuite
288remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100289run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200290collect_logs