1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <test_progs.h>
4 #include "progs/profiler.h"
5 #include "profiler1.skel.h"
6 #include "profiler2.skel.h"
7 #include "profiler3.skel.h"
8 
9 static int sanity_run(struct bpf_program *prog)
10 {
11 	struct bpf_prog_test_run_attr test_attr = {};
12 	__u64 args[] = {1, 2, 3};
13 	__u32 duration = 0;
14 	int err, prog_fd;
15 
16 	prog_fd = bpf_program__fd(prog);
17 	test_attr.prog_fd = prog_fd;
18 	test_attr.ctx_in = args;
19 	test_attr.ctx_size_in = sizeof(args);
20 	err = bpf_prog_test_run_xattr(&test_attr);
21 	if (CHECK(err || test_attr.retval, "test_run",
22 		  "err %d errno %d retval %d duration %d\n",
23 		  err, errno, test_attr.retval, duration))
24 		return -1;
25 	return 0;
26 }
27 
28 void test_test_profiler(void)
29 {
30 	struct profiler1 *profiler1_skel = NULL;
31 	struct profiler2 *profiler2_skel = NULL;
32 	struct profiler3 *profiler3_skel = NULL;
33 	__u32 duration = 0;
34 	int err;
35 
36 	profiler1_skel = profiler1__open_and_load();
37 	if (CHECK(!profiler1_skel, "profiler1_skel_load", "profiler1 skeleton failed\n"))
38 		goto cleanup;
39 
40 	err = profiler1__attach(profiler1_skel);
41 	if (CHECK(err, "profiler1_attach", "profiler1 attach failed: %d\n", err))
42 		goto cleanup;
43 
44 	if (sanity_run(profiler1_skel->progs.raw_tracepoint__sched_process_exec))
45 		goto cleanup;
46 
47 	profiler2_skel = profiler2__open_and_load();
48 	if (CHECK(!profiler2_skel, "profiler2_skel_load", "profiler2 skeleton failed\n"))
49 		goto cleanup;
50 
51 	err = profiler2__attach(profiler2_skel);
52 	if (CHECK(err, "profiler2_attach", "profiler2 attach failed: %d\n", err))
53 		goto cleanup;
54 
55 	if (sanity_run(profiler2_skel->progs.raw_tracepoint__sched_process_exec))
56 		goto cleanup;
57 
58 	profiler3_skel = profiler3__open_and_load();
59 	if (CHECK(!profiler3_skel, "profiler3_skel_load", "profiler3 skeleton failed\n"))
60 		goto cleanup;
61 
62 	err = profiler3__attach(profiler3_skel);
63 	if (CHECK(err, "profiler3_attach", "profiler3 attach failed: %d\n", err))
64 		goto cleanup;
65 
66 	if (sanity_run(profiler3_skel->progs.raw_tracepoint__sched_process_exec))
67 		goto cleanup;
68 cleanup:
69 	profiler1__destroy(profiler1_skel);
70 	profiler2__destroy(profiler2_skel);
71 	profiler3__destroy(profiler3_skel);
72 }
73