[LTP] [PATCH 3/3] syscalls/kcmp03.c: Add new testcase

Cyril Hrubis chrubis@suse.cz
Tue Jul 19 16:21:19 CEST 2016


Hi!
> +#ifndef CLONE_SYSVSEM
> +#define CLONE_SYSVSEM	0x00040000
> +#endif
> +
> +#ifndef CLONE_IO
> +#define CLONE_IO	0x80000000
> +#endif

These should rather go to the lapi/namespaces_constants.h

> +#define STACK_SIZE	(1024*1024)
> +
> +static int pid1;
> +static int pid2;
> +
> +static struct tcase {
> +	int clone_type;
> +	int kcmp_type;
> +} tcases[] = {
> +	{CLONE_VM, KCMP_VM},
> +	{CLONE_FS, KCMP_FS},
> +	{CLONE_IO, KCMP_IO},
> +	{CLONE_SYSVSEM, KCMP_SYSVSEM}
> +};
> +
> +static int do_child(void *arg)
> +{
> +	pid2 = getpid();
> +
> +	TEST(kcmp(pid1, pid2, *(int *)arg, 0, 0));
> +
> +	if (TEST_RETURN == -1) {
> +		tst_res(TFAIL | TTERRNO, "kcmp() failed unexpectedly");
> +		return 1;
> +	}
> +
> +	if (TEST_RETURN == 0) {
> +		tst_res(TPASS, "kcmp() returned the expected value");
> +	} else {
> +		tst_res(TFAIL, "kcmp() returned the unexpected value");
> +		return 1;

Why do we do the return 1 here if the value is not used at all? Why
don't we just fall down to the return 0; below?

> +	}
> +
> +	return 0;
> +}
> +
> +static void verify_kcmp(unsigned int n)
> +{
> +	int res;
> +	void *stack;
> +
> +	struct tcase *tc = &tcases[n];
> +
> +	pid1 = getpid();
> +
> +	stack = SAFE_MALLOC(STACK_SIZE);

Well, the stack could be allocated once in the test setup and freed in
the test cleanup.

> +	res = ltp_clone(tc->clone_type | SIGCHLD, do_child, &tc->kcmp_type,
> +			STACK_SIZE, stack);
> +	if (res == -1)
> +		tst_res(TFAIL | TERRNO, "clone() Failed");
> +
> +	SAFE_WAIT(NULL);
> +
> +	free(stack);
> +}
> +
> +static struct tst_test test = {
> +	.tid = "kcmp03",
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_kcmp,
> +	.min_kver = "3.5.0"
> +};

The rest is fine.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list