tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc

Source file repositories/reference/linux-study-clean/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
Extension
.tc
Size
2309 bytes
Lines
108
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: ftrace - function pid filters
# requires: set_ftrace_pid set_ftrace_filter function:tracer
# flags: instance

# Make sure that function pid matching filter works.
# Also test it on an instance directory

do_function_fork=1
do_funcgraph_proc=1

if [ ! -f options/function-fork ]; then
    do_function_fork=0
    echo "no option for function-fork found. Option will not be tested."
fi

if [ ! -f options/funcgraph-proc ]; then
    do_funcgraph_proc=0
    echo "no option for function-fork found. Option will not be tested."
fi

read PID _ < /proc/self/stat

if [ $do_function_fork -eq 1 ]; then
    # default value of function-fork option
    orig_value=`grep function-fork trace_options`
fi

if [ $do_funcgraph_proc -eq 1 ]; then
    orig_value2=`cat options/funcgraph-proc`
    echo 1 > options/funcgraph-proc
fi

do_reset() {
    if [ $do_function_fork -eq 1 ]; then
	echo $orig_value > trace_options
    fi

    if [ $do_funcgraph_proc -eq 1 ]; then
	echo $orig_value2 > options/funcgraph-proc
    fi
}

fail() { # msg
    do_reset
    echo $1
    exit_fail
}

do_test() {
    TRACER=$1

    disable_tracing

    echo do_execve* > set_ftrace_filter
    echo $FUNCTION_FORK >> set_ftrace_filter

    echo $PID > set_ftrace_pid
    echo $TRACER > current_tracer

    if [ $do_function_fork -eq 1 ]; then
	# don't allow children to be traced
	echo nofunction-fork > trace_options
    fi

    enable_tracing
    yield

    count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`

Annotation

Implementation Notes