WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / prog_run_xattr.c
blob935a294f049a23fc060b8bbb4358114a07229647
1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 #include <network_helpers.h>
5 void test_prog_run_xattr(void)
7 const char *file = "./test_pkt_access.o";
8 struct bpf_object *obj;
9 char buf[10];
10 int err;
11 struct bpf_prog_test_run_attr tattr = {
12 .repeat = 1,
13 .data_in = &pkt_v4,
14 .data_size_in = sizeof(pkt_v4),
15 .data_out = buf,
16 .data_size_out = 5,
19 err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj,
20 &tattr.prog_fd);
21 if (CHECK_ATTR(err, "load", "err %d errno %d\n", err, errno))
22 return;
24 memset(buf, 0, sizeof(buf));
26 err = bpf_prog_test_run_xattr(&tattr);
27 CHECK_ATTR(err != -1 || errno != ENOSPC || tattr.retval, "run",
28 "err %d errno %d retval %d\n", err, errno, tattr.retval);
30 CHECK_ATTR(tattr.data_size_out != sizeof(pkt_v4), "data_size_out",
31 "incorrect output size, want %zu have %u\n",
32 sizeof(pkt_v4), tattr.data_size_out);
34 CHECK_ATTR(buf[5] != 0, "overflow",
35 "BPF_PROG_TEST_RUN ignored size hint\n");
37 tattr.data_out = NULL;
38 tattr.data_size_out = 0;
39 errno = 0;
41 err = bpf_prog_test_run_xattr(&tattr);
42 CHECK_ATTR(err || errno || tattr.retval, "run_no_output",
43 "err %d errno %d retval %d\n", err, errno, tattr.retval);
45 tattr.data_size_out = 1;
46 err = bpf_prog_test_run_xattr(&tattr);
47 CHECK_ATTR(err != -EINVAL, "run_wrong_size_out", "err %d\n", err);
49 bpf_object__close(obj);