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

Cyril Hrubis chrubis@suse.cz
Thu Feb 20 15:23:02 CET 2025


Hi!
> 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();

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

	is_kcmp_supported_flag = is_kmcp_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 add any information because the if does exactly what
the comment say. We do not add comments like this into LTP.

> +	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.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list