1*3cccbaa0SDelyan Kratunov // SPDX-License-Identifier: GPL-2.0
2*3cccbaa0SDelyan Kratunov /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3*3cccbaa0SDelyan Kratunov
4*3cccbaa0SDelyan Kratunov #include <test_progs.h>
5*3cccbaa0SDelyan Kratunov #include "test_subskeleton.skel.h"
6*3cccbaa0SDelyan Kratunov #include "test_subskeleton_lib.subskel.h"
7*3cccbaa0SDelyan Kratunov
subskeleton_lib_setup(struct bpf_object * obj)8*3cccbaa0SDelyan Kratunov static void subskeleton_lib_setup(struct bpf_object *obj)
9*3cccbaa0SDelyan Kratunov {
10*3cccbaa0SDelyan Kratunov struct test_subskeleton_lib *lib = test_subskeleton_lib__open(obj);
11*3cccbaa0SDelyan Kratunov
12*3cccbaa0SDelyan Kratunov if (!ASSERT_OK_PTR(lib, "open subskeleton"))
13*3cccbaa0SDelyan Kratunov return;
14*3cccbaa0SDelyan Kratunov
15*3cccbaa0SDelyan Kratunov *lib->rodata.var1 = 1;
16*3cccbaa0SDelyan Kratunov *lib->data.var2 = 2;
17*3cccbaa0SDelyan Kratunov lib->bss.var3->var3_1 = 3;
18*3cccbaa0SDelyan Kratunov lib->bss.var3->var3_2 = 4;
19*3cccbaa0SDelyan Kratunov
20*3cccbaa0SDelyan Kratunov test_subskeleton_lib__destroy(lib);
21*3cccbaa0SDelyan Kratunov }
22*3cccbaa0SDelyan Kratunov
subskeleton_lib_subresult(struct bpf_object * obj)23*3cccbaa0SDelyan Kratunov static int subskeleton_lib_subresult(struct bpf_object *obj)
24*3cccbaa0SDelyan Kratunov {
25*3cccbaa0SDelyan Kratunov struct test_subskeleton_lib *lib = test_subskeleton_lib__open(obj);
26*3cccbaa0SDelyan Kratunov int result;
27*3cccbaa0SDelyan Kratunov
28*3cccbaa0SDelyan Kratunov if (!ASSERT_OK_PTR(lib, "open subskeleton"))
29*3cccbaa0SDelyan Kratunov return -EINVAL;
30*3cccbaa0SDelyan Kratunov
31*3cccbaa0SDelyan Kratunov result = *lib->bss.libout1;
32*3cccbaa0SDelyan Kratunov ASSERT_EQ(result, 1 + 2 + 3 + 4 + 5 + 6, "lib subresult");
33*3cccbaa0SDelyan Kratunov
34*3cccbaa0SDelyan Kratunov ASSERT_OK_PTR(lib->progs.lib_perf_handler, "lib_perf_handler");
35*3cccbaa0SDelyan Kratunov ASSERT_STREQ(bpf_program__name(lib->progs.lib_perf_handler),
36*3cccbaa0SDelyan Kratunov "lib_perf_handler", "program name");
37*3cccbaa0SDelyan Kratunov
38*3cccbaa0SDelyan Kratunov ASSERT_OK_PTR(lib->maps.map1, "map1");
39*3cccbaa0SDelyan Kratunov ASSERT_STREQ(bpf_map__name(lib->maps.map1), "map1", "map name");
40*3cccbaa0SDelyan Kratunov
41*3cccbaa0SDelyan Kratunov ASSERT_EQ(*lib->data.var5, 5, "__weak var5");
42*3cccbaa0SDelyan Kratunov ASSERT_EQ(*lib->data.var6, 6, "extern var6");
43*3cccbaa0SDelyan Kratunov ASSERT_TRUE(*lib->kconfig.CONFIG_BPF_SYSCALL, "CONFIG_BPF_SYSCALL");
44*3cccbaa0SDelyan Kratunov
45*3cccbaa0SDelyan Kratunov test_subskeleton_lib__destroy(lib);
46*3cccbaa0SDelyan Kratunov return result;
47*3cccbaa0SDelyan Kratunov }
48*3cccbaa0SDelyan Kratunov
test_subskeleton(void)49*3cccbaa0SDelyan Kratunov void test_subskeleton(void)
50*3cccbaa0SDelyan Kratunov {
51*3cccbaa0SDelyan Kratunov int err, result;
52*3cccbaa0SDelyan Kratunov struct test_subskeleton *skel;
53*3cccbaa0SDelyan Kratunov
54*3cccbaa0SDelyan Kratunov skel = test_subskeleton__open();
55*3cccbaa0SDelyan Kratunov if (!ASSERT_OK_PTR(skel, "skel_open"))
56*3cccbaa0SDelyan Kratunov return;
57*3cccbaa0SDelyan Kratunov
58*3cccbaa0SDelyan Kratunov skel->rodata->rovar1 = 10;
59*3cccbaa0SDelyan Kratunov skel->rodata->var1 = 1;
60*3cccbaa0SDelyan Kratunov subskeleton_lib_setup(skel->obj);
61*3cccbaa0SDelyan Kratunov
62*3cccbaa0SDelyan Kratunov err = test_subskeleton__load(skel);
63*3cccbaa0SDelyan Kratunov if (!ASSERT_OK(err, "skel_load"))
64*3cccbaa0SDelyan Kratunov goto cleanup;
65*3cccbaa0SDelyan Kratunov
66*3cccbaa0SDelyan Kratunov err = test_subskeleton__attach(skel);
67*3cccbaa0SDelyan Kratunov if (!ASSERT_OK(err, "skel_attach"))
68*3cccbaa0SDelyan Kratunov goto cleanup;
69*3cccbaa0SDelyan Kratunov
70*3cccbaa0SDelyan Kratunov /* trigger tracepoint */
71*3cccbaa0SDelyan Kratunov usleep(1);
72*3cccbaa0SDelyan Kratunov
73*3cccbaa0SDelyan Kratunov result = subskeleton_lib_subresult(skel->obj) * 10;
74*3cccbaa0SDelyan Kratunov ASSERT_EQ(skel->bss->out1, result, "unexpected calculation");
75*3cccbaa0SDelyan Kratunov
76*3cccbaa0SDelyan Kratunov cleanup:
77*3cccbaa0SDelyan Kratunov test_subskeleton__destroy(skel);
78*3cccbaa0SDelyan Kratunov }
79