tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
Extension
.tc
Size
4486 bytes
Lines
162
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 - test reading of set_ftrace_filter
#
# The triggers are set within the set_ftrace_filter file
# requires: set_ftrace_filter
#
# The set_ftrace_filter file of ftrace is used to list functions as well as
# triggers (probes) attached to functions. The code to read this file is not
# straight forward and has had various bugs in the past. This test is designed
# to add functions and triggers to that file in various ways and read that
# file in various ways (cat vs dd).
#

fail() { # mesg
    echo $1
    exit_fail
}

FILTER=set_ftrace_filter
FUNC1="schedule"
if grep '^sched_tick\b' available_filter_functions; then
    FUNC2="sched_tick"
elif grep '^scheduler_tick\b' available_filter_functions; then
    FUNC2="scheduler_tick"
else
    exit_unresolved
fi


ALL_FUNCS="#### all functions enabled ####"

test_func() {
    if ! echo "$1" | grep -q "^$2\$"; then
	return 0
    fi
    echo "$1" | grep -v "^$2\$"
    return 1
}

check_set_ftrace_filter() {
    cat=`cat $FILTER`
    dd1=`dd if=$FILTER bs=1 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`
    dd100=`dd if=$FILTER bs=100 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`

    echo "Testing '$@'"

    while [ $# -gt 0 ]; do
	echo "test $1"
	if cat=`test_func "$cat" "$1"`; then
	    return 0
	fi
	if dd1=`test_func "$dd1" "$1"`; then
	    return 0
	fi
	if dd100=`test_func "$dd100" "$1"`; then
	    return 0
	fi
	shift
    done

    if [ -n "$cat" ]; then
	return 0
    fi
    if [ -n "$dd1" ]; then
	return 0
    fi
    if [ -n "$dd100" ]; then
	return 0
    fi

Annotation

Implementation Notes