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

Andrea Cervesato andrea.cervesato@suse.com
Tue Feb 18 16:16:26 CET 2025


Hi,

there are still a couple of issues we can fix.

On 2/17/25 13:43, Dorinda Bassey wrote:
> 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.

> 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;
We don't need to initialize this flag.
> +
> +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.
> +		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.
> +	if (tc->kcmp_type == KCMP_SYSVSEM) {
> +		if (is_kcmp_supported_flag == 0) {
nit: in LTP we commonly use "!is_kcmp_supported_flag" format.
> +			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



More information about the ltp mailing list