From 87634576208f47bfdd3f80b20b9d936bcf28eea0 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 4 Jul 2024 09:25:51 -0400 Subject: [PATCH] tests: Add helper functions to validate if lttng modules are loaded MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== Regression tests exercising kernel modules don't validate before and after the test execution that there are no LTTng kernel modules loaded. Solution ======== Add convenient tap helper functions that may be used by shell TAP tests. Known drawbacks =============== None. Change-Id: I8244358137c2d049ed72e6dc7d9290cb9dda10e3 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- tests/utils/utils.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index f9f545bd4..8ffc424f4 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -470,6 +470,38 @@ function _run_babeltrace_cmd () fi } +function _lttng_modules_loaded_opt +{ + local fail_when_present="${1}" + local module_count + local ret + local message="%d LTTng modules loaded, expected count " + + if [[ "${fail_when_present}" -eq "1" ]] ; then + message+="= 0" + else + message+="> 0" + fi + + grep -q -E '^lttng' '/proc/modules' + ret="${?}" + module_count="$(grep -E '^lttng' '/proc/modules' | wc -l)" + + is "${ret}" "${fail_when_present}" "$(printf "${message}" "${module_count}")" +} + +# Pass if any lttng modules are loaded +function lttng_modules_loaded_ok() +{ + _lttng_modules_loaded_opt 0 +} + +# Fail if any lttng modules are loaded +function lttng_modules_loaded_fail() +{ + _lttng_modules_loaded_opt 1 +} + # Run the lttng binary. # # The first two arguments are stdout and stderr redirect paths, respectively. -- 2.39.5