WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / module_attach.c
blob50796b651f72652a77f306d6b23cc97f8a2b91e4
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
4 #include <test_progs.h>
5 #include "test_module_attach.skel.h"
7 static int duration;
9 static int trigger_module_test_read(int read_sz)
11 int fd, err;
13 fd = open("/sys/kernel/bpf_testmod", O_RDONLY);
14 err = -errno;
15 if (CHECK(fd < 0, "testmod_file_open", "failed: %d\n", err))
16 return err;
18 read(fd, NULL, read_sz);
19 close(fd);
21 return 0;
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;
29 int err;
31 skel = test_module_attach__open();
32 if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
33 return;
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"))
41 return;
43 bss = skel->bss;
45 err = test_module_attach__attach(skel);
46 if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
47 goto cleanup;
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");
60 cleanup:
61 test_module_attach__destroy(skel);