blob: 20d61842b65a2c8e93f5b1dabf28b3cdfbff8ded [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
98 ( echo "# Generated by ttcn3.sh, do not edit"
99 cat ./3G+2G.deps
100 echo
101 echo "osmo-bts libosmocore libosmo-abis"
102 echo "osmo-pcu libosmocore"
103 # just clone these, building is handled by ttcn3.sh
Oliver Smith01a510a2020-03-18 15:46:41 +0100104 echo "docker-playground"
Oliver Smith855d66e2021-08-12 16:58:26 +0200105 echo "osmo-ttcn3-hacks" ) > ttcn3/3G+2G_ttcn3.deps
Oliver Smithe3985642019-10-11 16:37:59 +0200106
Oliver Smith0fa204e2021-08-12 15:16:11 +0200107 local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh"
108 docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD"
109
Oliver Smith10da26d2020-01-07 13:17:54 +0100110 ./gen_makefile.py \
111 ttcn3/3G+2G_ttcn3.deps \
112 default.opts \
113 iu.opts \
114 no_systemd.opts \
115 no_doxygen.opts \
116 no_dahdi.opts \
117 no_optimization.opts \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200118 ttcn3/ttcn3.opts \
119 --docker-cmd "$docker_cmd" \
120 --make-dir "$DIR_MAKE" \
121 --no-ldconfig
Oliver Smithe3985642019-10-11 16:37:59 +0200122}
123
124# $1: name of repository (e.g. osmo-ttcn3-hacks)
125clone_repo() {
126 make -C "$DIR_MAKE" ".make.${1}.clone"
127}
128
Oliver Smith01a510a2020-03-18 15:46:41 +0100129# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200130check_dir_testsuite() {
131 local program
132 local config_testsuite
133 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100134 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200135
136 if ! [ -d "$dir_testsuite" ]; then
137 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
138 exit 1
139 fi
140
Oliver Smith01a510a2020-03-18 15:46:41 +0100141 if ! [ -d "$dir_testsuite_docker" ]; then
142 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
143 exit 1
144 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200145
Oliver Smith01a510a2020-03-18 15:46:41 +0100146 # Sanity check for jenkins.sh
147 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
148 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200149 exit 1
150 fi
151}
152
Oliver Smith1b471a92020-04-27 12:00:25 +0200153# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
154# inside the docker container
155prepare_local_bin() {
156 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200157 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200158 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200159 "
160
161 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200162 local script_path_localbin
163 local name_install="$(basename "$script")"
164
165 case "$name_install" in
166 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
167 esac
168
Oliver Smith0fa204e2021-08-12 15:16:11 +0200169 script_path_localbin="$DIR_USR_LOCAL/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200170 if [ -x "$script_path_localbin" ]; then
171 continue
172 fi
173
Oliver Smith7531cea2021-06-01 13:29:56 +0200174 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200175 done
176}
177
Oliver Smithe3985642019-10-11 16:37:59 +0200178# Use osmo-dev to build a typical Osmocom program, and run a few sanity checks.
179# $1 program
180build_osmo_program_osmodev() {
181 local repo="$(get_program_repo "$program")"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200182 local usr_local_bin="$DIR_USR_LOCAL/bin"
Oliver Smithe3985642019-10-11 16:37:59 +0200183 make -C "$DIR_MAKE" "$repo"
184
Oliver Smith0fa204e2021-08-12 15:16:11 +0200185 if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then
186 echo "ERROR: program was not installed properly: $program"
187 echo "Expected it to be in path: $PATH_dest"
Oliver Smithe3985642019-10-11 16:37:59 +0200188 exit 1
189 fi
190
Oliver Smithe3985642019-10-11 16:37:59 +0200191 local reference="$DIR_MAKE/.make.$repo.build"
Oliver Smith0fa204e2021-08-12 15:16:11 +0200192 if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then
Oliver Smithe3985642019-10-11 16:37:59 +0200193 echo "ERROR: $path is outdated!"
194 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 +0200195 exit 1
196 fi
197}
198
Oliver Smith0fa204e2021-08-12 15:16:11 +0200199prepare_docker_build_container() {
200 local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build"
201
202 if [ -e "$marker" ]; then
203 return
204 fi
205
206 make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD"
207 touch "$marker"
208}
209
Oliver Smithe3985642019-10-11 16:37:59 +0200210# Use osmo-dev to build one Osmocom program and its dependencies
211build_osmo_programs() {
212 local program
213 for program in $(get_programs); do
214 case "$program" in
Oliver Smithe3985642019-10-11 16:37:59 +0200215 *) build_osmo_program_osmodev "$program" ;;
216 esac
217 done
218}
219
220build_testsuite() {
221 cd "$(get_testsuite_dir)"
Oliver Smith389dafb2020-04-27 14:33:15 +0200222
223 local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps"
224 if ! [ -e "$deps_marker" ]; then
225 make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS"
226 touch "$deps_marker"
227 fi
228
Oliver Smithe3985642019-10-11 16:37:59 +0200229 ./gen_links.sh
230 ./regen_makefile.sh
231 make compile
232 make -j"$JOBS"
233}
234
Oliver Smith01a510a2020-03-18 15:46:41 +0100235run_docker() {
236 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
237 local docker_dir="$(get_testsuite_dir_docker)"
238 local docker_name="$(basename "$docker_dir")"
Oliver Smithf3eb0ba2021-08-10 15:41:47 +0200239 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX"
Oliver Smithe3985642019-10-11 16:37:59 +0200240
Oliver Smith01a510a2020-03-18 15:46:41 +0100241 # Skip building docker containers if this already ran
242 if [ -e "$marker" ]; then
243 echo "NOTE: skipping docker container build, because marker exists: $marker"
244 export NO_DOCKER_IMAGE_BUILD=1
Oliver Smithe3985642019-10-11 16:37:59 +0200245 fi
Oliver Smith01a510a2020-03-18 15:46:41 +0100246
247 cd "$(get_testsuite_dir_docker)"
Oliver Smithbfe59292021-08-12 11:15:40 +0200248 export DOCKER_ARGS="\
249 -e LD_LIBRARY_PATH=/usr/local/lib \
Oliver Smith0fa204e2021-08-12 15:16:11 +0200250 -v "$DIR_USR_LOCAL":/usr/local:ro \
Oliver Smithbfe59292021-08-12 11:15:40 +0200251 -v $hacks:/osmo-ttcn3-hacks:ro \
252 "
Oliver Smith6b84b462021-07-09 10:12:18 +0200253 export NO_LIST_OSMO_PACKAGES=1
Oliver Smith01a510a2020-03-18 15:46:41 +0100254 ./jenkins.sh
255
256 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200257}
258
Oliver Smith01a510a2020-03-18 15:46:41 +0100259remove_old_logs() {
260 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200261}
262
263collect_logs() {
264 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100265 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200266
267 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200268 for log in *.merged; do
269 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100270 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200271 done
272
273 # Print log path
274 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100275 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200276 echo "---"
277}
278
Oliver Smithe3985642019-10-11 16:37:59 +0200279check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200280check_ttcn3_install
281setup_dir_make
282clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100283clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200284check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200285prepare_local_bin
Oliver Smith0fa204e2021-08-12 15:16:11 +0200286prepare_docker_build_container
Oliver Smithe3985642019-10-11 16:37:59 +0200287build_osmo_programs
288build_testsuite
289remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100290run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200291collect_logs