0001
0002 #include <test_progs.h>
0003 #include "test_enable_stats.skel.h"
0004
0005 void test_enable_stats(void)
0006 {
0007 struct test_enable_stats *skel;
0008 int stats_fd, err, prog_fd;
0009 struct bpf_prog_info info;
0010 __u32 info_len = sizeof(info);
0011 int duration = 0;
0012
0013 skel = test_enable_stats__open_and_load();
0014 if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n"))
0015 return;
0016
0017 stats_fd = bpf_enable_stats(BPF_STATS_RUN_TIME);
0018 if (CHECK(stats_fd < 0, "get_stats_fd", "failed %d\n", errno)) {
0019 test_enable_stats__destroy(skel);
0020 return;
0021 }
0022
0023 err = test_enable_stats__attach(skel);
0024 if (CHECK(err, "attach_raw_tp", "err %d\n", err))
0025 goto cleanup;
0026
0027 test_enable_stats__detach(skel);
0028
0029 prog_fd = bpf_program__fd(skel->progs.test_enable_stats);
0030 memset(&info, 0, info_len);
0031 err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len);
0032 if (CHECK(err, "get_prog_info",
0033 "failed to get bpf_prog_info for fd %d\n", prog_fd))
0034 goto cleanup;
0035 if (CHECK(info.run_time_ns == 0, "check_stats_enabled",
0036 "failed to enable run_time_ns stats\n"))
0037 goto cleanup;
0038
0039 CHECK(info.run_cnt != skel->bss->count, "check_run_cnt_valid",
0040 "invalid run_cnt stats\n");
0041
0042 cleanup:
0043 test_enable_stats__destroy(skel);
0044 close(stats_fd);
0045 }