This source file includes following definitions.
- test_prog_run_xattr
1
2 #include <test_progs.h>
3
4 void test_prog_run_xattr(void)
5 {
6 const char *file = "./test_pkt_access.o";
7 struct bpf_object *obj;
8 char buf[10];
9 int err;
10 struct bpf_prog_test_run_attr tattr = {
11 .repeat = 1,
12 .data_in = &pkt_v4,
13 .data_size_in = sizeof(pkt_v4),
14 .data_out = buf,
15 .data_size_out = 5,
16 };
17
18 err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj,
19 &tattr.prog_fd);
20 if (CHECK_ATTR(err, "load", "err %d errno %d\n", err, errno))
21 return;
22
23 memset(buf, 0, sizeof(buf));
24
25 err = bpf_prog_test_run_xattr(&tattr);
26 CHECK_ATTR(err != -1 || errno != ENOSPC || tattr.retval, "run",
27 "err %d errno %d retval %d\n", err, errno, tattr.retval);
28
29 CHECK_ATTR(tattr.data_size_out != sizeof(pkt_v4), "data_size_out",
30 "incorrect output size, want %lu have %u\n",
31 sizeof(pkt_v4), tattr.data_size_out);
32
33 CHECK_ATTR(buf[5] != 0, "overflow",
34 "BPF_PROG_TEST_RUN ignored size hint\n");
35
36 tattr.data_out = NULL;
37 tattr.data_size_out = 0;
38 errno = 0;
39
40 err = bpf_prog_test_run_xattr(&tattr);
41 CHECK_ATTR(err || errno || tattr.retval, "run_no_output",
42 "err %d errno %d retval %d\n", err, errno, tattr.retval);
43
44 tattr.data_size_out = 1;
45 err = bpf_prog_test_run_xattr(&tattr);
46 CHECK_ATTR(err != -EINVAL, "run_wrong_size_out", "err %d\n", err);
47
48 bpf_object__close(obj);
49 }