Skip to contentSkip to conversation

kcmp03: Add check for KCMP_SYSVSEM before running test

PATCH In review Dorinda Bassey 3 participants 3 messages Feb 17, 2025 – Feb 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
v2 changes
fix coding style
use kcmp() instead of syscall()
do is_kcmp_supported() check in the setup and
cache result
use tst_res instead of tst_brk

 testcases/kernel/syscalls/kcmp/kcmp03.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/kcmp/kcmp03.c +18 -0
index 37d5118d5..8610cea46 100644
@@ -42,9 +42,19 @@ static struct tcase {
 	{ARGS(CLONE_SYSVSEM, KCMP_SYSVSEM)}
 };
 
+static int is_kcmp_supported_flag = -1;
+
+static int is_kcmp_supported(void)
+{
+	return kcmp(getpid(), getpid(), KCMP_SYSVSEM, 0, 0) == 0;
+}
+
 static void setup(void)
 {
 	stack = SAFE_MALLOC(STACK_SIZE);
+
+	if (is_kcmp_supported_flag == -1)
+		is_kcmp_supported_flag = is_kcmp_supported();
 }
 
 static void cleanup(void)
@@ -64,6 +74,14 @@ 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_flag == 0) {
+			tst_res(TCONF, "Kernel does not support KCMP_SYSVSEM, skipping test.");
+			return;
+		}
+	}
+
 	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,

there are still a couple of issues we can fix.

Quoted 7 lines · Dorinda Bassey

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.

The commit message can be simplified, reducing implementation details which might change in the future (such as functions names). We can use an imperative text as well:

Skip the test case verifying KCMP_SYSVSEM support if it's not enabled by the kernel configuration.

Quoted 17 lines

---
v2 changes
fix coding style
use kcmp() instead of syscall()
do is_kcmp_supported() check in the setup and
cache result
use tst_res instead of tst_brk

  testcases/kernel/syscalls/kcmp/kcmp03.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
testcases/kernel/syscalls/kcmp/kcmp03.c +0 -0
index 37d5118d5..8610cea46 100644

testcases/kernel/syscalls/kcmp/kcmp03.c static struct tcase { · line 45

Quoted 4 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +1 -0
@@ -42,9 +42,19 @@ static struct tcase {
  	{ARGS(CLONE_SYSVSEM, KCMP_SYSVSEM)}
  };
 
+static int is_kcmp_supported_flag = -1;

We don't need to initialize this flag.

testcases/kernel/syscalls/kcmp/kcmp03.c static struct tcase { · line 56

Quoted 11 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +8 -0
+
+static int is_kcmp_supported(void)
+{
+	return kcmp(getpid(), getpid(), KCMP_SYSVSEM, 0, 0) == 0;
+}
+
  static void setup(void)
  {
  	stack = SAFE_MALLOC(STACK_SIZE);
+
+	if (is_kcmp_supported_flag == -1)

This statement is not needed. We can simply store the variable because in the case malloc() will fail, we will never reach verify_kcmp() function anyway. setup() is called once, unless we use tst_variant, which is not our case here.

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

Quoted 9 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +2 -0
+		is_kcmp_supported_flag = is_kcmp_supported();
  }
 
  static void cleanup(void)
@@ -64,6 +74,14 @@ static void verify_kcmp(unsigned int n)
  	int res;
  	struct tcase *tc = &tcases[n];
 
+    // Handle the case for KCMP_SYSVSEM specifically

This comment is not needed. Also, please run "make check" on the test before sending the patch so you will have the chance to verify errors.

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

Quoted 2 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +2 -0
+	if (tc->kcmp_type == KCMP_SYSVSEM) {
+		if (is_kcmp_supported_flag == 0) {

nit: in LTP we commonly use "!is_kcmp_supported_flag" format.

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

Quoted 8 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +5 -0
+			tst_res(TCONF, "Kernel does not support KCMP_SYSVSEM, skipping test.");
+			return;
+		}
+	}
+
  	pid1 = getpid();
  	tst_res(TINFO, "Testing %s", tc->desc);
 

Kind regards,
Andrea Cervesato

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Dorinda Bassey

Hi!

Quoted 31 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.

---
v2 changes
fix coding style
use kcmp() instead of syscall()
do is_kcmp_supported() check in the setup and
cache result
use tst_res instead of tst_brk

 testcases/kernel/syscalls/kcmp/kcmp03.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
testcases/kernel/syscalls/kcmp/kcmp03.c +3 -0
index 37d5118d5..8610cea46 100644
@@ -42,9 +42,19 @@ static struct tcase {
 	{ARGS(CLONE_SYSVSEM, KCMP_SYSVSEM)}
 };
 
+static int is_kcmp_supported_flag = -1;
+
+static int is_kcmp_supported(void)

testcases/kernel/syscalls/kcmp/kcmp03.c static struct tcase { · line 57

Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +7 -0
+{
+	return kcmp(getpid(), getpid(), KCMP_SYSVSEM, 0, 0) == 0;
+}
+
 static void setup(void)
 {
 	stack = SAFE_MALLOC(STACK_SIZE);
+
+	if (is_kcmp_supported_flag == -1)
+		is_kcmp_supported_flag = is_kcmp_supported();

The setup is executed once so all we need to do here is:

	is_kcmp_supported_flag = is_kmcp_supported();

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

Quoted 8 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +1 -0
 }
 
 static void cleanup(void)
@@ -64,6 +74,14 @@ static void verify_kcmp(unsigned int n)
 	int res;
 	struct tcase *tc = &tcases[n];
 
+    // Handle the case for KCMP_SYSVSEM specifically

This comment is not add any information because the if does exactly what the comment say. We do not add comments like this into LTP.

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

Quoted 9 lines
testcases/kernel/syscalls/kcmp/kcmp03.c +7 -0
+	if (tc->kcmp_type == KCMP_SYSVSEM) {
+		if (is_kcmp_supported_flag == 0) {
+			tst_res(TCONF, "Kernel does not support KCMP_SYSVSEM, skipping test.");
+			return;
+		}
+	}
+
 	pid1 = getpid();
 	tst_res(TINFO, "Testing %s", tc->desc);

The rest looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp