tests: file create/unlink cleanup
PATCH 1/1 tests: file create/unlink cleanup
Unlink earlier if possible right after getting an fd, so tests don't leave files when exited abnormally. Also, improve test file naming in a couple of cases.
Signed-off-by Pavel Begunkov <[email protected]>
--- test/cq-overflow.c | 13 +++++++------ test/d4ae271dfaae-test.c | 4 ++-- test/eeed8b54e0df-test.c | 11 +++-------- test/fallocate.c | 9 +++------ test/fsync.c | 4 ++-- test/io-cancel.c | 9 +++++---- test/link_drain.c | 3 +-- test/read-write.c | 2 +- test/sq-poll-dup.c | 7 +++---- test/sq-poll-share.c | 6 ++---- test/submit-reuse.c | 25 +++++++++++-------------- test/thread-exit.c | 10 +++------- 12 files changed, 43 insertions(+), 60 deletions(-)
test/cq-overflow.c +7 -6
@@ -243,6 +243,7 @@ err:int main (int argc,char *argv[]) { +const char *fname =".cq-overflow" ;unsigned iters, drops;unsigned long usecs;int ret;
@@ -256,7 +257,7 @@ int main(int argc, char *argv[])return ret; } -t_create_file (".basic-rw" ,FILE_SIZE ); +t_create_file (fname,FILE_SIZE ); vecs =t_create_buffers (BUFFERS ,BS );
@@ -265,7 +266,7 @@ int main(int argc, char *argv[]) do { drops = 0; - if (test_io(".basic-rw", usecs, &drops, 0)) { + if (test_io(fname, usecs, &drops, 0)) { fprintf(stderr, "test_io nofault failed\n"); goto err; }
@@ -275,19 +276,19 @@ int main(int argc, char *argv[]) iters++; }while (iters <40 ); -if (test_io (".basic-rw" , usecs, &drops,0 )) { +if (test_io (fname, usecs, &drops,0 )) {fprintf (stderr,"test_io nofault failed\n" ); goto err; } -if (test_io (".basic-rw" , usecs, &drops,1 )) { +if (test_io (fname, usecs, &drops,1 )) {fprintf (stderr,"test_io fault failed\n" ); goto err; } -unlink (".basic-rw" ); +unlink (fname);return 0 ; err: -unlink (".basic-rw" ); +unlink (fname);return 1 ; }
test/d4ae271dfaae-test.c +2 -2
@@ -43,6 +43,8 @@ int main(int argc, char *argv[]) } fd =open (fname,O_RDONLY |O_DIRECT ); +if (fname != argv[1 ]) +unlink (fname);if (fd <0 ) {perror ("open" ); goto out;
@@ -89,8 +91,6 @@ int main(int argc, char *argv[])close (fd); out: -if (fname != argv[1 ]) -unlink (fname);io_uring_queue_exit (&ring);return ret; }
test/eeed8b54e0df-test.c +3 -8
@@ -26,6 +26,7 @@ static int get_file_fd(void)int fd; fd =open ("testfile" ,O_RDWR |O_CREAT ,0644 ); +unlink ("testfile" );if (fd <0 ) {perror ("open file" );return -1 ;
@@ -54,12 +55,6 @@ err:return fd; } -static void put_file_fd (int fd) -{ -close (fd); -unlink ("testfile" ); -} -int main (int argc,char *argv[]) {struct io_uring ring;
@@ -111,9 +106,9 @@ int main(int argc, char *argv[]) goto err; } -put_file_fd (fd); +close (fd);return 0 ; err: -put_file_fd (fd); +close (fd);return 1 ; }
test/fallocate.c +3 -6
@@ -42,6 +42,7 @@ static int test_fallocate_rlimit(struct io_uring *ring)perror ("open" );return 1 ; } +unlink (buf); sqe =io_uring_get_sqe (ring);if (!sqe) {
@@ -72,10 +73,8 @@ static int test_fallocate_rlimit(struct io_uring *ring) }io_uring_cqe_seen (ring, cqe); out: -unlink (buf);return 0 ; err: -unlink (buf);return 1 ; }
@@ -93,6 +92,7 @@ static int test_fallocate(struct io_uring *ring)perror ("open" );return 1 ; } +unlink (buf); sqe =io_uring_get_sqe (ring);if (!sqe) {
@@ -136,10 +136,8 @@ static int test_fallocate(struct io_uring *ring) } out: -unlink (buf);return 0 ; err: -unlink (buf);return 1 ; }
@@ -160,6 +158,7 @@ static int test_fallocate_fsync(struct io_uring *ring)perror ("open" );return 1 ; } +unlink (buf); sqe =io_uring_get_sqe (ring);if (!sqe) {
@@ -209,10 +208,8 @@ static int test_fallocate_fsync(struct io_uring *ring) goto err; } -unlink (buf);return 0 ; err: -unlink (buf);return 1 ; }
test/fsync.c +2 -2
@@ -63,11 +63,12 @@ static int test_barrier_fsync(struct io_uring *ring)int i, fd, ret;off_t off; - fd =open ("testfile" ,O_WRONLY |O_CREAT ,0644 ); + fd =open ("fsync-testfile" ,O_WRONLY |O_CREAT ,0644 );if (fd <0 ) {perror ("open" );return 1 ; } +unlink ("fsync-testfile" );for (i =0 ; i <ARRAY_SIZE (iovecs); i++) { iovecs[i].iov_base =t_malloc (4096 );
@@ -135,7 +136,6 @@ static int test_barrier_fsync(struct io_uring *ring) err: ret =1 ; out: -unlink ("testfile" );for (i =0 ; i <ARRAY_SIZE (iovecs); i++)free (iovecs[i].iov_base);return ret;
test/io-cancel.c +5 -4
@@ -486,6 +486,7 @@ static int test_sqpoll_cancel_iowq_requests(void)int main (int argc,char *argv[]) { +const char *fname =".io-cancel-test" ;int i, ret;if (argc >1 )
@@ -511,7 +512,7 @@ int main(int argc, char *argv[])return 1 ; } -t_create_file (".basic-rw" ,FILE_SIZE ); +t_create_file (fname,FILE_SIZE ); vecs =t_create_buffers (BUFFERS ,BS );
@@ -520,7 +521,7 @@ int main(int argc, char *argv[])int partial = (i &2 ) !=0 ;int async = (i &4 ) !=0 ; - ret =test_io_cancel (".basic-rw" , write, partial, async); + ret =test_io_cancel (fname, write, partial, async);if (ret) {fprintf (stderr,"test_io_cancel %d %d %d failed\n" , write, partial, async);
@@ -528,9 +529,9 @@ int main(int argc, char *argv[]) } } -unlink (".basic-rw" ); +unlink (fname);return 0 ; err: -unlink (".basic-rw" ); +unlink (fname);return 1 ; }
test/link_drain.c +1 -2
@@ -111,6 +111,7 @@ int test_link_drain_multi(struct io_uring *ring)perror ("open" );return 1 ; } +unlink ("testfile" ); iovecs.iov_base =t_malloc (4096 ); iovecs.iov_len =4096 ;
@@ -189,12 +190,10 @@ int test_link_drain_multi(struct io_uring *ring)free (iovecs.iov_base);close (fd); -unlink ("testfile" );return 0 ; err:free (iovecs.iov_base);close (fd); -unlink ("testfile" );return 1 ; }
test/read-write.c +1 -1
@@ -670,6 +670,7 @@ static int test_write_efbig(void)perror ("file open" ); goto err; } +unlink (".efbig" ); ret =io_uring_queue_init (32 , &ring,0 );if (ret) {
@@ -726,7 +727,6 @@ static int test_write_efbig(void) err:if (fd !=-1 )close (fd); -unlink (".efbig" );return 1 ; }
test/sq-poll-dup.c +3 -4
@@ -167,6 +167,9 @@ int main(int argc, char *argv[]) vecs =t_create_buffers (BUFFERS ,BS ); fd =open (fname,O_RDONLY |O_DIRECT ); +if (fname != argv[1 ]) +unlink (fname); +if (fd <0 ) {perror ("open" );return -1 ;
@@ -191,11 +194,7 @@ int main(int argc, char *argv[]) goto err; } -if (fname != argv[1 ]) -unlink (fname);return 0 ; err: -if (fname != argv[1 ]) -unlink (fname);return 1 ; }
test/sq-poll-share.c +2 -4
@@ -89,6 +89,8 @@ int main(int argc, char *argv[]) vecs =t_create_buffers (BUFFERS ,BS ); fd =open (fname,O_RDONLY |O_DIRECT ); +if (fname != argv[1 ]) +unlink (fname);if (fd <0 ) {perror ("open" );return -1 ;
@@ -129,11 +131,7 @@ int main(int argc, char *argv[]) ios +=BUFFERS ; } -if (fname != argv[1 ]) -unlink (fname);return 0 ; err: -if (fname != argv[1 ]) -unlink (fname);return 1 ; }
test/submit-reuse.c +11 -14
@@ -140,11 +140,6 @@ static int test_reuse(int argc, char *argv[], int split, int async)int do_unlink =1 ;void *tret; -if (argc >1 ) { - fname1 = argv[1 ]; - do_unlink =0 ; - } - ret =io_uring_queue_init_params (32 , &ring, &p);if (ret) {fprintf (stderr,"io_uring_queue_init: %d\n" , ret);
@@ -153,21 +148,29 @@ static int test_reuse(int argc, char *argv[], int split, int async)if (!(p.features &IORING_FEAT_SUBMIT_STABLE )) {fprintf (stdout,"FEAT_SUBMIT_STABLE not there, skipping\n" ); +io_uring_queue_exit (&ring); no_stable =1 ;return 0 ; } -if (do_unlink) +if (argc >1 ) { + fname1 = argv[1 ]; + do_unlink =0 ; + }else {t_create_file (fname1,FILE_SIZE ); - -t_create_file (".reuse.2" ,FILE_SIZE ); + } fd1 =open (fname1,O_RDONLY ); +if (do_unlink) +unlink (fname1);if (fd1 <0 ) {perror ("open fname1" ); goto err; } + +t_create_file (".reuse.2" ,FILE_SIZE ); fd2 =open (".reuse.2" ,O_RDONLY ); +unlink (".reuse.2" );if (fd2 <0 ) {perror ("open .reuse.2" ); goto err;
@@ -206,15 +209,9 @@ static int test_reuse(int argc, char *argv[], int split, int async)close (fd2);close (fd1);io_uring_queue_exit (&ring); -if (do_unlink) -unlink (fname1); -unlink (".reuse.2" );return 0 ; err:io_uring_queue_exit (&ring); -if (do_unlink) -unlink (fname1); -unlink (".reuse.2" );return 1 ; }
test/thread-exit.c +3 -7
@@ -86,12 +86,12 @@ int main(int argc, char *argv[]) }else { fname =".thread.exit" ; do_unlink =1 ; - } - -if (do_unlink)t_create_file (fname,4096 ); + } fd =open (fname,O_WRONLY ); +if (do_unlink) +unlink (fname);if (fd <0 ) {perror ("open" );return 1 ;
@@ -125,11 +125,7 @@ int main(int argc, char *argv[])io_uring_cqe_seen (&ring, cqe); } -if (do_unlink) -unlink (fname);return d.err; err: -if (do_unlink) -unlink (fname);return 1 ; }
Signature · 1 line
2.33.0
Quoted 3 lines · Pavel Begunkov
Unlink earlier if possible right after getting an fd, so tests don't leave files when exited abnormally. Also, improve test file naming in a couple of cases.
Applied, thanks.
Signature · 1 line
Jens Axboe