#!/bin/sh -e PROJECT="$1" PROJECT_UPPER="$(echo "$PROJECT" | tr '[:lower:]' '[:upper:]')" DIR_OSMODEV="$(readlink -f "$(dirname $0)/..")" DIR_MAKE="${DIR_MAKE:-${DIR_OSMODEV}/ttcn3/make}" DIR_OUTPUT="${DIR_OUTPUT:-${DIR_OSMODEV}/ttcn3/out}" JOBS="${JOBS:-9}" check_usage() { if [ -z "$PROJECT" ]; then echo "usage: $(basename $0) PROJECT" echo "example: $(basename $0) hlr" exit 1 fi } # Returns the name of the testsuite binary get_testsuite_name() { case "$PROJECT" in bts-*) echo "BTS_Tests" ;; mgw) echo "MGCP_Test" ;; pcu-sns) echo "PCU_Tests" ;; *) echo "${PROJECT_UPPER}_Tests" ;; esac } get_testsuite_dir() { local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks" case "$PROJECT" in bts-*) echo "$hacks/bts" ;; pcu-sns) echo "$hacks/pcu" ;; *) echo "$hacks/$PROJECT" ;; esac } get_testsuite_config() { case "$PROJECT" in bts-gprs) echo "BTS_Tests_GPRS.cfg" ;; bts-oml) echo "BTS_Tests_OML.cfg" ;; pcu-sns) echo "PCU_Tests_SNS.cfg" ;; *) echo "$(get_testsuite_name).cfg" ;; esac } get_testsuite_dir_docker() { local dp="${DIR_OSMODEV}/src/docker-playground" case "$PROJECT" in *) echo "$dp/ttcn3-$PROJECT-test" ;; esac } # Programs that need to be built get_programs() { case "$PROJECT" in bsc) echo "osmo-stp osmo-bsc osmo-bts-omldummy" ;; bts) echo "osmo-bsc osmo-bts-trx fake_trx.py trxcon" ;; msc) echo "osmo-stp osmo-msc" ;; pcu-sns) echo "osmo-pcu" ;; pcu) echo "osmo-pcu osmo-bsc osmo-bts-virtual virtphy" ;; sgsn) echo "osmo-stp osmo-sgsn" ;; sip) echo "osmo-sip-connector" ;; *) echo "osmo-$PROJECT" ;; esac } # Return the git repository name, which has the source for a specific program. # $1: program name get_program_repo() { case "$1" in fake_trx.py) echo "osmocom-bb" ;; osmo-bts-*) echo "osmo-bts" ;; osmo-stp) echo "libosmo-sccp" ;; trxcon) echo "osmocom-bb" ;; virtphy) echo "osmocom-bb" ;; *) echo "$1" ;; esac } check_ttcn3_install() { if ! command -v ttcn3_compiler > /dev/null; then echo "ERROR: ttcn3_compiler is not installed." echo "Install eclipse-titan from the Osmocom latest repository." echo "Details: https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites" exit 1 fi } setup_dir_make() { cd "$DIR_OSMODEV" ( echo "# Generated by ttcn3.sh, do not edit" cat ./3G+2G.deps echo echo "osmo-bts libosmocore libosmo-abis" echo "osmo-pcu libosmocore" # just clone these, building is handled by ttcn3.sh echo "docker-playground" echo "osmo-ttcn3-hacks" echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps ./gen_makefile.py \ ttcn3/3G+2G_ttcn3.deps \ default.opts \ iu.opts \ no_systemd.opts \ no_doxygen.opts \ no_dahdi.opts \ no_optimization.opts \ ttcn3/ttcn3.opts -I -m "$DIR_MAKE" } # $1: name of repository (e.g. osmo-ttcn3-hacks) clone_repo() { make -C "$DIR_MAKE" ".make.${1}.clone" } # Require testsuite dir and docker-playground dir check_dir_testsuite() { local program local config_testsuite local dir_testsuite="$(get_testsuite_dir)" local dir_testsuite_docker="$(get_testsuite_dir_docker)" if ! [ -d "$dir_testsuite" ]; then echo "ERROR: project '$PROJECT' is invalid, resulting path not found: $dir_testsuite" exit 1 fi if ! [ -d "$dir_testsuite_docker" ]; then echo "ERROR: could not find docker dir for project: $PROJECT. Adjust get_testsuite_dir_docker?" exit 1 fi # Sanity check for jenkins.sh if ! grep -q DOCKER_ARGS $dir_testsuite_docker/jenkins.sh; then echo "ERROR: DOCKER_ARGS not found in $dir_testsuite_docker/jenkins.sh!" exit 1 fi } # Build a program that is in the subdir of a repository (e.g. trxcon in osmocom-bb.git). # $1: repository # $2: path in the repository build_osmo_program_subdir() { clone_repo "$1" cd "$DIR_OSMODEV/src/$1/$2" if ! [ -e "./configure" ] && [ -e "configure.ac" ]; then autoreconf -fi fi if ! [ -e "Makefile" ] && [ -e "Makefile.am" ]; then ./configure fi make -j"$JOBS" } # Use osmo-dev to build a typical Osmocom program, and run a few sanity checks. # $1 program build_osmo_program_osmodev() { local repo="$(get_program_repo "$program")" make -C "$DIR_MAKE" "$repo" local path="$(command -v "$program")" if [ -z "$path" ]; then echo "ERROR: program was not installed to PATH: $program" echo "Maybe you need to add /usr/local/bin to PATH?" exit 1 fi local pathdir="$(dirname "$path")" local reference="$DIR_MAKE/.make.$repo.build" if [ -z "$(find "$pathdir" -name "$program" -newer "$reference")" ]; then echo "ERROR: $path is outdated!" echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?" echo "Or the order in PATH is wrong?" exit 1 fi } # Use osmo-dev to build one Osmocom program and its dependencies build_osmo_programs() { local program for program in $(get_programs); do case "$program" in fake_trx.py) clone_repo "osmocom-bb" ;; trxcon) build_osmo_program_subdir "osmocom-bb" "src/host/trxcon" ;; virtphy) build_osmo_program_subdir "osmocom-bb" "src/host/virt_phy" ;; *) build_osmo_program_osmodev "$program" ;; esac done } build_testsuite() { cd "$(get_testsuite_dir)" ./gen_links.sh ./regen_makefile.sh make compile make -j"$JOBS" } run_docker() { local hacks="${DIR_OSMODEV}/src/osmo-ttcn3-hacks" local docker_dir="$(get_testsuite_dir_docker)" local docker_name="$(basename "$docker_dir")" local marker="${DIR_OSMODEV}/ttcn3/make/.docker.$docker_name" # Skip building docker containers if this already ran if [ -e "$marker" ]; then echo "NOTE: skipping docker container build, because marker exists: $marker" export NO_DOCKER_IMAGE_BUILD=1 fi cd "$(get_testsuite_dir_docker)" export DOCKER_ARGS="-v /usr/local:/usr/local:ro -v $hacks:/osmo-ttcn3-hacks:ro" ./jenkins.sh touch "$marker" } remove_old_logs() { sudo rm -rf /tmp/tmp.* 2>/dev/null } collect_logs() { # Merge and move logs cd /tmp/logs/*-tester # Format logs for log in *.merged; do ttcn3_logformat -o "${log}.log" "$log" sudo rm "$log" done # Print log path echo "---" echo "Logs: /tmp/logs" echo "---" } check_usage check_ttcn3_install setup_dir_make clone_repo "osmo-ttcn3-hacks" clone_repo "docker-playground" check_dir_testsuite build_osmo_programs build_testsuite remove_old_logs run_docker collect_logs