All of lore.kernel.org
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: "daisl.fnst@fujitsu.com" <daisl.fnst@fujitsu.com>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v3] syscalls/write06: Add new test
Date: Thu, 23 Dec 2021 01:42:25 +0000	[thread overview]
Message-ID: <61C3D411.8070906@fujitsu.com> (raw)
In-Reply-To: <1640117003-627-1-git-send-email-daisl.fnst@fujitsu.com>

Hi Dai
LGTM, merged!

Best Regards
Yang Xu
> Like pwrite04.c, test the write() system call with O_APPEND.
>
> Signed-off-by: Dai Shili<daisl.fnst@fujitsu.com>
> ---
>   runtest/syscalls                           |  1 +
>   testcases/kernel/syscalls/write/.gitignore |  1 +
>   testcases/kernel/syscalls/write/write06.c  | 94 ++++++++++++++++++++++++++++++
>   3 files changed, 96 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/write/write06.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index bcf3d56..32fcda4 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1699,6 +1699,7 @@ write02 write02
>   write03 write03
>   write04 write04
>   write05 write05
> +write06 write06
>
>   writev01 writev01
>   writev02 writev02
> diff --git a/testcases/kernel/syscalls/write/.gitignore b/testcases/kernel/syscalls/write/.gitignore
> index 7f36194..8529aae 100644
> --- a/testcases/kernel/syscalls/write/.gitignore
> +++ b/testcases/kernel/syscalls/write/.gitignore
> @@ -3,3 +3,4 @@
>   /write03
>   /write04
>   /write05
> +/write06
> diff --git a/testcases/kernel/syscalls/write/write06.c b/testcases/kernel/syscalls/write/write06.c
> new file mode 100644
> index 0000000..c175548
> --- /dev/null
> +++ b/testcases/kernel/syscalls/write/write06.c
> @@ -0,0 +1,94 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> + * Author: Dai Shili<daisl.fnst@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test the write() system call with O_APPEND.
> + *
> + * The full description of O_APPEND is in open(2) man-pages:
> + * The file is opened in append mode.  Before each write(2), the
> + * file offset is positioned at the end of the file, as if with lseek(2).
> + * The modification of the file offset and the write operation are
> + * performed as a single atomic step.
> + *
> + * Writing 2k data to the file, close it and reopen it with O_APPEND.
> + * Verify that the file size is 3k and offset is moved to the end of the file.
> + */
> +
> +#include<stdlib.h>
> +#include<inttypes.h>
> +#include "tst_test.h"
> +#include "tst_safe_prw.h"
> +
> +#define K1              1024
> +#define K2              (K1 * 2)
> +#define K3              (K1 * 3)
> +#define DATA_FILE       "write06_file"
> +
> +static int fd = -1;
> +static char *write_buf[2];
> +
> +static void verify_write(void)
> +{
> +	off_t off;
> +	struct stat statbuf;
> +
> +	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0666);
> +	SAFE_WRITE(1, fd, write_buf[0], K2);
> +	SAFE_CLOSE(fd);
> +
> +	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_APPEND);
> +	SAFE_FSTAT(fd,&statbuf);
> +	if (statbuf.st_size != K2)
> +		tst_res(TFAIL, "file size is %ld != K2", statbuf.st_size);
> +
> +	off = SAFE_LSEEK(fd, K1, SEEK_SET);
> +	if (off != K1)
> +		tst_brk(TBROK, "Failed to seek to K1");
> +
> +	SAFE_WRITE(1, fd, write_buf[1], K1);
> +
> +	off = SAFE_LSEEK(fd, 0, SEEK_CUR);
> +	if (off != K3)
> +		tst_res(TFAIL, "Wrong offset after write %zu expected %u", off, K3);
> +	else
> +		tst_res(TPASS, "Offset is correct after write %zu", off);
> +
> +	SAFE_FSTAT(fd,&statbuf);
> +	if (statbuf.st_size != K3)
> +		tst_res(TFAIL, "Wrong file size after append %zu expected %u", statbuf.st_size, K3);
> +	else
> +		tst_res(TPASS, "Correct file size after append %u", K3);
> +
> +	SAFE_CLOSE(fd);
> +}
> +
> +static void setup(void)
> +{
> +	memset(write_buf[0], 0, K2);
> +	memset(write_buf[1], 1, K1);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd != -1)
> +		SAFE_CLOSE(fd);
> +
> +	SAFE_UNLINK(DATA_FILE);
> +}
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_write,
> +	.bufs = (struct tst_buffers[]) {
> +		{&write_buf[0], .size = K2},
> +		{&write_buf[1], .size = K1},
> +		{}
> +	}
> +};

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      parent reply	other threads:[~2021-12-23  1:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 21:17 [LTP] [PATCH] syscalls/write06: Add new test Dai Shili
2021-12-07 13:51 ` Cyril Hrubis
2021-12-08  8:38   ` daisl.fnst
2021-12-10 10:57     ` Cyril Hrubis
2021-12-20 19:23       ` [LTP] [PATCH v2] " Dai Shili
2021-12-20  9:53         ` Petr Vorel
2021-12-21 20:03           ` [LTP] [PATCH v3] " Dai Shili
2021-12-21 19:44             ` Petr Vorel
2021-12-23  1:42             ` xuyang2018.jy [this message]

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=61C3D411.8070906@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=daisl.fnst@fujitsu.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.