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
;
10 struct bpf_prog_test_run_attr tattr
= {
13 .data_size_in
= sizeof(pkt_v4
),
18 err
= bpf_prog_load(file
, BPF_PROG_TYPE_SCHED_CLS
, &obj
,
20 if (CHECK_ATTR(err
, "load", "err %d errno %d\n", err
, errno
))
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;
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
);