[LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full

Cyril Hrubis chrubis@suse.cz
Thu Apr 11 12:42:14 CEST 2024


Hi!
> > +{
> > +	int pipefd[2];
> > +	char buf[bytes];
> > +	size_t i;
> > +	int fail = 0;
> > +
> > +	memset(buf, 0xff, sizeof(buf));
> > +
> > +	SAFE_PIPE(pipefd);
> > +
> > +	TST_EXP_POSITIVE(splice(dev_fd, NULL, pipefd[1], NULL, sizeof(buf), 0));
> > +
> > +	if (!TST_PASS)
> > +		goto ret;
> > +
> > +	SAFE_READ(1, pipefd[0], buf, sizeof(buf));
> > +
> > +	for (i = 0; i < sizeof(buf); i++) {
> > +		if (buf[i])
> > +			fail++;
> > +	}
> > +
> > +	if (fail)
> > +		tst_res(TFAIL, "Non-zero bytes spliced from /dev/zero");
> Maybe write how many fail we have?
> 
> I also agree with Jan's comment about missing TST_RET, which is in splice09.

Will fix both.

> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> > +	else
> > +		tst_res(TPASS, "All bytes spliced from /dev/zero are zeroed");
> > +
> > +ret:
> > +	SAFE_CLOSE(pipefd[0]);
> > +	SAFE_CLOSE(pipefd[1]);
> > +}
> > +
> > +static void verify_splice(unsigned int n)
> > +{
> > +	unsigned int bytes = 1009 * n;
> 
> Out of curiosity, why 1009 and not 1000?

Because people tend to use buffers that are either power of two or
multiples of 100 or 1000. The 1009 is a prime number which means that
multiples of it will have "unexpected" sizes.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list