blob: 6300ff78f30278af7c82fe4b466128d98b215ebb [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" ;;
65 bts) echo "osmo-bsc osmo-bts-trx fake_trx.py trxcon" ;;
66 msc) echo "osmo-stp osmo-msc" ;;
67 pcu-sns) echo "osmo-pcu" ;;
68 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual virtphy" ;;
69 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
79 fake_trx.py) echo "osmocom-bb" ;;
80 osmo-bts-*) echo "osmo-bts" ;;
Oliver Smithf03dfa32021-08-09 09:09:04 +020081 osmo-pcap-*) echo "osmo-pcap" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020082 osmo-stp) echo "libosmo-sccp" ;;
83 trxcon) echo "osmocom-bb" ;;
84 virtphy) echo "osmocom-bb" ;;
85 *) echo "$1" ;;
86 esac
87}
88
89check_ttcn3_install() {
90 if ! command -v ttcn3_compiler > /dev/null; then
91 echo "ERROR: ttcn3_compiler is not installed."
92 echo "Install eclipse-titan from the Osmocom latest repository."
93 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
94 exit 1
95 fi
96}
97
Oliver Smithe3985642019-10-11 16:37:59 +020098setup_dir_make() {
99 cd "$DIR_OSMODEV"
100
101 ( echo "# Generated by ttcn3.sh, do not edit"
102 cat ./3G+2G.deps
103 echo
104 echo "osmo-bts libosmocore libosmo-abis"
105 echo "osmo-pcu libosmocore"
106 # just clone these, building is handled by ttcn3.sh
Oliver Smith01a510a2020-03-18 15:46:41 +0100107 echo "docker-playground"
108 echo "osmo-ttcn3-hacks"
Oliver Smithe3985642019-10-11 16:37:59 +0200109 echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps
110
Oliver Smith0fa204e2021-08-12 15:16:11 +0200111 local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh"
112 docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD"
113
Oliver Smith10da26d2020-01-07 13:17:54 +0100114 ./gen_makefile.py \
115 ttcn3/3G+2G_ttcn3.deps \
116 default.opts \
117 iu.opts \
118 no_systemd.opts \
119 no_doxygen.opts \
120 no_dahdi.opts \
121 no_optimization.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200122 ttcn3/ttcn3.opts \
123 --docker-cmd "$docker_cmd" \
124 --make-dir "$DIR_MAKE" \
125 --no-ldconfig
Oliver Smithe3985642019-10-11 16:37:59 +0200126}
127
128# $1: name of repository (e.g. osmo-ttcn3-hacks)
129clone_repo() {
130 make -C "$DIR_MAKE" ".make.${1}.clone"
131}
132
Oliver Smith01a510a2020-03-18 15:46:41 +0100133# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200134check_dir_testsuite() {
135 local program
136 local config_testsuite
137 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100138 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200139
140 if ! [ -d "$dir_testsuite" ]; then
141 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
142 exit 1
143 fi
144
Oliver Smith01a510a2020-03-18 15:46:41 +0100145 if ! [ -d "$dir_testsuite_docker" ]; then
146 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
147 exit 1
148 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200149
Oliver Smith01a510a2020-03-18 15:46:41 +0100150 # Sanity check for jenkins.sh
151 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
152 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200153 exit 1
154 fi
155}
156
Oliver Smith1b471a92020-04-27 12:00:25 +0200157# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
158# inside the docker container
159prepare_local_bin() {
160 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200161 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200162 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200163 "
164
165 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200166 local script_path_localbin
167 local name_install="$(basename "$script")"
168
169 case "$name_install" in
170 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
171 esac
172
Oliver Smith0fa204e2021-08-12 15:16:11 +0200173 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200174 if [ -x "$script_path_localbin" ]; then
175 continue
176 fi
177
Oliver Smith7531cea2021-06-01 13:29:56 +0200178 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200179 done
180}
181
Oliver Smithe3985642019-10-11 16:37:59 +0200182# Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git).
183# $1: repository
184# $2: path in the repository
185build_osmo_program_subdir() {
186 clone_repo "$1"
187 cd "$DIR_OSMODEV/src/$1/$2"
188 if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then
189 autoreconf -fi
190 fi
191 if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then
192 ./configure
193 fi
194 make -j"$JOBS"
195}
196
197# Use osmo-dev to build a typical Osmocom program, and run a few sanity checks.
198# $1 program
199build_osmo_program_osmodev() {
200 local repo="$(get_program_repo "$program")"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200201 local usr_local_bin="$DIR_USR_LOCAL/bin"
Oliver Smithe3985642019-10-11 16:37:59 +0200202 make -C "$DIR_MAKE" "$repo"
203
Oliver Smith0fa204e2021-08-12 15:16:11 +0200204 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
205 echo "ERROR: program was not installed properly: $program"
206 echo "Expected it to be in path: $PATH_dest"
Oliver Smithe3985642019-10-11 16:37:59 +0200207 exit 1
208 fi
209
Oliver Smithe3985642019-10-11 16:37:59 +0200210 local reference="$DIR_MAKE/.make.$repo.build"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200211 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
Oliver Smithe3985642019-10-11 16:37:59 +0200212 echo "ERROR: $path is outdated!"
213 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?"
Oliver Smithe3985642019-10-11 16:37:59 +0200214 exit 1
215 fi
216}
217
Oliver Smith0fa204e2021-08-12 15:16:11 +0200218prepare_docker_build_container() {
219 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build"
220
221 if [ -e "$marker" ]; then
222 return
223 fi
224
225 make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD"
226 touch "$marker"
227}
228
Oliver Smithe3985642019-10-11 16:37:59 +0200229# Use osmo-dev to build one Osmocom program and its dependencies
230build_osmo_programs() {
231 local program
232 for program in $(get_programs); do
233 case "$program" in
234 fake_trx.py) clone_repo "osmocom-bb" ;;
235 trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;;
236 virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;;
237 *) build_osmo_program_osmodev "$program" ;;
238 esac
239 done
240}
241
242build_testsuite() {
243 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200244
245 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
246 if ! [ -e "$deps_marker" ]; then
247 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
248 touch "$deps_marker"
249 fi
250
Oliver Smithe3985642019-10-11 16:37:59 +0200251 ./gen_links.sh
252 ./regen_makefile.sh
253 make compile
254 make -j"$JOBS"
255}
256
Oliver Smith01a510a2020-03-18 15:46:41 +0100257run_docker() {
258 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
259 local docker_dir="$(get_testsuite_dir_docker)"
260 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200261 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200262
Oliver Smith01a510a2020-03-18 15:46:41 +0100263 # Skip building docker containers if this already ran
264 if [ -e "$marker" ]; then
265 echo "NOTE: skipping docker container build, because marker exists: $marker"
266 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200267 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100268
269 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200270 export DOCKER_ARGS="\
271 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200272 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200273 -v $hacks:/osmo-ttcn3-hacks:ro \
274 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200275 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100276 ./jenkins.sh
277
278 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200279}
280
Oliver Smith01a510a2020-03-18 15:46:41 +0100281remove_old_logs() {
282 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200283}
284
285collect_logs() {
286 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100287 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200288
289 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200290 for log in *.merged; do
291 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100292 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200293 done
294
295 # Print log path
296 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100297 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200298 echo "---"
299}
300
Oliver Smithe3985642019-10-11 16:37:59 +0200301check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200302check_ttcn3_install
303setup_dir_make
304clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100305clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200306check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200307prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200308prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200309build_osmo_programs
310build_testsuite
311remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100312run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200313collect_logs