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