test/probe: split verification into helper
#include "liburing.h"
+static int verify_probe(struct io_uring_probe *p, int full)
+{
+ if (!full && p->ops_len) {
+ fprintf(stderr, "Got ops_len=%u\n", p->ops_len);
+ return 1;
+ }
+ if (!p->last_op) {
+ fprintf(stderr, "Got last_op=%u\n", p->last_op);
+ return 1;
+ }
+ if (!full)
+ return 0;
+ /* check a few ops that must be supported */
+ if (!(p->ops[IORING_OP_NOP].flags & IO_URING_OP_SUPPORTED)) {
+ fprintf(stderr, "NOP not supported!?\n");
+ return 1;
+ }
+ if (!(p->ops[IORING_OP_READV].flags & IO_URING_OP_SUPPORTED)) {
+ fprintf(stderr, "READV not supported!?\n");
+ return 1;
+ }
+ if (!(p->ops[IORING_OP_WRITE].flags & IO_URING_OP_SUPPORTED)) {
+ fprintf(stderr, "READV not supported!?\n");
+ return 1;
+ }
+
+ return 0;
+}
+
static int test_probe(struct io_uring *ring)
{
struct io_uring_probe *p;
@@ -21,47 +50,35 @@ static int test_probe(struct io_uring *ring)
ret = io_uring_register_probe(ring, p, 0);
if (ret == -EINVAL) {
fprintf(stdout, "Probe not supported, skipping\n");
- return 0;
+ goto out;
} else if (ret) {
fprintf(stdout, "Probe returned %d\n", ret);
- return 1;
+ goto err;
}
- if (p->ops_len) {
- fprintf(stderr, "Got ops_len=%u\n", p->ops_len);
- return 1;
- }
- if (!p->last_op) {
- fprintf(stderr, "Got last_op=%u\n", p->last_op);
- return 1;
- }
+ if (verify_probe(p, 0))
+ goto err;
/* now grab for all entries */
memset(p, 0, len);
ret = io_uring_register_probe(ring, p, 256);
if (ret == -EINVAL) {
fprintf(stdout, "Probe not supported, skipping\n");
- return 0;
+ goto err;
} else if (ret) {
fprintf(stdout, "Probe returned %d\n", ret);
- return 1;
+ goto err;
}
- /* check a few ops that must be supported */
- if (!(p->ops[IORING_OP_NOP].flags & IO_URING_OP_SUPPORTED)) {
- fprintf(stderr, "NOP not supported!?\n");
- return 1;
- }
- if (!(p->ops[IORING_OP_READV].flags & IO_URING_OP_SUPPORTED)) {
- fprintf(stderr, "READV not supported!?\n");
- return 1;
- }
- if (!(p->ops[IORING_OP_WRITE].flags & IO_URING_OP_SUPPORTED)) {
- fprintf(stderr, "READV not supported!?\n");
- return 1;
- }
+ if (verify_probe(p, 1))
+ goto err;
+out:
+ free(p);
return 0;
+err:
+ free(p);
+ return 1;
}
int main(int argc, char *argv[])
