summaryrefslogtreecommitdiff
path: root/test/probe.c
blob: 0adc03e45dcd23f9d26d3785f04f0fb4e3734011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Description: test IORING_REGISTER_PROBE
 */
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

#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;
	size_t len;
	int ret;

	len = sizeof(*p) + 256 * sizeof(struct io_uring_probe_op);
	p = calloc(1, len);
	ret = io_uring_register_probe(ring, p, 0);
	if (ret == -EINVAL) {
		fprintf(stdout, "Probe not supported, skipping\n");
		goto out;
	} else if (ret) {
		fprintf(stdout, "Probe returned %d\n", ret);
		goto err;
	}

	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");
		goto err;
	} else if (ret) {
		fprintf(stdout, "Probe returned %d\n", ret);
		goto err;
	}

	if (verify_probe(p, 1))
		goto err;

out:
	free(p);
	return 0;
err:
	free(p);
	return 1;
}

int main(int argc, char *argv[])
{
	struct io_uring ring;
	int ret;

	ret = io_uring_queue_init(8, &ring, 0);
	if (ret) {
		fprintf(stderr, "ring setup failed\n");
		return 1;
	}

	ret = test_probe(&ring);
	if (ret) {
		fprintf(stderr, "test_probe failed\n");
		return ret;
	}

	return 0;
}