extra tests
cover extra tests
2 and 3 add extra tests that were useful during the SCM patching and rsrc refactoring. 1/3 tames the multicqe_drain's execution time.
Pavel Begunkov (3):
tests: reduce multicqe_drain waiting time
tests: extend scm cycle breaking tests
tests: add more file registration tests
test/file-register.c | 95 ++++++++++++++++++++++++++++++++++++++++++ test/multicqes_drain.c | 4 +- test/ring-leak.c | 84 +++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 2 deletions(-)
Signature · 1 line
2.35.2
PATCH 1/3 tests: reduce multicqe_drain waiting time
sleep(4) is too long and not needed, wait just for one second, should be good enough.
--- test/multicqes_drain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
test/multicqes_drain.c +2 -2
@@ -224,7 +224,7 @@ static int test_generic_drain(struct io_uring *ring) goto err; } -sleep (4 ); +sleep (1 );// TODO: randomize event triggerring order for (i =0 ; i < max_entry; i++) {if (si[i].op != multi && si[i].op != single)
@@ -233,7 +233,7 @@ static int test_generic_drain(struct io_uring *ring)if (trigger_event (pipes[i])) goto err; } -sleep (5 ); +sleep (1 ); i =0 ;while (!io_uring_peek_cqe (ring, &cqe)) { cqe_data[i] = cqe->user_data;
Signature · 1 line
2.35.2
PATCH 2/3 tests: extend scm cycle breaking tests
In reply to Pavel BegunkovAdd a test with file ref dependency, which is actually checks that the files are removed and put.
--- test/ring-leak.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
test/ring-leak.c +84 -0
@@ -131,12 +131,84 @@ static int test_iowq_request_cancel(void) ret =read (fds[0 ], buffer,10 );if (ret <0 )perror ("read" ); +close (fds[0 ]); +return 0 ; +} + +static int test_scm_cycles (bool update) +{ +char buffer[128 ]; +struct io_uring ring; +int i, ret; +int sp[2 ], fds[2 ], reg_fds[4 ]; + +if (socketpair (AF_UNIX ,SOCK_DGRAM ,0 , sp) !=0 ) { +perror ("Failed to create Unix-domain socket pair\n" ); +return 1 ; + } + ret =io_uring_queue_init (8 , &ring,0 ); +if (ret <0 ) { +fprintf (stderr,"failed to init io_uring: %s\n" ,strerror (-ret)); +return ret; + } +if (pipe (fds)) { +perror ("pipe" ); +return -1 ; + } +send_fd (sp[0 ], ring.ring_fd); + +/* register an empty set for updates */ +if (update) { +for (i =0 ; i <4 ; i++) + reg_fds[i] =-1 ; + ret =io_uring_register_files (&ring, reg_fds,4 ); +if (ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + } + } + + reg_fds[0 ] = fds[0 ]; + reg_fds[1 ] = fds[1 ]; + reg_fds[2 ] = sp[0 ]; + reg_fds[3 ] = sp[1 ]; +if (update) { + ret =io_uring_register_files_update (&ring,0 , reg_fds,4 ); +if (ret !=4 ) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + } + }else { + ret =io_uring_register_files (&ring, reg_fds,4 ); +if (ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + } + } + +close (fds[1 ]); +close (sp[0 ]); +close (sp[1 ]); + +/* should unregister files and close the write fd */ +io_uring_queue_exit (&ring); + +/* +* We're trying to wait for the ring to "really" exit, that will be +* done async. For that rely on the registered write end to be closed +* after ring quiesce, so failing read from the other pipe end. +*/ + ret =read (fds[0 ], buffer,10 ); +if (ret <0 ) +perror ("read" ); +close (fds[0 ]);return 0 ; }int main (int argc,char *argv[]) {int sp[2 ], pid, ring_fd, ret; +int i;if (argc >1 )return 0 ;
@@ -147,6 +219,18 @@ int main(int argc, char *argv[])return 1 ; } +for (i =0 ; i <2 ; i++) { +bool update = !!(i &1 ); + + ret =test_scm_cycles (update); +if (ret) { +fprintf (stderr,"test_scm_cycles() failed %i\n" , + update); +return 1 ; + } +break ; + } +if (socketpair (AF_UNIX ,SOCK_DGRAM ,0 , sp) !=0 ) {perror ("Failed to create Unix-domain socket pair\n" );return 1 ;
Signature · 1 line
2.35.2
PATCH 3/3 tests: add more file registration tests
In reply to Pavel BegunkovAdd tests for file registration failing in the middle of the fd set, and mixing files that need and don't SCM accounting + checking for underflows.
--- test/file-register.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
test/file-register.c +95 -0
@@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)return 0 ; } +/* mix files requiring SCM-accounting and not in a single register */ +static int test_mixed_af_unix (void ) +{ +struct io_uring ring; +int i, ret, fds[2 ]; +int reg_fds[32 ]; +int sp[2 ]; + + ret =io_uring_queue_init (8 , &ring,0 ); +if (ret <0 ) { +fprintf (stderr,"failed to init io_uring: %s\n" ,strerror (-ret)); +return ret; + } +if (pipe (fds)) { +perror ("pipe" ); +return -1 ; + } +if (socketpair (AF_UNIX ,SOCK_DGRAM ,0 , sp) !=0 ) { +perror ("Failed to create Unix-domain socket pair\n" ); +return 1 ; + } + +for (i =0 ; i <16 ; i++) { + reg_fds[i *2 ] = fds[0 ]; + reg_fds[i *2 +1 ] = sp[0 ]; + } + ret =io_uring_register_files (&ring, reg_fds,32 ); +if (!ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + } + +close (fds[0 ]); +close (fds[1 ]); +close (sp[0 ]); +close (sp[1 ]); +io_uring_queue_exit (&ring); +return 0 ; +} + +static int test_partial_register_fail (void ) +{ +char buffer[128 ]; +struct io_uring ring; +int ret, fds[2 ]; +int reg_fds[5 ]; + + ret =io_uring_queue_init (8 , &ring,0 ); +if (ret <0 ) { +fprintf (stderr,"failed to init io_uring: %s\n" ,strerror (-ret)); +return ret; + } +if (pipe (fds)) { +perror ("pipe" ); +return -1 ; + } + +/* +* Expect register to fail as it doesn't support io_uring fds, shouldn't +* leave any fds referenced afterwards. +*/ + reg_fds[0 ] = fds[0 ]; + reg_fds[1 ] = fds[1 ]; + reg_fds[2 ] =-1 ; + reg_fds[3 ] = ring.ring_fd; + reg_fds[4 ] =-1 ; + ret =io_uring_register_files (&ring, reg_fds,5 ); +if (!ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + } + +/* ring should have fds referenced, can close them */ +close (fds[1 ]); + +/* confirm that fds[1] is actually close and to ref'ed by io_uring */ + ret =read (fds[0 ], buffer,10 ); +if (ret <0 ) +perror ("read" ); +close (fds[0 ]); +io_uring_queue_exit (&ring); +return 0 ; +}int main (int argc,char *argv[]) {
@@ -854,5 +937,17 @@ int main(int argc, char *argv[])return 1 ; } + ret =test_mixed_af_unix (); +if (ret) { +printf ("test_mixed_af_unix failed\n" ); +return 1 ; + } + + ret =test_partial_register_fail (); +if (ret) { +printf ("test_partial_register_fail failed\n" ); +return ret; + } +return 0 ; }
Signature · 1 line
2.35.2
Jens Axboe
maintainerRe: [PATCH liburing 3/3] tests: add more file registration tests
Quoted 30 lines · Pavel Begunkov
test/file-register.c +22
-0@@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)return 0 ; } +/* mix files requiring SCM-accounting and not in a single register */ +static int test_mixed_af_unix (void ) +{ +struct io_uring ring; +int i, ret, fds[2 ]; +int reg_fds[32 ]; +int sp[2 ]; + + ret =io_uring_queue_init (8 , &ring,0 ); +if (ret <0 ) { +fprintf (stderr,"failed to init io_uring: %s\n" ,strerror (-ret)); +return ret; + } +if (pipe (fds)) { +perror ("pipe" ); +return -1 ; + } +if (socketpair (AF_UNIX ,SOCK_DGRAM ,0 , sp) !=0 ) { +perror ("Failed to create Unix-domain socket pair\n" ); +return 1 ; + } +
test/file-register.c static int test_fixed_removal_ordering(void) · line 779
Quoted 10 lines
test/file-register.c +9
-0+for (i =0 ; i <16 ; i++) { + reg_fds[i *2 ] = fds[0 ]; + reg_fds[i *2 +1 ] = sp[0 ]; + } + ret =io_uring_register_files (&ring, reg_fds,32 ); +if (!ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + }
This check looks wrong.
Signature · 1 line
Jens Axboe
Re: (subset) [PATCH liburing 0/3] extra tests
In reply to Pavel BegunkovQuoted 9 lines · Pavel Begunkov
2 and 3 add extra tests that were useful during the SCM patching and rsrc refactoring. 1/3 tames the multicqe_drain's execution time.
Pavel Begunkov (3):
tests: reducemulticqe_drainwaiting time
tests: extend scm cycle breaking tests
tests: add more file registration tests[...]
Applied, thanks!
[1/3] tests: reduce multicqe_drain waiting time
commit: e0aa6fceed8e9a36325ae3d6d83b0dfb73aea2ca
[2/3] tests: extend scm cycle breaking tests
commit: c1459b2c99f0bb2554d181d9bf55388814add1a5Best regards,
Signature · 1 line
Jens Axboe
Re: [PATCH liburing 3/3] tests: add more file registration tests
In reply to Jens AxboeQuoted 36 lines · Jens Axboe
Quoted 35 lines · Pavel Begunkov
test/file-register.c +26
-0@@ -745,7 +745,90 @@ static int test_fixed_removal_ordering(void)return 0 ; } +/* mix files requiring SCM-accounting and not in a single register */ +static int test_mixed_af_unix (void ) +{ +struct io_uring ring; +int i, ret, fds[2 ]; +int reg_fds[32 ]; +int sp[2 ]; + + ret =io_uring_queue_init (8 , &ring,0 ); +if (ret <0 ) { +fprintf (stderr,"failed to init io_uring: %s\n" ,strerror (-ret)); +return ret; + } +if (pipe (fds)) { +perror ("pipe" ); +return -1 ; + } +if (socketpair (AF_UNIX ,SOCK_DGRAM ,0 , sp) !=0 ) { +perror ("Failed to create Unix-domain socket pair\n" ); +return 1 ; + } + +for (i =0 ; i <16 ; i++) { + reg_fds[i *2 ] = fds[0 ]; + reg_fds[i *2 +1 ] = sp[0 ]; + }
Quoted 7 lines
test/file-register.c static int test_fixed_removal_ordering(void) · line 779
Quoted 5 lines
test/file-register.c +5
-0+ ret =io_uring_register_files (&ring, reg_fds,32 ); +if (!ret) { +fprintf (stderr,"file_register: %d\n" , ret); +return ret; + }This check looks wrong.
Agree, resending it
Signature · 1 line
Pavel Begunkov