]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: add tests for the "module: Function" syntax
authorViktor Malik <vmalik@redhat.com>
Tue, 30 Apr 2024 09:38:07 +0000 (11:38 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 1 May 2024 16:53:48 +0000 (09:53 -0700)
The previous patch added support for the "module:function" syntax for
tracing programs. This adds tests for explicitly specifying the module
name via the SEC macro and via the bpf_program__set_attach_target call.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/8a076168ed847f7c8a6c25715737b1fea84e38be.1714469650.git.vmalik@redhat.com
tools/testing/selftests/bpf/prog_tests/module_attach.c
tools/testing/selftests/bpf/progs/test_module_attach.c

index f53d658ed080b70273811f033adb205d3cd8161a..6d391d95f96e0041088f62a53ba90a618ce21230 100644 (file)
@@ -51,6 +51,10 @@ void test_module_attach(void)
                                             0, "bpf_testmod_test_read");
        ASSERT_OK(err, "set_attach_target");
 
+       err = bpf_program__set_attach_target(skel->progs.handle_fentry_explicit_manual,
+                                            0, "bpf_testmod:bpf_testmod_test_read");
+       ASSERT_OK(err, "set_attach_target_explicit");
+
        err = test_module_attach__load(skel);
        if (CHECK(err, "skel_load", "failed to load skeleton\n"))
                return;
@@ -70,6 +74,8 @@ void test_module_attach(void)
        ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
        ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
        ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
+       ASSERT_EQ(bss->fentry_explicit_read_sz, READ_SZ, "fentry_explicit");
+       ASSERT_EQ(bss->fentry_explicit_manual_read_sz, READ_SZ, "fentry_explicit_manual");
        ASSERT_EQ(bss->fexit_read_sz, READ_SZ, "fexit");
        ASSERT_EQ(bss->fexit_ret, -EIO, "fexit_tet");
        ASSERT_EQ(bss->fmod_ret_read_sz, READ_SZ, "fmod_ret");
index 8a1b50f3a002de48b7a44f478427dd28b53445ff..cc1a012d038f1ddca8c982a88b9ef15802f39610 100644 (file)
@@ -73,6 +73,29 @@ int BPF_PROG(handle_fentry_manual,
        return 0;
 }
 
+__u32 fentry_explicit_read_sz = 0;
+
+SEC("fentry/bpf_testmod:bpf_testmod_test_read")
+int BPF_PROG(handle_fentry_explicit,
+            struct file *file, struct kobject *kobj,
+            struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
+{
+       fentry_explicit_read_sz = len;
+       return 0;
+}
+
+
+__u32 fentry_explicit_manual_read_sz = 0;
+
+SEC("fentry")
+int BPF_PROG(handle_fentry_explicit_manual,
+            struct file *file, struct kobject *kobj,
+            struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
+{
+       fentry_explicit_manual_read_sz = len;
+       return 0;
+}
+
 __u32 fexit_read_sz = 0;
 int fexit_ret = 0;