test/unlink: add failure case
#include "liburing.h"
-static int no_unlink;
-
static int test_unlink(struct io_uring *ring, const char *old)
{
struct io_uring_cqe *cqe;
@@ -38,19 +36,9 @@ static int test_unlink(struct io_uring *ring, const char *old)
fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
- if (cqe->res < 0) {
- if (cqe->res == -EBADF || cqe->res == -EINVAL) {
- fprintf(stdout, "Unlink not supported, skipping\n");
- no_unlink = 1;
- goto out;
- }
- fprintf(stderr, "rename: %s\n", strerror(-cqe->res));
- goto err;
- }
-
-out:
+ ret = cqe->res;
io_uring_cqe_seen(ring, cqe);
- return 0;
+ return ret;
err:
return 1;
}
@@ -93,14 +81,16 @@ int main(int argc, char *argv[])
}
ret = test_unlink(&ring, buf);
- if (ret) {
- fprintf(stderr, "test_rename failed\n");
- return ret;
- }
- if (no_unlink) {
+ if (ret < 0) {
+ if (ret == -EBADF || ret == -EINVAL) {
+ fprintf(stdout, "Unlink not supported, skipping\n");
unlink(buf);
return 0;
}
+ fprintf(stderr, "rename: %s\n", strerror(-ret));
+ goto err;
+ } else if (ret)
+ goto err;
ret = stat_file(buf);
if (ret != ENOENT) {
@@ -108,5 +98,14 @@ int main(int argc, char *argv[])
return 1;
}
+ ret = test_unlink(&ring, "/3/2/3/1/z/y");
+ if (ret != -ENOENT) {
+ fprintf(stderr, "invalid unlink got %s\n", strerror(-ret));
+ return 1;
+ }
+
return 0;
+err:
+ unlink(buf);
+ return 1;
}
