Loading...
Note: File does not exist in v3.5.6.
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright 2022 Sony Group Corporation */
3#include <sys/prctl.h>
4#include <test_progs.h>
5#include "bpf_syscall_macro.skel.h"
6
7void test_bpf_syscall_macro(void)
8{
9 struct bpf_syscall_macro *skel = NULL;
10 int err;
11 int exp_arg1 = 1001;
12 unsigned long exp_arg2 = 12;
13 unsigned long exp_arg3 = 13;
14 unsigned long exp_arg4 = 14;
15 unsigned long exp_arg5 = 15;
16
17 /* check whether it can open program */
18 skel = bpf_syscall_macro__open();
19 if (!ASSERT_OK_PTR(skel, "bpf_syscall_macro__open"))
20 return;
21
22 skel->rodata->filter_pid = getpid();
23
24 /* check whether it can load program */
25 err = bpf_syscall_macro__load(skel);
26 if (!ASSERT_OK(err, "bpf_syscall_macro__load"))
27 goto cleanup;
28
29 /* check whether it can attach kprobe */
30 err = bpf_syscall_macro__attach(skel);
31 if (!ASSERT_OK(err, "bpf_syscall_macro__attach"))
32 goto cleanup;
33
34 /* check whether args of syscall are copied correctly */
35 prctl(exp_arg1, exp_arg2, exp_arg3, exp_arg4, exp_arg5);
36#if defined(__aarch64__) || defined(__s390__)
37 ASSERT_NEQ(skel->bss->arg1, exp_arg1, "syscall_arg1");
38#else
39 ASSERT_EQ(skel->bss->arg1, exp_arg1, "syscall_arg1");
40#endif
41 ASSERT_EQ(skel->bss->arg2, exp_arg2, "syscall_arg2");
42 ASSERT_EQ(skel->bss->arg3, exp_arg3, "syscall_arg3");
43 /* it cannot copy arg4 when uses PT_REGS_PARM4 on x86_64 */
44#ifdef __x86_64__
45 ASSERT_NEQ(skel->bss->arg4_cx, exp_arg4, "syscall_arg4_from_cx");
46#else
47 ASSERT_EQ(skel->bss->arg4_cx, exp_arg4, "syscall_arg4_from_cx");
48#endif
49 ASSERT_EQ(skel->bss->arg4, exp_arg4, "syscall_arg4");
50 ASSERT_EQ(skel->bss->arg5, exp_arg5, "syscall_arg5");
51
52 /* check whether args of syscall are copied correctly for CORE variants */
53 ASSERT_EQ(skel->bss->arg1_core, exp_arg1, "syscall_arg1_core_variant");
54 ASSERT_EQ(skel->bss->arg2_core, exp_arg2, "syscall_arg2_core_variant");
55 ASSERT_EQ(skel->bss->arg3_core, exp_arg3, "syscall_arg3_core_variant");
56 /* it cannot copy arg4 when uses PT_REGS_PARM4_CORE on x86_64 */
57#ifdef __x86_64__
58 ASSERT_NEQ(skel->bss->arg4_core_cx, exp_arg4, "syscall_arg4_from_cx_core_variant");
59#else
60 ASSERT_EQ(skel->bss->arg4_core_cx, exp_arg4, "syscall_arg4_from_cx_core_variant");
61#endif
62 ASSERT_EQ(skel->bss->arg4_core, exp_arg4, "syscall_arg4_core_variant");
63 ASSERT_EQ(skel->bss->arg5_core, exp_arg5, "syscall_arg5_core_variant");
64
65 ASSERT_EQ(skel->bss->option_syscall, exp_arg1, "BPF_KPROBE_SYSCALL_option");
66 ASSERT_EQ(skel->bss->arg2_syscall, exp_arg2, "BPF_KPROBE_SYSCALL_arg2");
67 ASSERT_EQ(skel->bss->arg3_syscall, exp_arg3, "BPF_KPROBE_SYSCALL_arg3");
68 ASSERT_EQ(skel->bss->arg4_syscall, exp_arg4, "BPF_KPROBE_SYSCALL_arg4");
69 ASSERT_EQ(skel->bss->arg5_syscall, exp_arg5, "BPF_KPROBE_SYSCALL_arg5");
70
71cleanup:
72 bpf_syscall_macro__destroy(skel);
73}