1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobes event arguments with types
4# requires: kprobe_events "x8/16/32/64":README
5
6gen_event() { # Bitsize
7  echo "p:testprobe $FUNCTION_FORK \$stack0:s$1 \$stack0:u$1 \$stack0:x$1 \$stack0:b4@4/$1"
8}
9
10check_types() { # s-type u-type x-type bf-type width
11  test $# -eq 5
12  CW=$5
13  CW=$((CW / 4))
14  X1=`printf "%x" $1 | tail -c ${CW}`
15  X2=`printf "%x" $2`
16  X3=`printf "%x" $3`
17  test $X1 = $X2
18  test $X2 = $X3
19  test 0x$X3 = $3
20
21  B4=`printf "%1x" $4`
22  B3=`printf "%03x" 0x$X3 | tail -c 2 | head -c 1`
23  test $B3 = $B4
24}
25
26for width in 64 32 16 8; do
27  : "Add new event with basic types"
28  gen_event $width > kprobe_events
29  grep testprobe kprobe_events
30  test -d events/kprobes/testprobe
31
32  : "Trace the event"
33  echo 1 > events/kprobes/testprobe/enable
34  ( echo "forked")
35  echo 0 > events/kprobes/testprobe/enable
36
37  : "Confirm the arguments is recorded in given types correctly"
38  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
39  check_types $ARGS $width
40
41  : "Clear event for next loop"
42  echo "-:testprobe" >> kprobe_events
43  clear_trace
44
45done
46
47exit_pass
48