File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,12 +76,18 @@ src/timerlat.skel.h: src/timerlat.bpf.o
7676
7777example/timerlat_bpf_action.o : example/timerlat_bpf_action.c
7878 $(QUIET_CLANG )$(CLANG ) -g -O2 -target bpf -c $(filter % .c,$^ ) -o $@
79+
80+ tests/bpf/bpf_action_map.o : tests/bpf/bpf_action_map.c
81+ $(QUIET_CLANG )$(CLANG ) -g -O2 -target bpf -c $(filter % .c,$^ ) -o $@
7982else
8083src/timerlat.skel.h :
8184 $(Q ) echo ' /* BPF skeleton is disabled */' > src/timerlat.skel.h
8285
8386example/timerlat_bpf_action.o : example/timerlat_bpf_action.c
8487 $(Q ) echo " BPF skeleton support is disabled, skipping example/timerlat_bpf_action.o"
88+
89+ tests/bpf/bpf_action_map.o : tests/bpf/bpf_action_map.c
90+ $(Q ) echo " BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"
8591endif
8692
8793$(RTLA ) : $(RTLA_IN )
@@ -103,7 +109,7 @@ clean: doc_clean fixdep-clean
103109 $(Q ) rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
104110 $(Q ) rm -rf feature
105111 $(Q ) rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
106- check : $(RTLA )
107- RTLA=$(RTLA ) prove -o -f tests/
112+ check : $(RTLA ) tests/bpf/bpf_action_map.o
113+ RTLA=$(RTLA ) BPFTOOL= $( SYSTEM_BPFTOOL ) prove -o -f tests/
108114examples : example/timerlat_bpf_action.o
109115.PHONY : FORCE clean check
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+ #include <linux/bpf.h>
3+ #include <bpf/bpf_tracing.h>
4+
5+ char LICENSE [] SEC ("license" ) = "GPL" ;
6+
7+ struct {
8+ __uint (type , BPF_MAP_TYPE_ARRAY );
9+ __uint (max_entries , 1 );
10+ __type (key , unsigned int );
11+ __type (value , unsigned long long );
12+ } rtla_test_map SEC (".maps" );
13+
14+ struct trace_event_raw_timerlat_sample ;
15+
16+ SEC ("tp/timerlat_action" )
17+ int action_handler (struct trace_event_raw_timerlat_sample * tp_args )
18+ {
19+ unsigned int key = 0 ;
20+ unsigned long long value = 42 ;
21+
22+ bpf_map_update_elem (& rtla_test_map , & key , & value , BPF_ANY );
23+
24+ return 0 ;
25+ }
Original file line number Diff line number Diff line change @@ -67,6 +67,21 @@ check "hist with trace output at end" \
6767 " timerlat hist -d 1s --on-end trace" 0 " ^ Saving trace to timerlat_trace.txt$"
6868check " top with trace output at end" \
6969 " timerlat top -d 1s --on-end trace" 0 " ^ Saving trace to timerlat_trace.txt$"
70+
71+ # BPF action program tests
72+ if [ " $option " -eq 0 ]
73+ then
74+ # Test BPF action program properly in BPF mode
75+ [ -z " $BPFTOOL " ] && BPFTOOL=bpftool
76+ check " hist with BPF action program (BPF mode)" \
77+ " timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o --on-threshold shell,command='$BPFTOOL map dump name rtla_test_map'" \
78+ 2 ' "value": 42'
79+ else
80+ # Test BPF action program failure in non-BPF mode
81+ check " hist with BPF action program (non-BPF mode)" \
82+ " timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o" \
83+ 1 " BPF actions are not supported in tracefs-only mode"
84+ fi
7085done
7186
7287test_end
You can’t perform that action at this time.
0 commit comments