treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / prog_run_xattr.c
blob5dd89b941f53f397de2aa13e984d7371d47e8a97
1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 void test_prog_run_xattr(void)
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,
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;
23 memset(buf, 0, sizeof(buf));
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);
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);
33 CHECK_ATTR(buf[5] != 0, "overflow",
34 "BPF_PROG_TEST_RUN ignored size hint\n");
36 tattr.data_out = NULL;
37 tattr.data_size_out = 0;
38 errno = 0;
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);
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);
48 bpf_object__close(obj);