18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# Check open filename arg using perf trace + vfs_getname
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci# Uses the 'perf test shell' library to add probe:vfs_getname to the system
58c2ecf20Sopenharmony_ci# then use it with 'perf trace' using 'touch' to write to a temp file, then
68c2ecf20Sopenharmony_ci# checks that that was captured by the vfs_getname was used by 'perf trace',
78c2ecf20Sopenharmony_ci# that already handles "probe:vfs_getname" if present, and used in the
88c2ecf20Sopenharmony_ci# "open" syscall "filename" argument beautifier.
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
118c2ecf20Sopenharmony_ci# Arnaldo Carvalho de Melo <acme@kernel.org>, 2017
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci. $(dirname $0)/lib/probe.sh
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciskip_if_no_perf_probe || exit 2
168c2ecf20Sopenharmony_ciskip_if_no_perf_trace || exit 2
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci. $(dirname $0)/lib/probe_vfs_getname.sh
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cifile=$(mktemp /tmp/temporary_file.XXXXX)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_citrace_open_vfs_getname() {
238c2ecf20Sopenharmony_ci	evts=$(echo $(perf list syscalls:sys_enter_open* 2>&1 | egrep 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/')
248c2ecf20Sopenharmony_ci	perf trace -e $evts touch $file 2>&1 | \
258c2ecf20Sopenharmony_ci	egrep " +[0-9]+\.[0-9]+ +\( +[0-9]+\.[0-9]+ ms\): +touch\/[0-9]+ open(at)?\((dfd: +CWD, +)?filename: +${file}, +flags: CREAT\|NOCTTY\|NONBLOCK\|WRONLY, +mode: +IRUGO\|IWUGO\) += +[0-9]+$"
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciadd_probe_vfs_getname || skip_if_no_debuginfo
308c2ecf20Sopenharmony_cierr=$?
318c2ecf20Sopenharmony_ciif [ $err -ne 0 ] ; then
328c2ecf20Sopenharmony_ci	exit $err
338c2ecf20Sopenharmony_cifi
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci# Do not use whatever ~/.perfconfig file, it may change the output
368c2ecf20Sopenharmony_ci# via trace.{show_timestamp,show_prefix,etc}
378c2ecf20Sopenharmony_ciexport PERF_CONFIG=/dev/null
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_citrace_open_vfs_getname
408c2ecf20Sopenharmony_cierr=$?
418c2ecf20Sopenharmony_cirm -f ${file}
428c2ecf20Sopenharmony_cicleanup_probe_vfs_getname
438c2ecf20Sopenharmony_ciexit $err
44