7
7
#include "find_vma_fail1.skel.h"
8
8
#include "find_vma_fail2.skel.h"
9
9
10
- static void test_and_reset_skel (struct find_vma * skel , int expected_find_zero_ret )
10
+ static void test_and_reset_skel (struct find_vma * skel , int expected_find_zero_ret , bool need_test )
11
11
{
12
- ASSERT_EQ (skel -> bss -> found_vm_exec , 1 , "found_vm_exec" );
13
- ASSERT_EQ (skel -> data -> find_addr_ret , 0 , "find_addr_ret" );
14
- ASSERT_EQ (skel -> data -> find_zero_ret , expected_find_zero_ret , "find_zero_ret" );
15
- ASSERT_OK_PTR (strstr (skel -> bss -> d_iname , "test_progs" ), "find_test_progs" );
12
+ if (need_test ) {
13
+ ASSERT_EQ (skel -> bss -> found_vm_exec , 1 , "found_vm_exec" );
14
+ ASSERT_EQ (skel -> data -> find_addr_ret , 0 , "find_addr_ret" );
15
+ ASSERT_EQ (skel -> data -> find_zero_ret , expected_find_zero_ret , "find_zero_ret" );
16
+ ASSERT_OK_PTR (strstr (skel -> bss -> d_iname , "test_progs" ), "find_test_progs" );
17
+ }
16
18
17
19
skel -> bss -> found_vm_exec = 0 ;
18
20
skel -> data -> find_addr_ret = -1 ;
@@ -30,17 +32,26 @@ static int open_pe(void)
30
32
attr .type = PERF_TYPE_HARDWARE ;
31
33
attr .config = PERF_COUNT_HW_CPU_CYCLES ;
32
34
attr .freq = 1 ;
33
- attr .sample_freq = 4000 ;
35
+ attr .sample_freq = 1000 ;
34
36
pfd = syscall (__NR_perf_event_open , & attr , 0 , -1 , -1 , PERF_FLAG_FD_CLOEXEC );
35
37
36
38
return pfd >= 0 ? pfd : - errno ;
37
39
}
38
40
41
+ static bool find_vma_pe_condition (struct find_vma * skel )
42
+ {
43
+ return skel -> bss -> found_vm_exec == 0 ||
44
+ skel -> data -> find_addr_ret != 0 ||
45
+ skel -> data -> find_zero_ret == -1 ||
46
+ strcmp (skel -> bss -> d_iname , "test_progs" ) != 0 ;
47
+ }
48
+
39
49
static void test_find_vma_pe (struct find_vma * skel )
40
50
{
41
51
struct bpf_link * link = NULL ;
42
52
volatile int j = 0 ;
43
53
int pfd , i ;
54
+ const int one_bn = 1000000000 ;
44
55
45
56
pfd = open_pe ();
46
57
if (pfd < 0 ) {
@@ -57,10 +68,10 @@ static void test_find_vma_pe(struct find_vma *skel)
57
68
if (!ASSERT_OK_PTR (link , "attach_perf_event" ))
58
69
goto cleanup ;
59
70
60
- for (i = 0 ; i < 1000000 ; ++ i )
71
+ for (i = 0 ; i < one_bn && find_vma_pe_condition ( skel ) ; ++ i )
61
72
++ j ;
62
73
63
- test_and_reset_skel (skel , - EBUSY /* in nmi, irq_work is busy */ );
74
+ test_and_reset_skel (skel , - EBUSY /* in nmi, irq_work is busy */ , i == one_bn );
64
75
cleanup :
65
76
bpf_link__destroy (link );
66
77
close (pfd );
@@ -75,7 +86,7 @@ static void test_find_vma_kprobe(struct find_vma *skel)
75
86
return ;
76
87
77
88
getpgid (skel -> bss -> target_pid );
78
- test_and_reset_skel (skel , - ENOENT /* could not find vma for ptr 0 */ );
89
+ test_and_reset_skel (skel , - ENOENT /* could not find vma for ptr 0 */ , true );
79
90
}
80
91
81
92
static void test_illegal_write_vma (void )
@@ -108,7 +119,6 @@ void serial_test_find_vma(void)
108
119
skel -> bss -> addr = (__u64 )(uintptr_t )test_find_vma_pe ;
109
120
110
121
test_find_vma_pe (skel );
111
- usleep (100000 ); /* allow the irq_work to finish */
112
122
test_find_vma_kprobe (skel );
113
123
114
124
find_vma__destroy (skel );
0 commit comments