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