From caa278d0c7e8691833d662caa20014dc1c3fd19f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 29 Jun 2023 15:12:57 -0400 Subject: [PATCH] tests: Look for zlog_backtrace in ci system There are parts of our daemons that upon certain types of errors that a zlog_backtrace is auto-generated. It is desirable for this to be caught and have the test auto-failed. Issue: #13787 Signed-off-by: Donald Sharp --- tests/topotests/conftest.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index cb25d63a36..27a6909a46 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -297,6 +297,39 @@ def check_for_memleaks(): pytest.fail("memleaks found for daemons: " + " ".join(daemons)) +def check_for_backtraces(): + backtraces = [] + tgen = get_topogen() # pylint: disable=redefined-outer-name + latest = [] + existing = [] + + if tgen is not None: + logdir = tgen.logdir + if hasattr(tgen, "backtraces_existing_files"): + existing = tgen.backtraces_existing_files + latest = glob.glob(os.path.join(logdir, "*/*.log")) + + daemons = [] + for vfile in latest: + if vfile in existing: + continue + with open(vfile, encoding="ascii") as vf: + vfcontent = vf.read() + backtrace = vfcontent.count("Backtrace:") + if backtrace: + existing.append(vfile) # have backtrace don't check again + emsg = "Backtrace found in {}, failing test".format(vfile) + backtraces.append(emsg) + + if tgen is not None: + tgen.backtrace_existing_files = existing + + if backtraces: + logger.error("Backtraces found in test suite, erroring") + logger.error(backtraces) + pytest.fail("Backtraces found") + + @pytest.fixture(autouse=True, scope="module") def module_autouse(request): basename = get_test_logdir(request.node.nodeid, True) @@ -320,6 +353,7 @@ def module_check_memtest(request): if request.config.option.memleaks: if get_topogen() is not None: check_for_memleaks() + check_for_backtraces() # -- 2.39.5