Message ID | 20240528034718.31798-1-wegao@suse.com |
---|---|
State | Rejected |
Headers | show |
Series | [v1] pwritev201.c: Add check for RWF_APPEND flag | expand |
Hi Wei, On 5/28/24 05:47, Wei Gao via ltp wrote: > Signed-off-by: Wei Gao <wegao@suse.com> > --- > .../kernel/syscalls/pwritev2/pwritev201.c | 35 ++++++++++++------- > 1 file changed, 23 insertions(+), 12 deletions(-) > > diff --git a/testcases/kernel/syscalls/pwritev2/pwritev201.c b/testcases/kernel/syscalls/pwritev2/pwritev201.c > index 987412ba8..cb329d8fc 100644 > --- a/testcases/kernel/syscalls/pwritev2/pwritev201.c > +++ b/testcases/kernel/syscalls/pwritev2/pwritev201.c > @@ -2,6 +2,7 @@ > /* > * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> > + * Copyright (c) 2024 SUSE LLC <wegao@suse.com> > */ > > /*\ > @@ -15,6 +16,9 @@ > * - If the file offset argument is -1, pwritev2() should succeed in > * writing the expected content of data and the current file offset > * is used and changed after writing. > + * - If the file flag argument is RWF_APPEND, pwritev2() should succeed in > + * writing the expected content to end of file. The offset argument does > + * not changed after writing except offset argument is -1. "If flags argument is RWF_APPEND, pwritev2() should write the expected content to the end of the file. If offset is -1, verify that current file offset is updated." > */ > > #define _GNU_SOURCE > @@ -42,13 +46,16 @@ static struct tcase { > off_t write_off; > ssize_t size; > off_t exp_off; > + int flag; > } tcases[] = { > - {0, 1, 0, CHUNK, 0}, > - {CHUNK, 2, 0, CHUNK, CHUNK}, > - {0, 1, CHUNK / 2, CHUNK, 0}, > - {0, 1, -1, CHUNK, CHUNK}, > - {0, 2, -1, CHUNK, CHUNK}, > - {CHUNK, 1, -1, CHUNK, CHUNK * 2}, > + {0, 1, 0, CHUNK, 0, 0}, > + {CHUNK, 2, 0, CHUNK, CHUNK, 0}, > + {0, 1, CHUNK / 2, CHUNK, 0, 0}, > + {0, 1, -1, CHUNK, CHUNK, 0}, > + {0, 2, -1, CHUNK, CHUNK, 0}, > + {CHUNK, 1, -1, CHUNK, CHUNK * 2, 0}, > + {CHUNK, 1, CHUNK, CHUNK, CHUNK, RWF_APPEND}, > + {CHUNK, 1, -1, CHUNK, CHUNK * 2, RWF_APPEND}, > }; > > static void verify_pwritev2(unsigned int n) > @@ -60,7 +67,7 @@ static void verify_pwritev2(unsigned int n) > SAFE_PWRITE(1, fd, initbuf, sizeof(initbuf), 0); > SAFE_LSEEK(fd, tc->seek_off, SEEK_SET); > > - TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0)); > + TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, tc->flag)); > if (TST_RET < 0) { > tst_res(TFAIL | TTERRNO, "pwritev2() failed"); > return; > @@ -72,17 +79,21 @@ static void verify_pwritev2(unsigned int n) > return; > } > > - if (SAFE_LSEEK(fd, 0, SEEK_CUR) != tc->exp_off) { > + if (SAFE_LSEEK(fd, 0, SEEK_CUR) != tc->exp_off && !(tc->flag == RWF_APPEND && tc->write_off == -1)) { > tst_res(TFAIL, "pwritev2() had changed file offset"); "pwritev2() changed the file offset" > return; > } > > memset(preadbuf, 0, CHUNK); > > - if (tc->write_off != -1) > - SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off); > - else > - SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off); > + if (tc->flag == RWF_APPEND) > + SAFE_PREAD(1, fd, preadbuf, tc->size, sizeof(initbuf)); > + else { > + if (tc->write_off != -1) > + SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off); > + else > + SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off); > + } > > for (i = 0; i < tc->size; i++) { > if (preadbuf[i] != 0x61) Probably RWF_APPEND test should stay in a different file since verify_pwritev2() has a more complex logic and we don't want to over-engineer code with too many if statements. Kind regards, Andrea
diff --git a/testcases/kernel/syscalls/pwritev2/pwritev201.c b/testcases/kernel/syscalls/pwritev2/pwritev201.c index 987412ba8..cb329d8fc 100644 --- a/testcases/kernel/syscalls/pwritev2/pwritev201.c +++ b/testcases/kernel/syscalls/pwritev2/pwritev201.c @@ -2,6 +2,7 @@ /* * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> + * Copyright (c) 2024 SUSE LLC <wegao@suse.com> */ /*\ @@ -15,6 +16,9 @@ * - If the file offset argument is -1, pwritev2() should succeed in * writing the expected content of data and the current file offset * is used and changed after writing. + * - If the file flag argument is RWF_APPEND, pwritev2() should succeed in + * writing the expected content to end of file. The offset argument does + * not changed after writing except offset argument is -1. */ #define _GNU_SOURCE @@ -42,13 +46,16 @@ static struct tcase { off_t write_off; ssize_t size; off_t exp_off; + int flag; } tcases[] = { - {0, 1, 0, CHUNK, 0}, - {CHUNK, 2, 0, CHUNK, CHUNK}, - {0, 1, CHUNK / 2, CHUNK, 0}, - {0, 1, -1, CHUNK, CHUNK}, - {0, 2, -1, CHUNK, CHUNK}, - {CHUNK, 1, -1, CHUNK, CHUNK * 2}, + {0, 1, 0, CHUNK, 0, 0}, + {CHUNK, 2, 0, CHUNK, CHUNK, 0}, + {0, 1, CHUNK / 2, CHUNK, 0, 0}, + {0, 1, -1, CHUNK, CHUNK, 0}, + {0, 2, -1, CHUNK, CHUNK, 0}, + {CHUNK, 1, -1, CHUNK, CHUNK * 2, 0}, + {CHUNK, 1, CHUNK, CHUNK, CHUNK, RWF_APPEND}, + {CHUNK, 1, -1, CHUNK, CHUNK * 2, RWF_APPEND}, }; static void verify_pwritev2(unsigned int n) @@ -60,7 +67,7 @@ static void verify_pwritev2(unsigned int n) SAFE_PWRITE(1, fd, initbuf, sizeof(initbuf), 0); SAFE_LSEEK(fd, tc->seek_off, SEEK_SET); - TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0)); + TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, tc->flag)); if (TST_RET < 0) { tst_res(TFAIL | TTERRNO, "pwritev2() failed"); return; @@ -72,17 +79,21 @@ static void verify_pwritev2(unsigned int n) return; } - if (SAFE_LSEEK(fd, 0, SEEK_CUR) != tc->exp_off) { + if (SAFE_LSEEK(fd, 0, SEEK_CUR) != tc->exp_off && !(tc->flag == RWF_APPEND && tc->write_off == -1)) { tst_res(TFAIL, "pwritev2() had changed file offset"); return; } memset(preadbuf, 0, CHUNK); - if (tc->write_off != -1) - SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off); - else - SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off); + if (tc->flag == RWF_APPEND) + SAFE_PREAD(1, fd, preadbuf, tc->size, sizeof(initbuf)); + else { + if (tc->write_off != -1) + SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off); + else + SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off); + } for (i = 0; i < tc->size; i++) { if (preadbuf[i] != 0x61)
Signed-off-by: Wei Gao <wegao@suse.com> --- .../kernel/syscalls/pwritev2/pwritev201.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-)