Skip to contentSkip to conversation

kcmp03: Add check for KCMP_SYSVSEM before running test

PATCH Superseded Dorinda Bassey 2 participants 3 messages Feb 14, 2025 – Feb 17, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kcmp03: Add check for KCMP_SYSVSEM before running test

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.

---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
testcases/kernel/syscalls/kcmp/kcmp03.c +13 -0
index 37d5118d5..255171d98 100644
@@ -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);
 
Signature · 5 lines
2.48.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 7 lines

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.

First of all the coding style is inconsistent, have you run 'make check' in the test directory and fixed all the problems?

Quoted 10 lines
---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
testcases/kernel/syscalls/kcmp/kcmp03.c +0 -0
index 37d5118d5..255171d98 100644

testcases/kernel/syscalls/kcmp/kcmp03.c static void cleanup(void) · line 57

Quoted 6 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +3 -0
@@ -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);

Why syscall() instead of kcmp() that is used in the rest of the test?

testcases/kernel/syscalls/kcmp/kcmp03.c static void verify_kcmp(unsigned int n) · line 75

Quoted 13 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +6 -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()) {

This function should be called once from the test setup and the results should be cached.

testcases/kernel/syscalls/kcmp/kcmp03.c static void verify_kcmp(unsigned int n) · line 76

Quoted 1 line
testcases/kernel/syscalls/kcmp/kcmp03.c +1 -0
+            tst_brk(TCONF, "Kernel does not support KCMP_SYSVSEM, skipping test.");

This should be just tst_res(TCONF, "..."); followed by return 0;

We do not want to abort subseqent test iterations (e.g. -i 2 on command line) just because one operation is not supported.

Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +2 -0
+	    }
+	}
 
 
 	pid1 = getpid();
 	tst_res(TINFO, "Testing %s", tc->desc);
Signature · 2 lines
-- 
2.48.1
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Cyril,

Thank you for the feedback, I just sent a v2 of the patch.

BR,
Dorinda Bassey.

Quoted 74 lines · Cyril Hrubis

Hi!

Quoted 7 lines

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.

First of all the coding style is inconsistent, have you run 'make check' in the test directory and fixed all the problems?

Review

Quoted 6 lines
---
 testcases/kernel/syscalls/kcmp/kcmp03.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/syscalls/kcmp/kcmp03.c

testcases/kernel/syscalls/kcmp/kcmp03.c static void cleanup(void) · line 57

Quoted 10 lines

index 37d5118d5..255171d98 100644

testcases/kernel/syscalls/kcmp/kcmp03.c +3 -0
@@ -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);

Why syscall() instead of kcmp() that is used in the rest of the test?

testcases/kernel/syscalls/kcmp/kcmp03.c static void verify_kcmp(unsigned int n) · line 75

Quoted 13 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +6 -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()) {

This function should be called once from the test setup and the results should be cached.

testcases/kernel/syscalls/kcmp/kcmp03.c static void verify_kcmp(unsigned int n) · line 76

Quoted 1 line
testcases/kernel/syscalls/kcmp/kcmp03.c +1 -0
+            tst_brk(TCONF, "Kernel does not support KCMP_SYSVSEM,

skipping test.");

This should be just tst_res(TCONF, "..."); followed by return 0;

We do not want to abort subseqent test iterations (e.g. -i 2 on command line) just because one operation is not supported.

Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +2 -1
+         }
+     }
 
 
      pid1 = getpid();
      tst_res(TINFO, "Testing %s", tc->desc);
 
--

2.48.1

--
Cyril Hrubis
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp