liburing: add test for stable statx api
PATCH 1/1 liburing: add test for stable statx api
This adds a test for the statx api to verify that io-uring statx api is stable.
--- test/statx.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
test/statx.c +65 -0
@@ -77,6 +77,61 @@ err:return -1 ; } +static int test_statx_stable (struct io_uring *ring,const char *path) +{ +struct io_uring_cqe *cqe; +struct io_uring_sqe *sqe; +struct statx x1, x2; +char path1[PATH_MAX ]; +char path2[PATH_MAX ]; +int ret =-1 ; + +strcpy (path2, path); +strcpy (path1, path); + + sqe =io_uring_get_sqe (ring); +if (!sqe) { +fprintf (stderr,"get sqe failed\n" ); + goto err; + } + +io_uring_prep_statx (sqe,-1 , path1,0 ,STATX_ALL , &x1); + + ret =io_uring_submit (ring); +if (ret <=0 ) { +fprintf (stderr,"sqe submit failed: %d\n" , ret); + goto err; + } +memset (path1,0 ,sizeof (path1)); + + ret =io_uring_wait_cqe (ring, &cqe); +if (ret <0 ) { +fprintf (stderr,"wait completion %d\n" , ret); + goto err; + } + + ret = cqe->res; +io_uring_cqe_seen (ring, cqe); +if (ret) { +fprintf (stderr,"statx res = %d\n" , ret); + goto err; + } + + ret =do_statx (-1 , path2,0 ,STATX_ALL , &x2); +if (ret <0 ) +return statx_syscall_supported (); + +if (memcmp (&x1, &x2,sizeof (x1))) { +fprintf (stderr,"Miscompare between io_uring and statx\n" ); + goto err; + } + + ret =0 ; + +err: +return ret; +} +static int test_statx_fd (struct io_uring *ring,const char *path) {struct io_uring_cqe *cqe;
@@ -156,6 +211,16 @@ int main(int argc, char *argv[]) goto err; } + ret =test_statx_stable (&ring, fname); +if (ret) { +if (ret == -EINVAL ) { +fprintf (stdout,"statx not supported, skipping\n" ); + goto done; + } +fprintf (stderr,"test_statx_loop failed: %d\n" , ret); + goto err; + } + ret =test_statx_fd (&ring, fname);if (ret) {fprintf (stderr,"test_statx_fd failed: %d\n" , ret);
base-commit: d9b0a424471f5c584f1d3f370e1746925733c01a
Signature · 1 line
2.30.2
Quoted 4 lines · Stefan Roesch
test/statx.c +0
-0@@ -156,6 +211,16 @@ int main(int argc, char *argv[]) goto err; }
test/statx.c int main(int argc, char *argv[]) · line 223
Quoted 10 lines
test/statx.c +10
-0+ ret =test_statx_stable (&ring, fname); +if (ret) { +if (ret == -EINVAL ) { +fprintf (stdout,"statx not supported, skipping\n" ); + goto done; + } +fprintf (stderr,"test_statx_loop failed: %d\n" , ret); + goto err; + } +
Why do we call it test_statx_loop? Isn't the function name test_statx_stable?
Signature · 1 line
Ammar Faizi
Quoted 54 lines · Stefan Roesch
This adds a test for the statx api to verify that io-uring statx api is stable.
Signed-off-by Stefan Roesch <[email protected]>--- test/statx.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)test/statx.c +38
-0@@ -77,6 +77,61 @@ err:return -1 ; } +static int test_statx_stable (struct io_uring *ring,const char *path) +{ +struct io_uring_cqe *cqe; +struct io_uring_sqe *sqe; +struct statx x1, x2; +char path1[PATH_MAX ]; +char path2[PATH_MAX ]; +int ret =-1 ; + +strcpy (path2, path); +strcpy (path1, path); + + sqe =io_uring_get_sqe (ring); +if (!sqe) { +fprintf (stderr,"get sqe failed\n" ); + goto err; + } + +io_uring_prep_statx (sqe,-1 , path1,0 ,STATX_ALL , &x1); + + ret =io_uring_submit (ring); +if (ret <=0 ) { +fprintf (stderr,"sqe submit failed: %d\n" , ret); + goto err; + } +memset (path1,0 ,sizeof (path1)); + + ret =io_uring_wait_cqe (ring, &cqe); +if (ret <0 ) { +fprintf (stderr,"wait completion %d\n" , ret); + goto err; + } + + ret = cqe->res; +io_uring_cqe_seen (ring, cqe); +if (ret) { +fprintf (stderr,"statx res = %d\n" , ret); + goto err;
test/statx.c err: · line 127
Quoted 10 lines
test/statx.c +10
-0+ } + + ret =do_statx (-1 , path2,0 ,STATX_ALL , &x2); +if (ret <0 ) +return statx_syscall_supported (); + +if (memcmp (&x1, &x2,sizeof (x1))) { +fprintf (stderr,"Miscompare between io_uring and statx\n" ); + goto err; + }
If we fail on memcmp() here, the ret should be set to non-zero *explicitly*. Otherwise, we have zero exit code since statx returns 0 on success.
I think that one can also be simplified like this:
ret = memcmp(&x1, &x2, sizeof(x1)); if (ret) fprintf(stderr, "Miscompare between io_uring and statx\n"); return ret;
Signature · 1 line
Ammar Faizi
Quoted 54 lines · Stefan Roesch
This adds a test for the statx api to verify that io-uring statx api is stable.
Signed-off-by Stefan Roesch <[email protected]>--- test/statx.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)test/statx.c +38
-0@@ -77,6 +77,61 @@ err:return -1 ; } +static int test_statx_stable (struct io_uring *ring,const char *path) +{ +struct io_uring_cqe *cqe; +struct io_uring_sqe *sqe; +struct statx x1, x2; +char path1[PATH_MAX ]; +char path2[PATH_MAX ]; +int ret =-1 ; + +strcpy (path2, path); +strcpy (path1, path); + + sqe =io_uring_get_sqe (ring); +if (!sqe) { +fprintf (stderr,"get sqe failed\n" ); + goto err; + } + +io_uring_prep_statx (sqe,-1 , path1,0 ,STATX_ALL , &x1); + + ret =io_uring_submit (ring); +if (ret <=0 ) { +fprintf (stderr,"sqe submit failed: %d\n" , ret); + goto err; + } +memset (path1,0 ,sizeof (path1)); + + ret =io_uring_wait_cqe (ring, &cqe); +if (ret <0 ) { +fprintf (stderr,"wait completion %d\n" , ret); + goto err; + } + + ret = cqe->res; +io_uring_cqe_seen (ring, cqe); +if (ret) { +fprintf (stderr,"statx res = %d\n" , ret); + goto err;
test/statx.c err: · line 127
Quoted 10 lines
test/statx.c +10
-0+ } + + ret =do_statx (-1 , path2,0 ,STATX_ALL , &x2); +if (ret <0 ) +return statx_syscall_supported (); + +if (memcmp (&x1, &x2,sizeof (x1))) { +fprintf (stderr,"Miscompare between io_uring and statx\n" ); + goto err; + }
If we fail on memcmp() here, the ret should be set to non-zero *explicitly*. Otherwise, we have zero exit code since statx returns 0 on success.
I think that one can also be simplified like this:
[...]
ret = memcmp(&x1, &x2, sizeof(x1)); if (ret) fprintf(stderr, "Miscompare between io_uring and statx\n");
err:
return ret; }
Quoted 29 lines
test/statx.c +17
-0+ + ret =0 ; + +err: +return ret; +} +static int test_statx_fd (struct io_uring *ring,const char *path) {struct io_uring_cqe *cqe;@@ -156,6 +211,16 @@ int main(int argc, char *argv[]) goto err; } + ret =test_statx_stable (&ring, fname); +if (ret) { +if (ret == -EINVAL ) { +fprintf (stdout,"statx not supported, skipping\n" ); + goto done; + } +fprintf (stderr,"test_statx_loop failed: %d\n" , ret); + goto err; + } + ret =test_statx_fd (&ring, fname);if (ret) {fprintf (stderr,"test_statx_fd failed: %d\n" , ret);base-commit:
d9b0a424471f5c584f1d3f370e1746925733c01a
Signature · 1 line
Ammar Faizi