@@ -28,37 +28,54 @@ static void test_bpf_spin_lock(bool is_spin_lock)
28
28
tracing_failure__destroy (skel );
29
29
}
30
30
31
- static void test_tracing_deny ( void )
31
+ static void test_tracing_fail_prog ( const char * prog_name , const char * exp_msg )
32
32
{
33
33
struct tracing_failure * skel ;
34
+ struct bpf_program * prog ;
34
35
char log_buf [256 ];
35
- int btf_id , err ;
36
-
37
- /* __rcu_read_lock depends on CONFIG_PREEMPT_RCU */
38
- btf_id = libbpf_find_vmlinux_btf_id ("__rcu_read_lock" , BPF_TRACE_FENTRY );
39
- if (btf_id <= 0 ) {
40
- test__skip ();
41
- return ;
42
- }
36
+ int err ;
43
37
44
38
skel = tracing_failure__open ();
45
39
if (!ASSERT_OK_PTR (skel , "tracing_failure__open" ))
46
40
return ;
47
41
48
- bpf_program__set_autoload (skel -> progs .tracing_deny , true);
49
- bpf_program__set_log_buf (skel -> progs .tracing_deny , log_buf , sizeof (log_buf ));
42
+ prog = bpf_object__find_program_by_name (skel -> obj , prog_name );
43
+ if (!ASSERT_OK_PTR (prog , "bpf_object__find_program_by_name" ))
44
+ goto out ;
45
+
46
+ bpf_program__set_autoload (prog , true);
47
+ bpf_program__set_log_buf (prog , log_buf , sizeof (log_buf ));
50
48
51
49
err = tracing_failure__load (skel );
52
50
if (!ASSERT_ERR (err , "tracing_failure__load" ))
53
51
goto out ;
54
52
55
- ASSERT_HAS_SUBSTR (log_buf ,
56
- "Attaching tracing programs to function '__rcu_read_lock' is rejected." ,
57
- "log_buf" );
53
+ ASSERT_HAS_SUBSTR (log_buf , exp_msg , "log_buf" );
58
54
out :
59
55
tracing_failure__destroy (skel );
60
56
}
61
57
58
+ static void test_tracing_deny (void )
59
+ {
60
+ int btf_id ;
61
+
62
+ /* __rcu_read_lock depends on CONFIG_PREEMPT_RCU */
63
+ btf_id = libbpf_find_vmlinux_btf_id ("__rcu_read_lock" , BPF_TRACE_FENTRY );
64
+ if (btf_id <= 0 ) {
65
+ test__skip ();
66
+ return ;
67
+ }
68
+
69
+ test_tracing_fail_prog ("tracing_deny" ,
70
+ "Attaching tracing programs to function '__rcu_read_lock' is rejected." );
71
+ }
72
+
73
+ static void test_fexit_noreturns (void )
74
+ {
75
+ test_tracing_fail_prog ("fexit_noreturns" ,
76
+ "Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected." );
77
+ }
78
+
62
79
void test_tracing_failure (void )
63
80
{
64
81
if (test__start_subtest ("bpf_spin_lock" ))
@@ -67,4 +84,6 @@ void test_tracing_failure(void)
67
84
test_bpf_spin_lock (false);
68
85
if (test__start_subtest ("tracing_deny" ))
69
86
test_tracing_deny ();
87
+ if (test__start_subtest ("fexit_noreturns" ))
88
+ test_fexit_noreturns ();
70
89
}
0 commit comments