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" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 13 | exit 1 |
| 14 | fi |
| 15 | } |
| 16 | |
| 17 | # Returns the name of the testsuite binary |
| 18 | get_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 | |
| 27 | get_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 | |
| 37 | get_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 Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 46 | get_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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 55 | get_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 Smith | 01401bc | 2019-11-28 12:19:28 +0100 | [diff] [blame] | 63 | sip) echo "osmo-sip-connector" ;; |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 64 | *) echo "osmo-$PROJECT" ;; |
| 65 | esac |
| 66 | } |
| 67 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 68 | # Return the git repository name, which has the source for a specific program. |
| 69 | # $1: program name |
| 70 | get_program_repo() { |
| 71 | case "$1" in |
| 72 | fake_trx.py) echo "osmocom-bb" ;; |
| 73 | osmo-bts-*) echo "osmo-bts" ;; |
Oliver Smith | f03dfa3 | 2021-08-09 09:09:04 +0200 | [diff] [blame] | 74 | osmo-pcap-*) echo "osmo-pcap" ;; |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 75 | osmo-stp) echo "libosmo-sccp" ;; |
| 76 | trxcon) echo "osmocom-bb" ;; |
| 77 | virtphy) echo "osmocom-bb" ;; |
| 78 | *) echo "$1" ;; |
| 79 | esac |
| 80 | } |
| 81 | |
| 82 | check_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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 91 | setup_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 Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 100 | echo "docker-playground" |
| 101 | echo "osmo-ttcn3-hacks" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 102 | echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps |
| 103 | |
Oliver Smith | 10da26d | 2020-01-07 13:17:54 +0100 | [diff] [blame] | 104 | ./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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | # $1: name of repository (e.g. osmo-ttcn3-hacks) |
| 116 | clone_repo() { |
| 117 | make -C "$DIR_MAKE" ".make.${1}.clone" |
| 118 | } |
| 119 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 120 | # Require testsuite dir and docker-playground dir |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 121 | check_dir_testsuite() { |
| 122 | local program |
| 123 | local config_testsuite |
| 124 | local dir_testsuite="$(get_testsuite_dir)" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 125 | local dir_testsuite_docker="$(get_testsuite_dir_docker)" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 126 | |
| 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 Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 132 | 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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 136 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 137 | # 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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 140 | exit 1 |
| 141 | fi |
| 142 | } |
| 143 | |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 144 | # 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 |
| 146 | prepare_local_bin() { |
| 147 | local scripts=" |
Oliver Smith | 7531cea | 2021-06-01 13:29:56 +0200 | [diff] [blame] | 148 | ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh |
Oliver Smith | 6f7954e | 2021-06-01 14:14:06 +0200 | [diff] [blame] | 149 | ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 150 | " |
| 151 | |
| 152 | for script in $scripts; do |
Oliver Smith | 6f7954e | 2021-06-01 14:14:06 +0200 | [diff] [blame] | 153 | 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 Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 161 | if [ -x "$script_path_localbin" ]; then |
| 162 | continue |
| 163 | fi |
| 164 | |
Oliver Smith | 7531cea | 2021-06-01 13:29:56 +0200 | [diff] [blame] | 165 | install -v -Dm755 "$script" "$script_path_localbin" |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 166 | done |
| 167 | } |
| 168 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 169 | # 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 |
| 172 | build_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 |
| 186 | build_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 |
| 208 | build_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 | |
| 220 | build_testsuite() { |
| 221 | cd "$(get_testsuite_dir)" |
Oliver Smith | 389dafb | 2020-04-27 14:33:15 +0200 | [diff] [blame] | 222 | |
| 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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 229 | ./gen_links.sh |
| 230 | ./regen_makefile.sh |
| 231 | make compile |
| 232 | make -j"$JOBS" |
| 233 | } |
| 234 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 235 | run_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 Smith | f3eb0ba | 2021-08-10 15:41:47 +0200 | [diff] [blame] | 239 | local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 240 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 241 | # 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 Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 245 | fi |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 246 | |
| 247 | cd "$(get_testsuite_dir_docker)" |
Oliver Smith | bfe5929 | 2021-08-12 11:15:40 +0200 | [diff] [blame^] | 248 | 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 Smith | 6b84b46 | 2021-07-09 10:12:18 +0200 | [diff] [blame] | 253 | export NO_LIST_OSMO_PACKAGES=1 |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 254 | ./jenkins.sh |
| 255 | |
| 256 | touch "$marker" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 259 | remove_old_logs() { |
| 260 | sudo rm -rf /tmp/tmp.* 2>/dev/null |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | collect_logs() { |
| 264 | # Merge and move logs |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 265 | cd /tmp/logs/*-tester |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 266 | |
| 267 | # Format logs |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 268 | for log in *.merged; do |
| 269 | ttcn3_logformat -o "${log}.log" "$log" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 270 | sudo rm "$log" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 271 | done |
| 272 | |
| 273 | # Print log path |
| 274 | echo "---" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 275 | echo "Logs: /tmp/logs" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 276 | echo "---" |
| 277 | } |
| 278 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 279 | check_usage |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 280 | check_ttcn3_install |
| 281 | setup_dir_make |
| 282 | clone_repo "osmo-ttcn3-hacks" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 283 | clone_repo "docker-playground" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 284 | check_dir_testsuite |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 285 | prepare_local_bin |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 286 | build_osmo_programs |
| 287 | build_testsuite |
| 288 | remove_old_logs |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 289 | run_docker |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 290 | collect_logs |