tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh

Source file repositories/reference/linux-study-clean/tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh
Extension
.sh
Size
3440 bytes
Lines
115
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/bash
# perf_probe :: Reject blacklisted probes (exclusive)
# SPDX-License-Identifier: GPL-2.0

#
#	test_adding_blacklisted of perf_probe test
#	Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
#	Author: Michael Petlan <mpetlan@redhat.com>
#
#	Description:
#
#		Blacklisted functions should not be added successfully as probes,
#	they must be skipped.
#

DIR_PATH="$(dirname $0)"
TEST_RESULT=0

# include working environment
. "$DIR_PATH/../common/init.sh"

# skip if not supported
BLACKFUNC_LIST=`head -n 5 /sys/kernel/debug/kprobes/blacklist 2> /dev/null | cut -f2`
if [ -z "$BLACKFUNC_LIST" ]; then
	print_overall_skipped
	exit 2
fi

# try to find vmlinux with DWARF debug info
VMLINUX_FILE=$(perf probe -v random_probe |& grep "Using.*for symbols" | sed -r 's/^Using (.*) for symbols$/\1/')

# remove all previously added probes
clear_all_probes


### adding blacklisted function
REGEX_SCOPE_FAIL="Failed to find scope of probe point"
REGEX_SKIP_MESSAGE=" is blacklisted function, skip it\."
REGEX_NOT_FOUND_MESSAGE="Probe point \'$RE_EVENT\' not found."
REGEX_ERROR_MESSAGE="Error: Failed to add events."
REGEX_INVALID_ARGUMENT="Failed to write event: Invalid argument"
REGEX_SYMBOL_FAIL="Failed to find symbol at $RE_ADDRESS"
REGEX_OUT_SECTION="$RE_EVENT is out of \.\w+, skip it"
REGEX_MISSING_DECL_LINE="A function DIE doesn't have decl_line. Maybe broken DWARF?"

BLACKFUNC=""
SKIP_DWARF=0

for BLACKFUNC in $BLACKFUNC_LIST; do
	echo "Probing $BLACKFUNC"

	# functions from blacklist should be skipped by perf probe
	! $CMD_PERF probe $BLACKFUNC > $LOGS_DIR/adding_blacklisted.log 2> $LOGS_DIR/adding_blacklisted.err
	PERF_EXIT_CODE=$?

	# check for bad DWARF polluting the result
	"$DIR_PATH/../common/check_all_patterns_found.pl" \
		"$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err

	if [ $? -eq 0 ]; then
		SKIP_DWARF=1
		echo "Result polluted by broken DWARF, trying another probe"

		# confirm that the broken DWARF comes from assembler
		if [ -n "$VMLINUX_FILE" ]; then
			readelf -wi "$VMLINUX_FILE" |
			awk -v probe="$BLACKFUNC" '/DW_AT_language/ { comp_lang = $0 }
						   $0 ~ probe { if (comp_lang) { print comp_lang }; exit }' |
			grep -q "MIPS assembler"

Annotation

Implementation Notes