1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 #include <network_helpers.h>
5 #include "test_pkt_access.skel.h"
7 static const __u32 duration;
9 static void check_run_cnt(int prog_fd, __u64 run_cnt)
11 struct bpf_prog_info info = {};
12 __u32 info_len = sizeof(info);
15 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
16 if (CHECK(err, "get_prog_info", "failed to get bpf_prog_info for fd %d\n", prog_fd))
19 CHECK(run_cnt != info.run_cnt, "run_cnt",
20 "incorrect number of repetitions, want %llu have %llu\n", run_cnt, info.run_cnt);
23 void test_prog_run_opts(void)
25 struct test_pkt_access *skel;
26 int err, stats_fd = -1, prog_fd;
30 LIBBPF_OPTS(bpf_test_run_opts, topts,
33 .data_size_in = sizeof(pkt_v4),
38 stats_fd = bpf_enable_stats(BPF_STATS_RUN_TIME);
39 if (!ASSERT_GE(stats_fd, 0, "enable_stats good fd"))
42 skel = test_pkt_access__open_and_load();
43 if (!ASSERT_OK_PTR(skel, "open_and_load"))
46 prog_fd = bpf_program__fd(skel->progs.test_pkt_access);
48 err = bpf_prog_test_run_opts(prog_fd, &topts);
49 ASSERT_EQ(errno, ENOSPC, "test_run errno");
50 ASSERT_ERR(err, "test_run");
51 ASSERT_OK(topts.retval, "test_run retval");
53 ASSERT_EQ(topts.data_size_out, sizeof(pkt_v4), "test_run data_size_out");
54 ASSERT_EQ(buf[5], 0, "overflow, BPF_PROG_TEST_RUN ignored size hint");
56 run_cnt += topts.repeat;
57 check_run_cnt(prog_fd, run_cnt);
59 topts.data_out = NULL;
60 topts.data_size_out = 0;
64 err = bpf_prog_test_run_opts(prog_fd, &topts);
65 ASSERT_OK(errno, "run_no_output errno");
66 ASSERT_OK(err, "run_no_output err");
67 ASSERT_OK(topts.retval, "run_no_output retval");
69 run_cnt += topts.repeat;
70 check_run_cnt(prog_fd, run_cnt);
74 test_pkt_access__destroy(skel);