1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2022, Oracle and/or its affiliates. */ 3 4 #include <test_progs.h> 5 #include "test_uprobe_autoattach.skel.h" 6 #include "progs/bpf_misc.h" 7 8 /* uprobe attach point */ 9 static noinline int autoattach_trigger_func(int arg1, int arg2, int arg3, 10 int arg4, int arg5, int arg6, 11 int arg7, int arg8) 12 { 13 asm volatile (""); 14 return arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + 1; 15 } 16 17 void test_uprobe_autoattach(void) 18 { 19 const char *devnull_str = "/dev/null"; 20 struct test_uprobe_autoattach *skel; 21 int trigger_ret; 22 FILE *devnull; 23 24 skel = test_uprobe_autoattach__open_and_load(); 25 if (!ASSERT_OK_PTR(skel, "skel_open")) 26 return; 27 28 if (!ASSERT_OK(test_uprobe_autoattach__attach(skel), "skel_attach")) 29 goto cleanup; 30 31 skel->bss->test_pid = getpid(); 32 33 /* trigger & validate uprobe & uretprobe */ 34 trigger_ret = autoattach_trigger_func(1, 2, 3, 4, 5, 6, 7, 8); 35 36 skel->bss->test_pid = getpid(); 37 38 /* trigger & validate shared library u[ret]probes attached by name */ 39 devnull = fopen(devnull_str, "r"); 40 41 ASSERT_EQ(skel->bss->uprobe_byname_parm1, 1, "check_uprobe_byname_parm1"); 42 ASSERT_EQ(skel->bss->uprobe_byname_ran, 1, "check_uprobe_byname_ran"); 43 ASSERT_EQ(skel->bss->uretprobe_byname_rc, trigger_ret, "check_uretprobe_byname_rc"); 44 ASSERT_EQ(skel->bss->uretprobe_byname_ret, trigger_ret, "check_uretprobe_byname_ret"); 45 ASSERT_EQ(skel->bss->uretprobe_byname_ran, 2, "check_uretprobe_byname_ran"); 46 ASSERT_EQ(skel->bss->uprobe_byname2_parm1, (__u64)(long)devnull_str, 47 "check_uprobe_byname2_parm1"); 48 ASSERT_EQ(skel->bss->uprobe_byname2_ran, 3, "check_uprobe_byname2_ran"); 49 ASSERT_EQ(skel->bss->uretprobe_byname2_rc, (__u64)(long)devnull, 50 "check_uretprobe_byname2_rc"); 51 ASSERT_EQ(skel->bss->uretprobe_byname2_ran, 4, "check_uretprobe_byname2_ran"); 52 53 ASSERT_EQ(skel->bss->a[0], 1, "arg1"); 54 ASSERT_EQ(skel->bss->a[1], 2, "arg2"); 55 ASSERT_EQ(skel->bss->a[2], 3, "arg3"); 56 #if FUNC_REG_ARG_CNT > 3 57 ASSERT_EQ(skel->bss->a[3], 4, "arg4"); 58 #endif 59 #if FUNC_REG_ARG_CNT > 4 60 ASSERT_EQ(skel->bss->a[4], 5, "arg5"); 61 #endif 62 #if FUNC_REG_ARG_CNT > 5 63 ASSERT_EQ(skel->bss->a[5], 6, "arg6"); 64 #endif 65 #if FUNC_REG_ARG_CNT > 6 66 ASSERT_EQ(skel->bss->a[6], 7, "arg7"); 67 #endif 68 #if FUNC_REG_ARG_CNT > 7 69 ASSERT_EQ(skel->bss->a[7], 8, "arg8"); 70 #endif 71 72 fclose(devnull); 73 cleanup: 74 test_uprobe_autoattach__destroy(skel); 75 } 76