From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/1] syscalls/splice04: add test for splice() from pipe to pipe
Date: Mon, 10 Apr 2017 16:31:18 +0200 [thread overview]
Message-ID: <20170410143118.GA21811@rei.lan> (raw)
In-Reply-To: <1491375303-1418-1-git-send-email-bxue@redhat.com>
Hi!
> +static void setup(void)
> +{
> + int i;
> +
> + if (tst_parse_int(str_len_data, &num_len_data, 1, MAX_DATA_LEN))
> + tst_brk(TBROK, "Invalid length of data: '%s'", str_len_data);
> + tst_res(TINFO, "splice size = %d\n", num_len_data);
^
The \n should be removed as it
adds a second newline after the
message.
> + arr_in = SAFE_MALLOC(num_len_data);
> + arr_out = SAFE_MALLOC(num_len_data);
> + for (i = 0; i < num_len_data; i++)
> + arr_in[i] = i & 0xff;
> +}
> +
> +static void cleanup(void)
> +{
> + free(arr_in);
> + free(arr_out);
> +}
> +
> +static void pipe_pipe(void)
> +{
> + int pp1[2], pp2[2], i;
> +
> + SAFE_PIPE(pp1);
> + SAFE_PIPE(pp2);
> + SAFE_WRITE(1, pp1[1], arr_in, num_len_data);
> + if (splice(pp1[0], NULL, pp2[1], NULL, num_len_data, SPLICE_F_MOVE) != num_len_data)
> + tst_res(TFAIL, "incomplete splice operation.");
We should print the return value from the splice and errno as well and
also close the fds and return.
ret = splice(...)
if (ret != num_len_data) {
tst_res(TFAIL | TERRNO, "Splice returned %i", ret);
goto exit;
}
> + SAFE_READ(1, pp2[0], arr_out, num_len_data);
> +
> + SAFE_CLOSE(pp1[1]);
> + SAFE_CLOSE(pp1[0]);
> + SAFE_CLOSE(pp2[1]);
> + SAFE_CLOSE(pp2[0]);
> +
> + for (i = 0; i < num_len_data; i++) {
> + if (arr_in[i] != arr_out[i]) {
> + tst_res(TFAIL, "splice(2) from pipe to pipe fails.");
We may print the actual and expected value, something as:
tst_res(TFAIL, "wrong data at %i have %i expected %i",
i, arr_out[i], arr_in[i]);
> + return;
And do the goto exit; to close the fds.
> + }
> + }
> + tst_res(TPASS, "splice(2) from pipe to pipe run pass.");
> + return;
^
The return here is useless
Here we should add the exit label
exit:
SAFE_CLOSE(pp1[1]);
SAFE_CLOSE(pp1[0]);
SAFE_CLOSE(pp2[1]);
SAFE_CLOSE(pp2[0]);
> +}
> +
> +static struct tst_test test = {
> + .tid = "splice04",
> + .test_all = pipe_pipe,
> + .setup = setup,
> + .cleanup = cleanup,
> + .options = options,
> + .min_kver = "2.6.31"
> +};
> --
> 1.8.3.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-04-10 14:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-05 6:55 [LTP] [PATCH v3 1/1] syscalls/splice04: add test for splice() from pipe to pipe bxue
2017-04-10 14:31 ` Cyril Hrubis [this message]
2017-04-10 14:32 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170410143118.GA21811@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox