[LTP] [PATCH 2/2] syscalls: Add test for splicing to /dev/zero and /dev/null

Petr Vorel pvorel@suse.cz
Thu Mar 21 10:33:50 CET 2024


Hi Cyril,

...
> +#define _GNU_SOURCE
> +#include "tst_test.h"
> +
> +static const char *test_devices[] = {
checkpatch.pl suggests:
static const char * const test_devices[] = {

> +	"/dev/null",
> +	"/dev/zero",
> +};
> +
> +static void verify_splice(unsigned int n)
> +{
> +	char buf[1024];
> +	char dev_fd;
> +	int pipefd[2];
> +
> +	memset(buf, 0xff, sizeof(buf));
> +
> +	tst_res(TINFO, "Testing %s", test_devices[n]);
> +
> +	dev_fd = SAFE_OPEN(test_devices[n], O_WRONLY);
> +
> +	SAFE_PIPE(pipefd);
> +	SAFE_WRITE(1, pipefd[1], buf, sizeof(buf));
I wonder if write() fails, we don't get SAFE_CLOSE() calls, right?

Otherwise LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> +
> +	TST_EXP_POSITIVE(splice(pipefd[0], NULL, dev_fd, NULL, sizeof(buf), 0));
> +
> +	if (TST_PASS && TST_RET != sizeof(buf))
> +		tst_res(TFAIL, "Wrote only part of the pipe buffer");
> +	else
> +		tst_res(TPASS, "Wrote whole pipe buffer");
> +
> +	SAFE_CLOSE(pipefd[0]);
> +	SAFE_CLOSE(pipefd[1]);
> +	SAFE_CLOSE(dev_fd);
> +}
> +
> +static struct tst_test test = {
> +	.test = verify_splice,
> +	.tcnt = ARRAY_SIZE(test_devices),
> +	.min_kver = "6.7",
> +};


More information about the ltp mailing list