blob: f9297b7d7bf46a5838eca2fa82832f557aabe5e9 [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 Smith01401bc2019-11-28 12:19:28 +010013 echo "known working projects: hlr, mgw, msc, pcu, pcu-sns, sip, sgsn"
Oliver Smithe3985642019-10-11 16:37:59 +020014 echo "wip: bts, bts-oml"
15 echo ""
16 echo "notes (see docker-playground.git/ttcn3-*/jenkins.sh):"
17 echo "- bts: classic test suite with BSC for OML and trxcon+fake_trx"
18 echo "- bts-oml: OML tests (without BSC)"
19 exit 1
20 fi
21}
22
23# Returns the name of the testsuite binary
24get_testsuite_name() {
25 case "$PROJECT" in
26 bts-*) echo "BTS_Tests" ;;
27 mgw) echo "MGCP_Test" ;;
28 pcu-sns) echo "PCU_Tests" ;;
29 *) echo "${PROJECT_UPPER}_Tests" ;;
30 esac
31}
32
33get_testsuite_dir() {
34 local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks"
35
36 case "$PROJECT" in
37 bts-*) echo "$hacks/bts" ;;
38 pcu-sns) echo "$hacks/pcu" ;;
39 *) echo "$hacks/$PROJECT" ;;
40 esac
41}
42
43get_testsuite_config() {
44 case "$PROJECT" in
45 bts-gprs) echo "BTS_Tests_GPRS.cfg" ;;
46 bts-oml) echo "BTS_Tests_OML.cfg" ;;
47 pcu-sns) echo "PCU_Tests_SNS.cfg" ;;
48 *) echo "$(get_testsuite_name).cfg" ;;
49 esac
50}
51
52# Programs that need to be built, launched and killed. To add programs to only one of the steps, modify the appropriate
53# function below (build_osmo_programs, run_osmo_programs, kill_osmo_programs).
54get_programs() {
55 case "$PROJECT" in
56 bsc) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;;
57 bts) echo "osmo-bsc osmo-bts-trx fake_trx.py trxcon" ;;
58 msc) echo "osmo-stp osmo-msc" ;;
59 pcu-sns) echo "osmo-pcu" ;;
60 pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual virtphy" ;;
61 sgsn) echo "osmo-stp osmo-sgsn" ;;
Oliver Smith01401bc2019-11-28 12:19:28 +010062 sip) echo "osmo-sip-connector" ;;
Oliver Smithe3985642019-10-11 16:37:59 +020063 *) echo "osmo-$PROJECT" ;;
64 esac
65}
66
67# $1: program name
68get_program_config() {
69 case "$1" in
70 fake_trx.py) ;; # no config
71 osmo-bts-*) echo "osmo-bts.cfg" ;;
72 osmo-pcu)
73 if [ "$PROJECT" = "pcu-sns" ]; then
74 echo "osmo-pcu-sns.cfg"
75 else
76 echo "osmo-pcu.cfg"
77 fi
78 ;;
79 trxcon) ;; # no config
80 virtphy) ;; # no config
81 *) echo "$1.cfg" ;;
82 esac
83}
84
85# Return the git repository name, which has the source for a specific program.
86# $1: program name
87get_program_repo() {
88 case "$1" in
89 fake_trx.py) echo "osmocom-bb" ;;
90 osmo-bts-*) echo "osmo-bts" ;;
91 osmo-stp) echo "libosmo-sccp" ;;
92 trxcon) echo "osmocom-bb" ;;
93 virtphy) echo "osmocom-bb" ;;
94 *) echo "$1" ;;
95 esac
96}
97
98check_ttcn3_install() {
99 if ! command -v ttcn3_compiler > /dev/null; then
100 echo "ERROR: ttcn3_compiler is not installed."
101 echo "Install eclipse-titan from the Osmocom latest repository."
102 echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites"
103 exit 1
104 fi
105}
106
107kill_osmo_programs() {
108 programs="$(get_programs)"
109
110 # Kill wrappers first
111 for program in $programs; do
112 case "$program" in
113 osmo-pcu) killall osmo-pcu-respawn.sh || true ;;
114 osmo-bts-trx) killall osmo-bts-trx-respawn.sh || true ;;
115 fake_trx.py) killall fake_trx.sh || true ;;
116 esac
117 done
118
119 killall $programs || true
120}
121
122setup_dir_make() {
123 cd "$DIR_OSMODEV"
124
125 ( echo "# Generated by ttcn3.sh, do not edit"
126 cat ./3G+2G.deps
127 echo
128 echo "osmo-bts libosmocore libosmo-abis"
129 echo "osmo-pcu libosmocore"
130 # just clone these, building is handled by ttcn3.sh
131 echo "osmo-ttcn3-hacks"
132 echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps
133
Oliver Smith10da26d2020-01-07 13:17:54 +0100134 ./gen_makefile.py \
135 ttcn3/3G+2G_ttcn3.deps \
136 default.opts \
137 iu.opts \
138 no_systemd.opts \
139 no_doxygen.opts \
140 no_dahdi.opts \
141 no_optimization.opts \
142 ttcn3/ttcn3.opts -I -m "$DIR_MAKE"
Oliver Smithe3985642019-10-11 16:37:59 +0200143}
144
145# $1: name of repository (e.g. osmo-ttcn3-hacks)
146clone_repo() {
147 make -C "$DIR_MAKE" ".make.${1}.clone"
148}
149
150# Require testsuite dir, with testsuite and all program configs
151check_dir_testsuite() {
152 local program
153 local config_testsuite
154 local dir_testsuite="$(get_testsuite_dir)"
155
156 if ! [ -d "$dir_testsuite" ]; then
157 echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite"
158 exit 1
159 fi
160
161 for program in $(get_programs); do
162 local config="$(get_program_config "$program")"
163 if [ -z "$config" ]; then
164 continue
165 fi
166 config="$dir_testsuite/$config"
167 if ! [ -e "$config" ]; then
168 echo "ERROR: config not found: $config"
169 echo "Copy it from docker-playground.git, and change IPs to 127.0.0.*."
170 echo "Make sure that everything works, then submit a patch with the config."
171 echo "If $program's config has a different name or is not needed at all, edit"
172 echo "get_program_config() in ttcn3.sh."
173 exit 1
174 fi
175 done
176
177 config_testsuite="$dir_testsuite/$(get_testsuite_config)"
178 if ! [ -e "$config_testsuite" ]; then
179 echo "ERROR: testsuite config not found: $config_testsuite"
180 echo "Copy it from docker-playground.git, change the paths to be relative and submit it as patch."
181 echo "If $program's testsuite has a different name, edit get_testsuite_name() in ttcn3.sh."
182 exit 1
183 fi
184}
185
186# Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git).
187# $1: repository
188# $2: path in the repository
189build_osmo_program_subdir() {
190 clone_repo "$1"
191 cd "$DIR_OSMODEV/src/$1/$2"
192 if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then
193 autoreconf -fi
194 fi
195 if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then
196 ./configure
197 fi
198 make -j"$JOBS"
199}
200
201# Use osmo-dev to build a typical Osmocom program, and run a few sanity checks.
202# $1 program
203build_osmo_program_osmodev() {
204 local repo="$(get_program_repo "$program")"
205 make -C "$DIR_MAKE" "$repo"
206
207 local path="$(command -v "$program")"
208 if [ -z "$path" ]; then
209 echo "ERROR: program was not installed to PATH: $program"
210 echo "Maybe you need to add /usr/local/bin to PATH?"
211 exit 1
212 fi
213
214 local pathdir="$(dirname "$path")"
215 local reference="$DIR_MAKE/.make.$repo.build"
216 if [ -z "$(find "$pathdir" -name "$program" -newer "$reference")" ]; then
217 echo "ERROR: $path is outdated!"
218 echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?"
219 echo "Or the order in PATH is wrong?"
220 exit 1
221 fi
222}
223
224# Use osmo-dev to build one Osmocom program and its dependencies
225build_osmo_programs() {
226 local program
227 for program in $(get_programs); do
228 case "$program" in
229 fake_trx.py) clone_repo "osmocom-bb" ;;
230 trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;;
231 virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;;
232 *) build_osmo_program_osmodev "$program" ;;
233 esac
234 done
235}
236
237build_testsuite() {
238 cd "$(get_testsuite_dir)"
239 ./gen_links.sh
240 ./regen_makefile.sh
241 make compile
242 make -j"$JOBS"
243}
244
245remove_old_logs() {
246 cd "$(get_testsuite_dir)"
247 rm *.log *.merged 2> /dev/null || true
248}
249
250prepare_dir_output() {
251 local program
252 local dir_testsuite="$(get_testsuite_dir)"
253
254 rm -r "$DIR_OUTPUT"/* 2> /dev/null || true
255 mkdir -p "$DIR_OUTPUT"
256
257 for program in $(get_programs); do
258 local config="$(get_program_config "$program")"
259 if [ -n "$config" ]; then
260 cp "$dir_testsuite/$config" "$DIR_OUTPUT"
261 fi
262 done
263}
264
265# $1: log name
266# $2: command to run
267run_osmo_program() {
268 local pid
269 local log="$1"
270 shift
271
272 echo "Starting ($log): $@"
273 "$@" > "$log" 2>&1 &
274 pid="$!"
275
276 sleep 0.5
277 if ! kill -0 "$pid" 2> /dev/null; then
278 echo "ERROR: failed to start: $@"
279 cat "$log"
280 exit 1
281 fi
282}
283
284run_osmo_programs() {
285 local program
286 local osmocom_bb="$DIR_OSMODEV/src/osmocom-bb"
287 local wrappers="$DIR_OSMODEV/ttcn3/wrappers"
288
289 cd "$DIR_OUTPUT"
290 for program in $(get_programs); do
291 case "$program" in
292 fake_trx.py)
293 run_osmo_program "fake_trx.log" \
294 "$wrappers/fake_trx.sh" \
295 --log-level DEBUG \
296 -b 127.0.0.21 \
297 -R 127.0.0.20 \
298 -r 127.0.0.22
299 ;;
300 osmo-bts-omldummy)
301 for i in $(seq 0 2); do
302 run_osmo_program "osmo-bts-$i.log" osmo-bts-omldummy 127.0.0.1 $((i + 1234)) 1
303 done
304 ;;
305 osmo-bts-trx)
306 run_osmo_program "$program.log" \
307 "$wrappers/osmo-bts-trx-respawn.sh" -i 127.0.0.10
308 ;;
309 osmo-pcu)
310 run_osmo_program "$program.log" "$wrappers/osmo-pcu-respawn.sh" \
311 -c "$(get_program_config osmo-pcu)"
312 ;;
313 trxcon)
314 run_osmo_program "$program.log" \
315 "$osmocom_bb/src/host/trxcon/trxcon" \
316 trxcon -i 127.0.0.21 \
317 -s /tmp/osmocom_l2
318 ;;
319 virtphy)
320 run_osmo_program "$program.log" "$osmocom_bb/src/host/virt_phy/src/virtphy" \
321 -s /tmp/osmocom_l2
322 ;;
323 *)
324 run_osmo_program "$program.log" "$program"
325 ;;
326 esac
327 done
328}
329
330run_testsuite() {
331 local testsuite="$(get_testsuite_name)"
332 local cfg="$(get_testsuite_config)"
333
334 cd "$(get_testsuite_dir)"
335 ../start-testsuite.sh "$testsuite" "$cfg" 2>&1 | tee "$DIR_OUTPUT/ttcn3_stdout.log"
336}
337
338collect_logs() {
339 # Merge and move logs
340 cd "$(get_testsuite_dir)"
341 ../log_merge.sh $(get_testsuite_name) --rm
342 if ! mv *.merged "$DIR_OUTPUT"; then
343 echo "---"
344 echo "ERROR: no logs generated! Invalid test names in $(get_testsuite_config)?"
345 echo "---"
346 exit 1
347 fi
348
349 # Format logs
350 cd "$DIR_OUTPUT"
351 for log in *.merged; do
352 ttcn3_logformat -o "${log}.log" "$log"
353 rm "$log"
354 done
355
356 # Print log path
357 echo "---"
358 echo "Logs: $DIR_OUTPUT"
359 echo "---"
360}
361
362# Tell glibc to print segfault output to stderr (OS#4212)
363export LIBC_FATAL_STDERR_=1
364
365check_usage
366kill_osmo_programs
367check_ttcn3_install
368setup_dir_make
369clone_repo "osmo-ttcn3-hacks"
370check_dir_testsuite
371build_osmo_programs
372build_testsuite
373remove_old_logs
374prepare_dir_output
375run_osmo_programs
376run_testsuite
377kill_osmo_programs
378collect_logs