0001
0002
0003 #include <test_progs.h>
0004 #include "progs/profiler.h"
0005 #include "profiler1.skel.h"
0006 #include "profiler2.skel.h"
0007 #include "profiler3.skel.h"
0008
0009 static int sanity_run(struct bpf_program *prog)
0010 {
0011 LIBBPF_OPTS(bpf_test_run_opts, test_attr);
0012 __u64 args[] = {1, 2, 3};
0013 int err, prog_fd;
0014
0015 prog_fd = bpf_program__fd(prog);
0016 test_attr.ctx_in = args;
0017 test_attr.ctx_size_in = sizeof(args);
0018 err = bpf_prog_test_run_opts(prog_fd, &test_attr);
0019 if (!ASSERT_OK(err, "test_run"))
0020 return -1;
0021
0022 if (!ASSERT_OK(test_attr.retval, "test_run retval"))
0023 return -1;
0024
0025 return 0;
0026 }
0027
0028 void test_test_profiler(void)
0029 {
0030 struct profiler1 *profiler1_skel = NULL;
0031 struct profiler2 *profiler2_skel = NULL;
0032 struct profiler3 *profiler3_skel = NULL;
0033 __u32 duration = 0;
0034 int err;
0035
0036 profiler1_skel = profiler1__open_and_load();
0037 if (CHECK(!profiler1_skel, "profiler1_skel_load", "profiler1 skeleton failed\n"))
0038 goto cleanup;
0039
0040 err = profiler1__attach(profiler1_skel);
0041 if (CHECK(err, "profiler1_attach", "profiler1 attach failed: %d\n", err))
0042 goto cleanup;
0043
0044 if (sanity_run(profiler1_skel->progs.raw_tracepoint__sched_process_exec))
0045 goto cleanup;
0046
0047 profiler2_skel = profiler2__open_and_load();
0048 if (CHECK(!profiler2_skel, "profiler2_skel_load", "profiler2 skeleton failed\n"))
0049 goto cleanup;
0050
0051 err = profiler2__attach(profiler2_skel);
0052 if (CHECK(err, "profiler2_attach", "profiler2 attach failed: %d\n", err))
0053 goto cleanup;
0054
0055 if (sanity_run(profiler2_skel->progs.raw_tracepoint__sched_process_exec))
0056 goto cleanup;
0057
0058 profiler3_skel = profiler3__open_and_load();
0059 if (CHECK(!profiler3_skel, "profiler3_skel_load", "profiler3 skeleton failed\n"))
0060 goto cleanup;
0061
0062 err = profiler3__attach(profiler3_skel);
0063 if (CHECK(err, "profiler3_attach", "profiler3 attach failed: %d\n", err))
0064 goto cleanup;
0065
0066 if (sanity_run(profiler3_skel->progs.raw_tracepoint__sched_process_exec))
0067 goto cleanup;
0068 cleanup:
0069 profiler1__destroy(profiler1_skel);
0070 profiler2__destroy(profiler2_skel);
0071 profiler3__destroy(profiler3_skel);
0072 }