[LTP] [PATCH] kcmp03: Add check for KCMP_SYSVSEM before running test

Dorinda Bassey dbassey@redhat.com
Fri Feb 14 16:31:58 CET 2025


This commit introduces a new function
`is_kcmp_supported()` to check if the kernel supports the
`KCMP_SYSVSEM` operation. In the `verify_kcmp()` function,
we add logic to detect when the kernel does not support
`KCMP_SYSVSEM` and skip the test for that case with a TCONF
result. This ensures that the test does not fail when the
Kconfig that supports `KCMP_SYSVSEM` is unavailable.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/testcases/kernel/syscalls/kcmp/kcmp03.c b/testcases/kernel/syscalls/kcmp/kcmp03.c
index 37d5118d5..255171d98 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp03.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp03.c
@@ -52,6 +52,12 @@ static void cleanup(void)
 	free(stack);
 }
 
+static int is_kcmp_supported(void)
+{
+	int result = syscall(__NR_kcmp, getpid(), getpid(), KCMP_SYSVSEM, 0, 0);
+	return result == 0 || errno != EOPNOTSUPP;
+}
+
 static int do_child(void *arg)
 {
 	pid2 = getpid();
@@ -64,6 +70,13 @@ static void verify_kcmp(unsigned int n)
 	int res;
 	struct tcase *tc = &tcases[n];
 
+    // Handle the case for KCMP_SYSVSEM specifically
+    if (tc->kcmp_type == KCMP_SYSVSEM) {
+        if (!is_kcmp_supported()) {
+            tst_brk(TCONF, "Kernel does not support KCMP_SYSVSEM, skipping test.");
+	    }
+	}
+
 	pid1 = getpid();
 	tst_res(TINFO, "Testing %s", tc->desc);
 
-- 
2.48.1



More information about the ltp mailing list