WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / enable_stats.c
blob2cb2085917e7dabe4692bd3487fabf8952edef79
1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 #include "test_enable_stats.skel.h"
5 void test_enable_stats(void)
7 struct test_enable_stats *skel;
8 int stats_fd, err, prog_fd;
9 struct bpf_prog_info info;
10 __u32 info_len = sizeof(info);
11 int duration = 0;
13 skel = test_enable_stats__open_and_load();
14 if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n"))
15 return;
17 stats_fd = bpf_enable_stats(BPF_STATS_RUN_TIME);
18 if (CHECK(stats_fd < 0, "get_stats_fd", "failed %d\n", errno)) {
19 test_enable_stats__destroy(skel);
20 return;
23 err = test_enable_stats__attach(skel);
24 if (CHECK(err, "attach_raw_tp", "err %d\n", err))
25 goto cleanup;
27 test_enable_stats__detach(skel);
29 prog_fd = bpf_program__fd(skel->progs.test_enable_stats);
30 memset(&info, 0, info_len);
31 err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len);
32 if (CHECK(err, "get_prog_info",
33 "failed to get bpf_prog_info for fd %d\n", prog_fd))
34 goto cleanup;
35 if (CHECK(info.run_time_ns == 0, "check_stats_enabled",
36 "failed to enable run_time_ns stats\n"))
37 goto cleanup;
39 CHECK(info.run_cnt != skel->bss->count, "check_run_cnt_valid",
40 "invalid run_cnt stats\n");
42 cleanup:
43 test_enable_stats__destroy(skel);
44 close(stats_fd);