[M] Change in osmo-ttcn3-hacks[master]: testenv: show unexpected respawns at the end
osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/44175?usp=email ) Change subject: testenv: show unexpected respawns at the end ...................................................................... testenv: show unexpected respawns at the end Split respawn.sh in respawn-expected.sh and respawn-unexpected.sh and adjust its users. Let the respawn-unexpected.sh script write each respawn to a new end.log file, which gets displayed at the end of testenv runs, if it exists. Example: [testenv] 1 warning found in end.log: [testenv] > Unexpected respawn of "osmo-bts-trx" during test "BTS_Tests_VAMOS.TC_vamos_chan_act_vhh" This allows us to quickly see if a program was respawned unexpectedly, while still respawning it in order to not abort the testsuite or have all following tests fail. Change-Id: Ia0650344b6df428e27de9e011676e884d27bfde0 --- M _testenv/README.md R _testenv/data/scripts/respawn-expected.sh A _testenv/data/scripts/respawn-unexpected.sh M _testenv/testenv.py M _testenv/testenv/daemons.py M _testenv/testenv/testdir.py M bsc/osmo_bts_omldummy.sh M bts/testenv_generic.cfg M bts/testenv_hopping.cfg M pcu/testenv_generic.cfg M pcu/testenv_sns.cfg 11 files changed, 99 insertions(+), 8 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/75/44175/1 diff --git a/_testenv/README.md b/_testenv/README.md index 4f53724..42dfce2 100644 --- a/_testenv/README.md +++ b/_testenv/README.md @@ -241,7 +241,7 @@ The user's `PATH` environment variable is prefixed with the following paths: * The directory of the testsuite. * The directory for binaries built from source. - * The directory `_testenv/data/scripts` (which has e.g. `respawn.sh`). + * The directory `_testenv/data/scripts` (which has e.g. `respawn-expected.sh`). * The directory `_testenv/data/scripts/qemu`. * `PWD`: @@ -249,15 +249,30 @@ log dir. For example: ``` -/tmp/logs +/tmp/logs # TESTENV_TESTDIR +├── end.log # TESTENV_END_LOG ├── ggsn # Executables from [ggsn] section run in this dir │ ├── ggsn.log │ └── osmo-ggsn.cfg └── testsuite # Executables from [testsuite] run in this dir + ├── .current_test # The current test name is in this file ├── Common.cfg ├── GGSN_Tests.cfg └── GGSN_Tests.default ``` + If a testsuite has multiple configurations (`./testenv.py run -c`), then + `TESTENV_TESTDIR` ends in the name of the current configuration and is next + to `end.log`. For example: +``` +/tmp/logs +├── end.log # TESTENV_END_LOG is here for all configurations +├── generic # TESTENV_TESTDIR while running the generic config +│ ├── bsc +│ ├── bts +│ └── testsuite +├── hopping # TESTENV_TESTDIR while running the hopping config +└── oml # TESTENV_TESTDIR while running the oml config +``` * `TESTENV_INSTALL_DIR`: The directory into which the SUT binaries and other files are installed. It @@ -306,6 +321,16 @@ running podman. This is used in `_testenv/data/scripts/require_ulimit_r.sh` to display a hint for setting the rtprio limit for this user. +* `TESTENV_TESTDIR`: + (Set for `program=` of test components only.) This directory contains logs + and configurations for the current configuration. See `PWD` above for + examples. + +* `TESTENV_END_LOG`: + (Set for `program=` of test components only.) Path to an `end.log` file, to + which warnings can be written that will be displayed at the end of the + testenv run. This is used by `respawn-unexpected.sh`. + ## Eclipse-titan versions It is possible to change the eclipse-titan version that is used to build and diff --git a/_testenv/data/scripts/respawn.sh b/_testenv/data/scripts/respawn-expected.sh similarity index 100% rename from _testenv/data/scripts/respawn.sh rename to _testenv/data/scripts/respawn-expected.sh diff --git a/_testenv/data/scripts/respawn-unexpected.sh b/_testenv/data/scripts/respawn-unexpected.sh new file mode 100755 index 0000000..27949db --- /dev/null +++ b/_testenv/data/scripts/respawn-unexpected.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Restart a given test component while the testsuite is running. Unlike +# respawn-expected.sh we don't expect this to happen but need to keep going +# anyway. We log that this happens to $TESTENV_END_LOG, which then gets +# displayed at the end of the testenv run. + +trap "kill 0" EXIT + +SLEEP_BEFORE_RESPAWN=${SLEEP_BEFORE_RESPAWN:-0} + +i=0 +max_i=500 +while [ $i -lt $max_i ]; do + echo "respawn: $i: starting: $*" + $* & + LAST_PID=$! + wait $LAST_PID + LAST_STATUS=$? + echo "respawn: $i: stopped pid $LAST_PID with status $LAST_STATUS" + + CURRENT_TEST="$(cat "$TESTENV_TESTDIR"/testsuite/.current_test)" + if [ -n "$CURRENT_TEST" ]; then + echo "Unexpected respawn of \"$*\" during test \"$CURRENT_TEST\"" >>"$TESTENV_END_LOG" + else + echo "Unexpected respawn of \"$*\"" >>"$TESTENV_END_LOG" + fi + + if [ $LAST_STATUS -ge 128 ]; then + echo "respawn: process was terminated abnormally, not respawning" + exit $LAST_STATUS + fi + if [ $SLEEP_BEFORE_RESPAWN -gt 0 ]; then + echo "respawn: sleeping $SLEEP_BEFORE_RESPAWN seconds..." + sleep $SLEEP_BEFORE_RESPAWN + fi + i=$(expr $i + 1) +done +echo "respawn: exiting after $max_i runs" diff --git a/_testenv/testenv.py b/_testenv/testenv.py index 695a857..ec64a73 100755 --- a/_testenv/testenv.py +++ b/_testenv/testenv.py @@ -135,11 +135,30 @@ clean() +def show_end_log(): + if getattr(testenv.args, "action", None) != "run": + return + + end_log = testenv.testdir.testdir_topdir_end_log + if not end_log or not os.path.exists(end_log): + return + + with open(end_log) as e: + lines = e.readlines() + + warnings = "warning" if len(lines) == 1 else "warnings" + logging.warning(f"{len(lines)} {warnings} found in end.log:") + for line in lines: + logging.warning(f"> {line.rstrip()}") + + try: main() + show_end_log() except testenv.NoTraceException as e: logging.error(e) testenv.podman.stop() + show_end_log() sys.exit(2) except KeyboardInterrupt: print() # new line @@ -147,7 +166,9 @@ if test: logging.critical(f"^C during {test}") testenv.podman.stop() + show_end_log() sys.exit(3) except: testenv.podman.stop() + show_end_log() raise diff --git a/_testenv/testenv/daemons.py b/_testenv/testenv/daemons.py index 3ee1e6d..aa8d4c0 100644 --- a/_testenv/testenv/daemons.py +++ b/_testenv/testenv/daemons.py @@ -55,7 +55,10 @@ pipe = f">{shlex.quote(log)} 2>&1" cmd = ["sh", "-c", f"ulimit -c unlimited; {program} {pipe}"] - env = {} + env = { + "TESTENV_END_LOG": testenv.testdir.testdir_topdir_end_log, + "TESTENV_TESTDIR": testenv.testdir.testdir, + } if testenv.args.io_uring: env["LIBOSMO_IO_BACKEND"] = "IO_URING" diff --git a/_testenv/testenv/testdir.py b/_testenv/testenv/testdir.py index 927ce69..a980f09 100644 --- a/_testenv/testenv/testdir.py +++ b/_testenv/testenv/testdir.py @@ -18,12 +18,14 @@ # current configuration. testdir = None testdir_topdir = None +testdir_topdir_end_log = None prefix = None clean_scripts = {} def init(): global testdir_topdir + global testdir_topdir_end_log global prefix prefix = f"testenv-{testenv.args.testsuite}-" @@ -50,6 +52,8 @@ testenv.cmd.run(["rm", "/tmp/logs"], no_podman=True) testenv.cmd.run(["ln", "-sf", testdir_topdir, "/tmp/logs"], no_podman=True) + testdir_topdir_end_log = os.path.join(testdir_topdir, "end.log") + def prepare(cfg_name, cfg, loop_count): global testdir diff --git a/bsc/osmo_bts_omldummy.sh b/bsc/osmo_bts_omldummy.sh index 611f750..8c707af 100755 --- a/bsc/osmo_bts_omldummy.sh +++ b/bsc/osmo_bts_omldummy.sh @@ -17,7 +17,7 @@ ;; esac -respawn.sh \ +respawn-expected.sh \ osmo-bts-omldummy \ "$BTS_FEATURES" \ "127.0.0.1" \ diff --git a/bts/testenv_generic.cfg b/bts/testenv_generic.cfg index 4807d7f..a8c4bef 100644 --- a/bts/testenv_generic.cfg +++ b/bts/testenv_generic.cfg @@ -22,7 +22,7 @@ [bts] prepare=require_ulimit_r.sh 30 -program=respawn.sh osmo-bts-trx +program=respawn-unexpected.sh osmo-bts-trx make=osmo-bts package=osmo-bts copy=osmo-bts.cfg diff --git a/bts/testenv_hopping.cfg b/bts/testenv_hopping.cfg index a7fba70..5c2d4dd 100644 --- a/bts/testenv_hopping.cfg +++ b/bts/testenv_hopping.cfg @@ -25,7 +25,7 @@ [bts] prepare=require_ulimit_r.sh 30 -program=respawn.sh osmo-bts-trx +program=respawn-unexpected.sh osmo-bts-trx make=osmo-bts package=osmo-bts copy=osmo-bts.cfg diff --git a/pcu/testenv_generic.cfg b/pcu/testenv_generic.cfg index 7d506cf..32f56d8 100644 --- a/pcu/testenv_generic.cfg +++ b/pcu/testenv_generic.cfg @@ -3,7 +3,7 @@ config=PCU_Tests.cfg [pcu] -program=respawn.sh osmo-pcu +program=respawn-expected.sh osmo-pcu make=osmo-pcu package=osmo-pcu copy=osmo-pcu.cfg diff --git a/pcu/testenv_sns.cfg b/pcu/testenv_sns.cfg index 0bf4e13..54c377f 100644 --- a/pcu/testenv_sns.cfg +++ b/pcu/testenv_sns.cfg @@ -3,7 +3,7 @@ config=PCU_Tests_SNS.cfg [pcu] -program=respawn.sh osmo-pcu -c osmo-pcu-sns.cfg +program=respawn-expected.sh osmo-pcu -c osmo-pcu-sns.cfg make=osmo-pcu package=osmo-pcu copy=osmo-pcu-sns.cfg -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/44175?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: Ia0650344b6df428e27de9e011676e884d27bfde0 Gerrit-Change-Number: 44175 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith@sysmocom.de>
participants (1)
-
osmith