1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event trigger - test inter-event histogram trigger eprobe on synthetic event
4# requires: dynamic_events synthetic_events events/syscalls/sys_enter_openat/hist "e[:[<group>/][<event>]] <attached-group>.<attached-event> [<args>]":README
5
6echo 0 > events/enable
7
8clear_dynamic_events
9
10SYSTEM="syscalls"
11START="sys_enter_openat"
12END="sys_exit_openat"
13FIELD="filename"
14SYNTH="synth_open"
15EPROBE="eprobe_open"
16
17echo "$SYNTH unsigned long filename; long ret;" > synthetic_events
18echo "hist:keys=common_pid:__arg__1=$FIELD" > events/$SYSTEM/$START/trigger
19echo "hist:keys=common_pid:filename=\$__arg__1,ret=ret:onmatch($SYSTEM.$START).trace($SYNTH,\$filename,\$ret)" > events/$SYSTEM/$END/trigger
20
21echo "e:$EPROBE synthetic/$SYNTH file=+0(\$filename):ustring ret=\$ret:s64" >> dynamic_events
22
23grep -q "$SYNTH" dynamic_events
24grep -q "$EPROBE" dynamic_events
25test -d events/synthetic/$SYNTH
26test -d events/eprobes/$EPROBE
27
28echo 1 > events/eprobes/$EPROBE/enable
29ls
30echo 0 > events/eprobes/$EPROBE/enable
31
32content=`grep '^ *ls-' trace | grep 'file='`
33nocontent=`grep '^ *ls-' trace | grep 'file=' | grep -v -e '"/' -e '"."'` || true
34
35if [ -z "$content" ]; then
36	exit_fail
37fi
38
39if [ ! -z "$nocontent" ]; then
40	exit_fail
41fi
42
43echo "-:$EPROBE" >> dynamic_events
44echo '!'"hist:keys=common_pid:filename=\$__arg__1,ret=ret:onmatch($SYSTEM.$START).trace($SYNTH,\$filename,\$ret)" > events/$SYSTEM/$END/trigger
45echo '!'"hist:keys=common_pid:__arg__1=$FIELD" > events/$SYSTEM/$START/trigger
46echo '!'"$SYNTH u64 filename; s64 ret;" >> synthetic_events
47
48! grep -q "$SYNTH" dynamic_events
49! grep -q "$EPROBE" dynamic_events
50! test -d events/synthetic/$SYNTH
51! test -d events/eprobes/$EPROBE
52
53clear_trace
54