Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 100 lines 2.5 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2 3#include <test_progs.h> 4#include "struct_ops_private_stack.skel.h" 5#include "struct_ops_private_stack_fail.skel.h" 6#include "struct_ops_private_stack_recur.skel.h" 7 8#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) 9static void test_private_stack(void) 10{ 11 struct struct_ops_private_stack *skel; 12 struct bpf_link *link; 13 int err; 14 15 skel = struct_ops_private_stack__open(); 16 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack__open")) 17 return; 18 19 err = struct_ops_private_stack__load(skel); 20 if (!ASSERT_OK(err, "struct_ops_private_stack__load")) 21 goto cleanup; 22 23 link = bpf_map__attach_struct_ops(skel->maps.testmod_1); 24 if (!ASSERT_OK_PTR(link, "attach_struct_ops")) 25 goto cleanup; 26 27 ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 28 29 ASSERT_EQ(skel->bss->val_i, 3, "val_i"); 30 ASSERT_EQ(skel->bss->val_j, 8, "val_j"); 31 32 bpf_link__destroy(link); 33 34cleanup: 35 struct_ops_private_stack__destroy(skel); 36} 37 38static void test_private_stack_fail(void) 39{ 40 struct struct_ops_private_stack_fail *skel; 41 int err; 42 43 skel = struct_ops_private_stack_fail__open(); 44 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_fail__open")) 45 return; 46 47 err = struct_ops_private_stack_fail__load(skel); 48 ASSERT_ERR(err, "struct_ops_private_stack_fail__load"); 49 50 struct_ops_private_stack_fail__destroy(skel); 51} 52 53static void test_private_stack_recur(void) 54{ 55 struct struct_ops_private_stack_recur *skel; 56 struct bpf_link *link; 57 int err; 58 59 skel = struct_ops_private_stack_recur__open(); 60 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_recur__open")) 61 return; 62 63 err = struct_ops_private_stack_recur__load(skel); 64 if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load")) 65 goto cleanup; 66 67 link = bpf_map__attach_struct_ops(skel->maps.testmod_1); 68 if (!ASSERT_OK_PTR(link, "attach_struct_ops")) 69 goto cleanup; 70 71 ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 72 73 ASSERT_EQ(skel->bss->val_j, 3, "val_j"); 74 75 bpf_link__destroy(link); 76 77cleanup: 78 struct_ops_private_stack_recur__destroy(skel); 79} 80 81static void __test_struct_ops_private_stack(void) 82{ 83 if (test__start_subtest("private_stack")) 84 test_private_stack(); 85 if (test__start_subtest("private_stack_fail")) 86 test_private_stack_fail(); 87 if (test__start_subtest("private_stack_recur")) 88 test_private_stack_recur(); 89} 90#else 91static void __test_struct_ops_private_stack(void) 92{ 93 test__skip(); 94} 95#endif 96 97void test_struct_ops_private_stack(void) 98{ 99 __test_struct_ops_private_stack(); 100}