[LTP] [PATCH v2] kcmp03: Add check for KCMP_SYSVSEM before running test
Dorinda Bassey
dbassey@redhat.com
Mon Feb 17 13:43:48 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>
---
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(+)
diff --git a/testcases/kernel/syscalls/kcmp/kcmp03.c b/testcases/kernel/syscalls/kcmp/kcmp03.c
index 37d5118d5..8610cea46 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp03.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp03.c
@@ -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);
--
2.48.1
More information about the ltp
mailing list