blob: 9f8c1f380fbcbe60c001503bd29b54948e746a67 [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}"
7JOBS="${JOBS:-9}"
8
9check_usage() {
10 if [ -z "$PROJECT" ]; then
11 echo "usage: $(basename $0) PROJECT"
12 echo "example: $(basename $0) hlr"
Oliver Smithe3985642019-10-11 16:37:59 +020013 exit 1
14 fi
15}
16
17# Returns the name of the testsuite binary
18get_testsuite_name() {
19 case "$PROJECT" in
20 bts-*) echo "BTS_Tests" ;;
21 mgw) echo "MGCP_Test" ;;
22 pcu-sns) echo "PCU_Tests" ;;
23 *) echo "${PROJECT_UPPER}_Tests" ;;
24 esac
25}
26
27get_testsuite_dir() {
28 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
29
30 case "$PROJECT" in
31 bts-*) echo "$hacks/bts" ;;
32 pcu-sns) echo "$hacks/pcu" ;;
33 *) echo "$hacks/$PROJECT" ;;
34 esac
35}
36
37get_testsuite_config() {
38 case "$PROJECT" in
39 bts-gprs) echo "BTS_Tests_GPRS.cfg" ;;
40 bts-oml) echo "BTS_Tests_OML.cfg" ;;
41 pcu-sns) echo "PCU_Tests_SNS.cfg" ;;
42 *) echo "$(get_testsuite_name).cfg" ;;
43 esac
44}
45
Oliver Smith01a510a2020-03-18 15:46:41 +010046get_testsuite_dir_docker() {
47 local dp="${DIR_OSMODEV}/src/docker-playground"
48
49 case "$PROJECT" in
50 *) echo "$dp/ttcn3-$PROJECT-test" ;;
51 esac
52}
53
54# Programs that need to be built
Oliver Smithe3985642019-10-11 16:37:59 +020055get_programs() {
56 case "$PROJECT" in
57 bsc) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;;
58 bts) echo "osmo-bsc osmo-bts-trx fake_trx.py trxcon" ;;
59 msc) echo "osmo-stp osmo-msc" ;;
60 pcu-sns) echo "osmo-pcu" ;;
61 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual virtphy" ;;
62 sgsn) echo "osmo-stp osmo-sgsn" ;;
Oliver Smith01401bc2019-11-28 12:19:28 +010063 sip) echo "osmo-sip-connector" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020064 *) echo "osmo-$PROJECT" ;;
65 esac
66}
67
Oliver Smithe3985642019-10-11 16:37:59 +020068# Return the git repository name, which has the source for a specific program.
69# $1: program name
70get_program_repo() {
71 case "$1" in
72 fake_trx.py) echo "osmocom-bb" ;;
73 osmo-bts-*) echo "osmo-bts" ;;
Oliver Smithf03dfa32021-08-09 09:09:04 +020074 osmo-pcap-*) echo "osmo-pcap" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020075 osmo-stp) echo "libosmo-sccp" ;;
76 trxcon) echo "osmocom-bb" ;;
77 virtphy) echo "osmocom-bb" ;;
78 *) echo "$1" ;;
79 esac
80}
81
82check_ttcn3_install() {
83 if ! command -v ttcn3_compiler > /dev/null; then
84 echo "ERROR: ttcn3_compiler is not installed."
85 echo "Install eclipse-titan from the Osmocom latest repository."
86 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
87 exit 1
88 fi
89}
90
Oliver Smithe3985642019-10-11 16:37:59 +020091setup_dir_make() {
92 cd "$DIR_OSMODEV"
93
94 ( echo "# Generated by ttcn3.sh, do not edit"
95 cat ./3G+2G.deps
96 echo
97 echo "osmo-bts libosmocore libosmo-abis"
98 echo "osmo-pcu libosmocore"
99 # just clone these, building is handled by ttcn3.sh
Oliver Smith01a510a2020-03-18 15:46:41 +0100100 echo "docker-playground"
101 echo "osmo-ttcn3-hacks"
Oliver Smithe3985642019-10-11 16:37:59 +0200102 echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps
103
Oliver Smith10da26d2020-01-07 13:17:54 +0100104 ./gen_makefile.py \
105 ttcn3/3G+2G_ttcn3.deps \
106 default.opts \
107 iu.opts \
108 no_systemd.opts \
109 no_doxygen.opts \
110 no_dahdi.opts \
111 no_optimization.opts \
112 ttcn3/ttcn3.opts -I -m "$DIR_MAKE"
Oliver Smithe3985642019-10-11 16:37:59 +0200113}
114
115# $1: name of repository (e.g. osmo-ttcn3-hacks)
116clone_repo() {
117 make -C "$DIR_MAKE" ".make.${1}.clone"
118}
119
Oliver Smith01a510a2020-03-18 15:46:41 +0100120# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200121check_dir_testsuite() {
122 local program
123 local config_testsuite
124 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100125 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200126
127 if ! [ -d "$dir_testsuite" ]; then
128 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
129 exit 1
130 fi
131
Oliver Smith01a510a2020-03-18 15:46:41 +0100132 if ! [ -d "$dir_testsuite_docker" ]; then
133 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
134 exit 1
135 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200136
Oliver Smith01a510a2020-03-18 15:46:41 +0100137 # Sanity check for jenkins.sh
138 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
139 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200140 exit 1
141 fi
142}
143
Oliver Smith1b471a92020-04-27 12:00:25 +0200144# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
145# inside the docker container
146prepare_local_bin() {
147 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200148 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200149 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200150 "
151
152 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200153 local script_path_localbin
154 local name_install="$(basename "$script")"
155
156 case "$name_install" in
157 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
158 esac
159
160 script_path_localbin="/usr/local/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200161 if [ -x "$script_path_localbin" ]; then
162 continue
163 fi
164
Oliver Smith7531cea2021-06-01 13:29:56 +0200165 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200166 done
167}
168
Oliver Smithe3985642019-10-11 16:37:59 +0200169# Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git).
170# $1: repository
171# $2: path in the repository
172build_osmo_program_subdir() {
173 clone_repo "$1"
174 cd "$DIR_OSMODEV/src/$1/$2"
175 if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then
176 autoreconf -fi
177 fi
178 if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then
179 ./configure
180 fi
181 make -j"$JOBS"
182}
183
184# Use osmo-dev to build a typical Osmocom program, and run a few sanity checks.
185# $1 program
186build_osmo_program_osmodev() {
187 local repo="$(get_program_repo "$program")"
188 make -C "$DIR_MAKE" "$repo"
189
190 local path="$(command -v "$program")"
191 if [ -z "$path" ]; then
192 echo "ERROR: program was not installed to PATH: $program"
193 echo "Maybe you need to add /usr/local/bin to PATH?"
194 exit 1
195 fi
196
197 local pathdir="$(dirname "$path")"
198 local reference="$DIR_MAKE/.make.$repo.build"
199 if [ -z "$(find "$pathdir" -name "$program" -newer "$reference")" ]; then
200 echo "ERROR: $path is outdated!"
201 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?"
202 echo "Or the order in PATH is wrong?"
203 exit 1
204 fi
205}
206
207# Use osmo-dev to build one Osmocom program and its dependencies
208build_osmo_programs() {
209 local program
210 for program in $(get_programs); do
211 case "$program" in
212 fake_trx.py) clone_repo "osmocom-bb" ;;
213 trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;;
214 virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;;
215 *) 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 \
250 -v /usr/local:/usr/local:ro \
251 -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 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