blob: 19019b3b766d79c33427b849a461edf0659aa0d0 [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" ;;
74 osmo-stp) echo "libosmo-sccp" ;;
75 trxcon) echo "osmocom-bb" ;;
76 virtphy) echo "osmocom-bb" ;;
77 *) echo "$1" ;;
78 esac
79}
80
81check_ttcn3_install() {
82 if ! command -v ttcn3_compiler > /dev/null; then
83 echo "ERROR: ttcn3_compiler is not installed."
84 echo "Install eclipse-titan from the Osmocom latest repository."
85 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
86 exit 1
87 fi
88}
89
Oliver Smithe3985642019-10-11 16:37:59 +020090setup_dir_make() {
91 cd "$DIR_OSMODEV"
92
93 ( echo "# Generated by ttcn3.sh, do not edit"
94 cat ./3G+2G.deps
95 echo
96 echo "osmo-bts libosmocore libosmo-abis"
97 echo "osmo-pcu libosmocore"
98 # just clone these, building is handled by ttcn3.sh
Oliver Smith01a510a2020-03-18 15:46:41 +010099 echo "docker-playground"
100 echo "osmo-ttcn3-hacks"
Oliver Smithe3985642019-10-11 16:37:59 +0200101 echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps
102
Oliver Smith10da26d2020-01-07 13:17:54 +0100103 ./gen_makefile.py \
104 ttcn3/3G+2G_ttcn3.deps \
105 default.opts \
106 iu.opts \
107 no_systemd.opts \
108 no_doxygen.opts \
109 no_dahdi.opts \
110 no_optimization.opts \
111 ttcn3/ttcn3.opts -I -m "$DIR_MAKE"
Oliver Smithe3985642019-10-11 16:37:59 +0200112}
113
114# $1: name of repository (e.g. osmo-ttcn3-hacks)
115clone_repo() {
116 make -C "$DIR_MAKE" ".make.${1}.clone"
117}
118
Oliver Smith01a510a2020-03-18 15:46:41 +0100119# Require testsuite dir and docker-playground dir
Oliver Smithe3985642019-10-11 16:37:59 +0200120check_dir_testsuite() {
121 local program
122 local config_testsuite
123 local dir_testsuite="$(get_testsuite_dir)"
Oliver Smith01a510a2020-03-18 15:46:41 +0100124 local dir_testsuite_docker="$(get_testsuite_dir_docker)"
Oliver Smithe3985642019-10-11 16:37:59 +0200125
126 if ! [ -d "$dir_testsuite" ]; then
127 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
128 exit 1
129 fi
130
Oliver Smith01a510a2020-03-18 15:46:41 +0100131 if ! [ -d "$dir_testsuite_docker" ]; then
132 echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?"
133 exit 1
134 fi
Oliver Smithe3985642019-10-11 16:37:59 +0200135
Oliver Smith01a510a2020-03-18 15:46:41 +0100136 # Sanity check for jenkins.sh
137 if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then
138 echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!"
Oliver Smithe3985642019-10-11 16:37:59 +0200139 exit 1
140 fi
141}
142
Oliver Smith1b471a92020-04-27 12:00:25 +0200143# Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin
144# inside the docker container
145prepare_local_bin() {
146 local scripts="
Oliver Smith7531cea2021-06-01 13:29:56 +0200147 ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh
Oliver Smith6f7954e2021-06-01 14:14:06 +0200148 ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh
Oliver Smith1b471a92020-04-27 12:00:25 +0200149 "
150
151 for script in $scripts; do
Oliver Smith6f7954e2021-06-01 14:14:06 +0200152 local script_path_localbin
153 local name_install="$(basename "$script")"
154
155 case "$name_install" in
156 ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;;
157 esac
158
159 script_path_localbin="/usr/local/bin/$name_install"
Oliver Smith1b471a92020-04-27 12:00:25 +0200160 if [ -x "$script_path_localbin" ]; then
161 continue
162 fi
163
Oliver Smith7531cea2021-06-01 13:29:56 +0200164 install -v -Dm755 "$script" "$script_path_localbin"
Oliver Smith1b471a92020-04-27 12:00:25 +0200165 done
166}
167
Oliver Smithe3985642019-10-11 16:37:59 +0200168# Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git).
169# $1: repository
170# $2: path in the repository
171build_osmo_program_subdir() {
172 clone_repo "$1"
173 cd "$DIR_OSMODEV/src/$1/$2"
174 if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then
175 autoreconf -fi
176 fi
177 if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then
178 ./configure
179 fi
180 make -j"$JOBS"
181}
182
183# Use osmo-dev to build a typical Osmocom program, and run a few sanity checks.
184# $1 program
185build_osmo_program_osmodev() {
186 local repo="$(get_program_repo "$program")"
187 make -C "$DIR_MAKE" "$repo"
188
189 local path="$(command -v "$program")"
190 if [ -z "$path" ]; then
191 echo "ERROR: program was not installed to PATH: $program"
192 echo "Maybe you need to add /usr/local/bin to PATH?"
193 exit 1
194 fi
195
196 local pathdir="$(dirname "$path")"
197 local reference="$DIR_MAKE/.make.$repo.build"
198 if [ -z "$(find "$pathdir" -name "$program" -newer "$reference")" ]; then
199 echo "ERROR: $path is outdated!"
200 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?"
201 echo "Or the order in PATH is wrong?"
202 exit 1
203 fi
204}
205
206# Use osmo-dev to build one Osmocom program and its dependencies
207build_osmo_programs() {
208 local program
209 for program in $(get_programs); do
210 case "$program" in
211 fake_trx.py) clone_repo "osmocom-bb" ;;
212 trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;;
213 virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;;
214 *) build_osmo_program_osmodev "$program" ;;
215 esac
216 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")"
238 local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name"
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)"
247 export DOCKER_ARGS="-v /usr/local:/usr/local:ro -v $hacks:/osmo-ttcn3-hacks:ro"
248 ./jenkins.sh
249
250 touch "$marker"
Oliver Smithe3985642019-10-11 16:37:59 +0200251}
252
Oliver Smith01a510a2020-03-18 15:46:41 +0100253remove_old_logs() {
254 sudo rm -rf /tmp/tmp.* 2>/dev/null
Oliver Smithe3985642019-10-11 16:37:59 +0200255}
256
257collect_logs() {
258 # Merge and move logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100259 cd /tmp/logs/*-tester
Oliver Smithe3985642019-10-11 16:37:59 +0200260
261 # Format logs
Oliver Smithe3985642019-10-11 16:37:59 +0200262 for log in *.merged; do
263 ttcn3_logformat -o "${log}.log" "$log"
Oliver Smith01a510a2020-03-18 15:46:41 +0100264 sudo rm "$log"
Oliver Smithe3985642019-10-11 16:37:59 +0200265 done
266
267 # Print log path
268 echo "---"
Oliver Smith01a510a2020-03-18 15:46:41 +0100269 echo "Logs: /tmp/logs"
Oliver Smithe3985642019-10-11 16:37:59 +0200270 echo "---"
271}
272
Oliver Smithe3985642019-10-11 16:37:59 +0200273check_usage
Oliver Smithe3985642019-10-11 16:37:59 +0200274check_ttcn3_install
275setup_dir_make
276clone_repo "osmo-ttcn3-hacks"
Oliver Smith01a510a2020-03-18 15:46:41 +0100277clone_repo "docker-playground"
Oliver Smithe3985642019-10-11 16:37:59 +0200278check_dir_testsuite
Oliver Smith1b471a92020-04-27 12:00:25 +0200279prepare_local_bin
Oliver Smithe3985642019-10-11 16:37:59 +0200280build_osmo_programs
281build_testsuite
282remove_old_logs
Oliver Smith01a510a2020-03-18 15:46:41 +0100283run_docker
Oliver Smithe3985642019-10-11 16:37:59 +0200284collect_logs