1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
4 #include <test_progs.h>
5 #include "test_module_attach.skel.h"
9 static int trigger_module_test_read(int read_sz
)
13 fd
= open("/sys/kernel/bpf_testmod", O_RDONLY
);
15 if (CHECK(fd
< 0, "testmod_file_open", "failed: %d\n", err
))
18 read(fd
, NULL
, read_sz
);
24 void test_module_attach(void)
26 const int READ_SZ
= 456;
27 struct test_module_attach
* skel
;
28 struct test_module_attach__bss
*bss
;
31 skel
= test_module_attach__open();
32 if (CHECK(!skel
, "skel_open", "failed to open skeleton\n"))
35 err
= bpf_program__set_attach_target(skel
->progs
.handle_fentry_manual
,
36 0, "bpf_testmod_test_read");
37 ASSERT_OK(err
, "set_attach_target");
39 err
= test_module_attach__load(skel
);
40 if (CHECK(err
, "skel_load", "failed to load skeleton\n"))
45 err
= test_module_attach__attach(skel
);
46 if (CHECK(err
, "skel_attach", "skeleton attach failed: %d\n", err
))
49 /* trigger tracepoint */
50 ASSERT_OK(trigger_module_test_read(READ_SZ
), "trigger_read");
52 ASSERT_EQ(bss
->raw_tp_read_sz
, READ_SZ
, "raw_tp");
53 ASSERT_EQ(bss
->tp_btf_read_sz
, READ_SZ
, "tp_btf");
54 ASSERT_EQ(bss
->fentry_read_sz
, READ_SZ
, "fentry");
55 ASSERT_EQ(bss
->fentry_manual_read_sz
, READ_SZ
, "fentry_manual");
56 ASSERT_EQ(bss
->fexit_read_sz
, READ_SZ
, "fexit");
57 ASSERT_EQ(bss
->fexit_ret
, -EIO
, "fexit_tet");
58 ASSERT_EQ(bss
->fmod_ret_read_sz
, READ_SZ
, "fmod_ret");
61 test_module_attach__destroy(skel
);