pwritev201.c: Add check for RWF_APPEND flag
PATCH 1/1 pwritev201.c: Add check for RWF_APPEND flag
Signed-off-by Wei Gao <[email protected]>
--- .../kernel/syscalls/pwritev2/pwritev201.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/pwritev2/pwritev201.c +23 -12
@@ -2,6 +2,7 @@/* * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. * Author: Jinhui Huang <[email protected]> +* Copyright (c) 2024 SUSE LLC <[email protected]> */ /*\
@@ -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 )
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Quoted 18 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>--- .../kernel/syscalls/pwritev2/pwritev201.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-)testcases/kernel/syscalls/pwritev2/pwritev201.c +1
-0@@ -2,6 +2,7 @@/* * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. * Author: Jinhui Huang <[email protected]> +* Copyright (c) 2024 SUSE LLC <[email protected]> */ /*\
testcases/kernel/syscalls/pwritev2/pwritev201.c line 21
Quoted 6 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +3
-0@@ -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."
Quoted 36 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +10
-7*/ #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 ;
testcases/kernel/syscalls/pwritev2/pwritev201.c static void verify_pwritev2(unsigned int n) · line 83
Quoted 6 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +1
-1@@ -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"
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +1
-4return ; }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 )
testcases/kernel/syscalls/pwritev2/pwritev201.c static void verify_pwritev2(unsigned int n) · line 99
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +7
-0+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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp