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}" |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 7 | DIR_USR_LOCAL="$DIR_OSMODEV/ttcn3/usr_local" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 8 | JOBS="${JOBS:-9}" |
| 9 | |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 10 | # Osmocom libraries and programs relevant for the current testsuite will be |
| 11 | # built in this container. It must have all build dependencies available and |
| 12 | # be based on the same distribution that master-* containers are based on, so |
| 13 | # there are no incompatibilities with shared libraries. |
| 14 | DOCKER_IMG_BUILD="debian-stretch-jenkins" |
| 15 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 16 | check_usage() { |
| 17 | if [ -z "$PROJECT" ]; then |
| 18 | echo "usage: $(basename $0) PROJECT" |
| 19 | echo "example: $(basename $0) hlr" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 20 | exit 1 |
| 21 | fi |
| 22 | } |
| 23 | |
| 24 | # Returns the name of the testsuite binary |
| 25 | get_testsuite_name() { |
| 26 | case "$PROJECT" in |
| 27 | bts-*) echo "BTS_Tests" ;; |
| 28 | mgw) echo "MGCP_Test" ;; |
| 29 | pcu-sns) echo "PCU_Tests" ;; |
| 30 | *) echo "${PROJECT_UPPER}_Tests" ;; |
| 31 | esac |
| 32 | } |
| 33 | |
| 34 | get_testsuite_dir() { |
| 35 | local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks" |
| 36 | |
| 37 | case "$PROJECT" in |
| 38 | bts-*) echo "$hacks/bts" ;; |
| 39 | pcu-sns) echo "$hacks/pcu" ;; |
| 40 | *) echo "$hacks/$PROJECT" ;; |
| 41 | esac |
| 42 | } |
| 43 | |
| 44 | get_testsuite_config() { |
| 45 | case "$PROJECT" in |
| 46 | bts-gprs) echo "BTS_Tests_GPRS.cfg" ;; |
| 47 | bts-oml) echo "BTS_Tests_OML.cfg" ;; |
| 48 | pcu-sns) echo "PCU_Tests_SNS.cfg" ;; |
| 49 | *) echo "$(get_testsuite_name).cfg" ;; |
| 50 | esac |
| 51 | } |
| 52 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 53 | get_testsuite_dir_docker() { |
| 54 | local dp="${DIR_OSMODEV}/src/docker-playground" |
| 55 | |
| 56 | case "$PROJECT" in |
| 57 | *) echo "$dp/ttcn3-$PROJECT-test" ;; |
| 58 | esac |
| 59 | } |
| 60 | |
| 61 | # Programs that need to be built |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 62 | get_programs() { |
| 63 | case "$PROJECT" in |
| 64 | bsc) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;; |
| 65 | bts) echo "osmo-bsc osmo-bts-trx fake_trx.py trxcon" ;; |
| 66 | msc) echo "osmo-stp osmo-msc" ;; |
| 67 | pcu-sns) echo "osmo-pcu" ;; |
| 68 | pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual virtphy" ;; |
| 69 | sgsn) echo "osmo-stp osmo-sgsn" ;; |
Oliver Smith | 01401bc | 2019-11-28 12:19:28 +0100 | [diff] [blame] | 70 | sip) echo "osmo-sip-connector" ;; |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 71 | *) echo "osmo-$PROJECT" ;; |
| 72 | esac |
| 73 | } |
| 74 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 75 | # Return the git repository name, which has the source for a specific program. |
| 76 | # $1: program name |
| 77 | get_program_repo() { |
| 78 | case "$1" in |
| 79 | fake_trx.py) echo "osmocom-bb" ;; |
| 80 | osmo-bts-*) echo "osmo-bts" ;; |
Oliver Smith | f03dfa3 | 2021-08-09 09:09:04 +0200 | [diff] [blame] | 81 | osmo-pcap-*) echo "osmo-pcap" ;; |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 82 | osmo-stp) echo "libosmo-sccp" ;; |
| 83 | trxcon) echo "osmocom-bb" ;; |
| 84 | virtphy) echo "osmocom-bb" ;; |
| 85 | *) echo "$1" ;; |
| 86 | esac |
| 87 | } |
| 88 | |
| 89 | check_ttcn3_install() { |
| 90 | if ! command -v ttcn3_compiler > /dev/null; then |
| 91 | echo "ERROR: ttcn3_compiler is not installed." |
| 92 | echo "Install eclipse-titan from the Osmocom latest repository." |
| 93 | echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites" |
| 94 | exit 1 |
| 95 | fi |
| 96 | } |
| 97 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 98 | setup_dir_make() { |
| 99 | cd "$DIR_OSMODEV" |
| 100 | |
| 101 | ( echo "# Generated by ttcn3.sh, do not edit" |
| 102 | cat ./3G+2G.deps |
| 103 | echo |
| 104 | echo "osmo-bts libosmocore libosmo-abis" |
| 105 | echo "osmo-pcu libosmocore" |
| 106 | # just clone these, building is handled by ttcn3.sh |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 107 | echo "docker-playground" |
| 108 | echo "osmo-ttcn3-hacks" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 109 | echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps |
| 110 | |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 111 | local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh" |
| 112 | docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD" |
| 113 | |
Oliver Smith | 10da26d | 2020-01-07 13:17:54 +0100 | [diff] [blame] | 114 | ./gen_makefile.py \ |
| 115 | ttcn3/3G+2G_ttcn3.deps \ |
| 116 | default.opts \ |
| 117 | iu.opts \ |
| 118 | no_systemd.opts \ |
| 119 | no_doxygen.opts \ |
| 120 | no_dahdi.opts \ |
| 121 | no_optimization.opts \ |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 122 | ttcn3/ttcn3.opts \ |
| 123 | --docker-cmd "$docker_cmd" \ |
| 124 | --make-dir "$DIR_MAKE" \ |
| 125 | --no-ldconfig |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | # $1: name of repository (e.g. osmo-ttcn3-hacks) |
| 129 | clone_repo() { |
| 130 | make -C "$DIR_MAKE" ".make.${1}.clone" |
| 131 | } |
| 132 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 133 | # Require testsuite dir and docker-playground dir |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 134 | check_dir_testsuite() { |
| 135 | local program |
| 136 | local config_testsuite |
| 137 | local dir_testsuite="$(get_testsuite_dir)" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 138 | local dir_testsuite_docker="$(get_testsuite_dir_docker)" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 139 | |
| 140 | if ! [ -d "$dir_testsuite" ]; then |
| 141 | echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite" |
| 142 | exit 1 |
| 143 | fi |
| 144 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 145 | if ! [ -d "$dir_testsuite_docker" ]; then |
| 146 | echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?" |
| 147 | exit 1 |
| 148 | fi |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 149 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 150 | # Sanity check for jenkins.sh |
| 151 | if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then |
| 152 | echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 153 | exit 1 |
| 154 | fi |
| 155 | } |
| 156 | |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 157 | # Copy scripts from docker-playground to /usr/local/bin, so we don't miss them when mounting the outside /usr/local/bin |
| 158 | # inside the docker container |
| 159 | prepare_local_bin() { |
| 160 | local scripts=" |
Oliver Smith | 7531cea | 2021-06-01 13:29:56 +0200 | [diff] [blame] | 161 | ${DIR_OSMODEV}/src/docker-playground/common/respawn.sh |
Oliver Smith | 6f7954e | 2021-06-01 14:14:06 +0200 | [diff] [blame] | 162 | ${DIR_OSMODEV}/src/docker-playground/debian-stretch-titan/ttcn3-docker-run.sh |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 163 | " |
| 164 | |
| 165 | for script in $scripts; do |
Oliver Smith | 6f7954e | 2021-06-01 14:14:06 +0200 | [diff] [blame] | 166 | local script_path_localbin |
| 167 | local name_install="$(basename "$script")" |
| 168 | |
| 169 | case "$name_install" in |
| 170 | ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;; |
| 171 | esac |
| 172 | |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 173 | script_path_localbin="$DIR_USR_LOCAL/bin/$name_install" |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 174 | if [ -x "$script_path_localbin" ]; then |
| 175 | continue |
| 176 | fi |
| 177 | |
Oliver Smith | 7531cea | 2021-06-01 13:29:56 +0200 | [diff] [blame] | 178 | install -v -Dm755 "$script" "$script_path_localbin" |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 179 | done |
| 180 | } |
| 181 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 182 | # Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git). |
| 183 | # $1: repository |
| 184 | # $2: path in the repository |
| 185 | build_osmo_program_subdir() { |
| 186 | clone_repo "$1" |
| 187 | cd "$DIR_OSMODEV/src/$1/$2" |
| 188 | if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then |
| 189 | autoreconf -fi |
| 190 | fi |
| 191 | if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then |
| 192 | ./configure |
| 193 | fi |
| 194 | make -j"$JOBS" |
| 195 | } |
| 196 | |
| 197 | # Use osmo-dev to build a typical Osmocom program, and run a few sanity checks. |
| 198 | # $1 program |
| 199 | build_osmo_program_osmodev() { |
| 200 | local repo="$(get_program_repo "$program")" |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 201 | local usr_local_bin="$DIR_USR_LOCAL/bin" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 202 | make -C "$DIR_MAKE" "$repo" |
| 203 | |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 204 | if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then |
| 205 | echo "ERROR: program was not installed properly: $program" |
| 206 | echo "Expected it to be in path: $PATH_dest" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 207 | exit 1 |
| 208 | fi |
| 209 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 210 | local reference="$DIR_MAKE/.make.$repo.build" |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 211 | if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 212 | echo "ERROR: $path is outdated!" |
| 213 | echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 214 | exit 1 |
| 215 | fi |
| 216 | } |
| 217 | |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 218 | prepare_docker_build_container() { |
| 219 | local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build" |
| 220 | |
| 221 | if [ -e "$marker" ]; then |
| 222 | return |
| 223 | fi |
| 224 | |
| 225 | make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD" |
| 226 | touch "$marker" |
| 227 | } |
| 228 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 229 | # Use osmo-dev to build one Osmocom program and its dependencies |
| 230 | build_osmo_programs() { |
| 231 | local program |
| 232 | for program in $(get_programs); do |
| 233 | case "$program" in |
| 234 | fake_trx.py) clone_repo "osmocom-bb" ;; |
| 235 | trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;; |
| 236 | virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;; |
| 237 | *) build_osmo_program_osmodev "$program" ;; |
| 238 | esac |
| 239 | done |
| 240 | } |
| 241 | |
| 242 | build_testsuite() { |
| 243 | cd "$(get_testsuite_dir)" |
Oliver Smith | 389dafb | 2020-04-27 14:33:15 +0200 | [diff] [blame] | 244 | |
| 245 | local deps_marker="${DIR_OSMODEV}/ttcn3/make/.ttcn3-deps" |
| 246 | if ! [ -e "$deps_marker" ]; then |
| 247 | make -C "${DIR_OSMODEV}/src/osmo-ttcn3-hacks/deps" -j"$JOBS" |
| 248 | touch "$deps_marker" |
| 249 | fi |
| 250 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 251 | ./gen_links.sh |
| 252 | ./regen_makefile.sh |
| 253 | make compile |
| 254 | make -j"$JOBS" |
| 255 | } |
| 256 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 257 | run_docker() { |
| 258 | local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks" |
| 259 | local docker_dir="$(get_testsuite_dir_docker)" |
| 260 | local docker_name="$(basename "$docker_dir")" |
Oliver Smith | f3eb0ba | 2021-08-10 15:41:47 +0200 | [diff] [blame] | 261 | local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name.$IMAGE_SUFFIX" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 262 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 263 | # Skip building docker containers if this already ran |
| 264 | if [ -e "$marker" ]; then |
| 265 | echo "NOTE: skipping docker container build, because marker exists: $marker" |
| 266 | export NO_DOCKER_IMAGE_BUILD=1 |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 267 | fi |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 268 | |
| 269 | cd "$(get_testsuite_dir_docker)" |
Oliver Smith | bfe5929 | 2021-08-12 11:15:40 +0200 | [diff] [blame] | 270 | export DOCKER_ARGS="\ |
| 271 | -e LD_LIBRARY_PATH=/usr/local/lib \ |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 272 | -v "$DIR_USR_LOCAL":/usr/local:ro \ |
Oliver Smith | bfe5929 | 2021-08-12 11:15:40 +0200 | [diff] [blame] | 273 | -v $hacks:/osmo-ttcn3-hacks:ro \ |
| 274 | " |
Oliver Smith | 6b84b46 | 2021-07-09 10:12:18 +0200 | [diff] [blame] | 275 | export NO_LIST_OSMO_PACKAGES=1 |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 276 | ./jenkins.sh |
| 277 | |
| 278 | touch "$marker" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 281 | remove_old_logs() { |
| 282 | sudo rm -rf /tmp/tmp.* 2>/dev/null |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | collect_logs() { |
| 286 | # Merge and move logs |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 287 | cd /tmp/logs/*-tester |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 288 | |
| 289 | # Format logs |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 290 | for log in *.merged; do |
| 291 | ttcn3_logformat -o "${log}.log" "$log" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 292 | sudo rm "$log" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 293 | done |
| 294 | |
| 295 | # Print log path |
| 296 | echo "---" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 297 | echo "Logs: /tmp/logs" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 298 | echo "---" |
| 299 | } |
| 300 | |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 301 | check_usage |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 302 | check_ttcn3_install |
| 303 | setup_dir_make |
| 304 | clone_repo "osmo-ttcn3-hacks" |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 305 | clone_repo "docker-playground" |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 306 | check_dir_testsuite |
Oliver Smith | 1b471a9 | 2020-04-27 12:00:25 +0200 | [diff] [blame] | 307 | prepare_local_bin |
Oliver Smith | 0fa204e | 2021-08-12 15:16:11 +0200 | [diff] [blame^] | 308 | prepare_docker_build_container |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 309 | build_osmo_programs |
| 310 | build_testsuite |
| 311 | remove_old_logs |
Oliver Smith | 01a510a | 2020-03-18 15:46:41 +0100 | [diff] [blame] | 312 | run_docker |
Oliver Smith | e398564 | 2019-10-11 16:37:59 +0200 | [diff] [blame] | 313 | collect_logs |