[PATCH 4/8] selftests: livepatch: functions: Introduce check_sysfs_exists

From: Marcos Paulo de Souza

Date: Fri Mar 13 2026 - 16:59:31 EST


Return 0 if the livepatch sysfs attribute don't exists, and 1 otherwise.
This new function will be used in the next patches.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@xxxxxxxx>
---
tools/testing/selftests/livepatch/functions.sh | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 8ec0cb64ad94a..781346d6e94e0 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -339,6 +339,20 @@ function check_result {
fi
}

+# check_sysfs_exists(modname, attr) - check sysfs attribute existence
+# modname - livepatch module creating the sysfs interface
+# attr - attribute name to be checked
+function check_sysfs_exists() {
+ local mod="$1"; shift
+ local attr="$1"; shift
+
+ if [[ ! -f "$SYSFS_KLP_DIR/$mod/$attr" ]]; then
+ return 0
+ fi
+
+ return 1
+}
+
# check_sysfs_rights(modname, rel_path, expected_rights) - check sysfs
# path permissions
# modname - livepatch module creating the sysfs interface

--
2.52.0