From: Kienan Stewart Date: Thu, 4 Jul 2024 13:25:51 +0000 (-0400) Subject: tests: Add helper functions to validate if lttng modules are loaded X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=87634576208f47bfdd3f80b20b9d936bcf28eea0;p=lttng-tools.git tests: Add helper functions to validate if lttng modules are loaded 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 --- 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.