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