xref: /linux/tools/testing/selftests/ftrace/test.d/dynevent/btf_probe_event.tc (revision 6439079365dcb33c6701f5f0e480ac2c17312b6b)
1*7d8d6ad6SMasami Hiramatsu (Google)#!/bin/sh
2*7d8d6ad6SMasami Hiramatsu (Google)# SPDX-License-Identifier: GPL-2.0
3*7d8d6ad6SMasami Hiramatsu (Google)# description: BTF event with typecast and percpu access
4*7d8d6ad6SMasami Hiramatsu (Google)# requires: dynamic_events "this_cpu_read(<fetcharg>)":README "[(structname[,field])]<argname>[->field[->field|.field...]]":README
5*7d8d6ad6SMasami Hiramatsu (Google)
6*7d8d6ad6SMasami Hiramatsu (Google)# Check if the sample module is loaded
7*7d8d6ad6SMasami Hiramatsu (Google)if ! lsmod | grep -q trace_events_sample; then
8*7d8d6ad6SMasami Hiramatsu (Google)  modprobe trace-events-sample || exit_unresolved
9*7d8d6ad6SMasami Hiramatsu (Google)fi
10*7d8d6ad6SMasami Hiramatsu (Google)
11*7d8d6ad6SMasami Hiramatsu (Google)echo 0 > events/enable
12*7d8d6ad6SMasami Hiramatsu (Google)echo > dynamic_events
13*7d8d6ad6SMasami Hiramatsu (Google)
14*7d8d6ad6SMasami Hiramatsu (Google)# The sample_timer_cb(struct timer_list *t) is called.
15*7d8d6ad6SMasami Hiramatsu (Google)# We want to check (STRUCT,FIELD)VAR typecast and this_cpu_read() access.
16*7d8d6ad6SMasami Hiramatsu (Google)# (foo_timer_data,timer)t converts t to struct foo_timer_data * using container_of.
17*7d8d6ad6SMasami Hiramatsu (Google)# data->counter is a per-cpu pointer to int.
18*7d8d6ad6SMasami Hiramatsu (Google)# this_cpu_read(data->counter) should give the value of the counter.
19*7d8d6ad6SMasami Hiramatsu (Google)
20*7d8d6ad6SMasami Hiramatsu (Google)echo 'f:mysample/myevent sample_timer_cb name=(foo_timer_data,timer)t->name:string count=this_cpu_read((foo_timer_data,timer)t->counter)' >> dynamic_events
21*7d8d6ad6SMasami Hiramatsu (Google)
22*7d8d6ad6SMasami Hiramatsu (Google)echo 1 > events/mysample/myevent/enable
23*7d8d6ad6SMasami Hiramatsu (Google)echo 1 > events/sample-trace/foo_timer_fn/enable
24*7d8d6ad6SMasami Hiramatsu (Google)
25*7d8d6ad6SMasami Hiramatsu (Google)sleep 2
26*7d8d6ad6SMasami Hiramatsu (Google)
27*7d8d6ad6SMasami Hiramatsu (Google)echo 0 > events/mysample/myevent/enable
28*7d8d6ad6SMasami Hiramatsu (Google)echo 0 > events/sample-trace/foo_timer_fn/enable
29*7d8d6ad6SMasami Hiramatsu (Google)
30*7d8d6ad6SMasami Hiramatsu (Google)# Compare the values.
31*7d8d6ad6SMasami Hiramatsu (Google)MATCH=0
32*7d8d6ad6SMasami Hiramatsu (Google)while read line; do
33*7d8d6ad6SMasami Hiramatsu (Google)  if echo $line | grep -q "foo_timer_fn:"; then
34*7d8d6ad6SMasami Hiramatsu (Google)    NAME=`echo $line | sed 's/.*name=\([^ ]*\) .*/\1/'`
35*7d8d6ad6SMasami Hiramatsu (Google)    COUNT=`echo $line | sed 's/.*count=\([^ ]*\).*/\1/'`
36*7d8d6ad6SMasami Hiramatsu (Google)    if grep -q "myevent:.*name=\"${NAME}\" count=$COUNT" trace; then
37*7d8d6ad6SMasami Hiramatsu (Google)       MATCH=$((MATCH+1))
38*7d8d6ad6SMasami Hiramatsu (Google)    fi
39*7d8d6ad6SMasami Hiramatsu (Google)  fi
40*7d8d6ad6SMasami Hiramatsu (Google)done < trace
41*7d8d6ad6SMasami Hiramatsu (Google)
42*7d8d6ad6SMasami Hiramatsu (Google)if [ $MATCH -eq 0 ]; then
43*7d8d6ad6SMasami Hiramatsu (Google)  echo "No matching events found"
44*7d8d6ad6SMasami Hiramatsu (Google)  exit_fail
45*7d8d6ad6SMasami Hiramatsu (Google)fi
46*7d8d6ad6SMasami Hiramatsu (Google)
47*7d8d6ad6SMasami Hiramatsu (Google)# Clean up
48*7d8d6ad6SMasami Hiramatsu (Google)echo 0 > events/mysample/myevent/enable
49*7d8d6ad6SMasami Hiramatsu (Google)echo 0 > events/sample-trace/foo_timer_fn/enable
50*7d8d6ad6SMasami Hiramatsu (Google)echo > dynamic_events
51*7d8d6ad6SMasami Hiramatsu (Google)clear_trace
52