File: kallsyms.sh

package info (click to toggle)
linux 6.19.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,760,712 kB
  • sloc: ansic: 27,010,185; asm: 273,400; sh: 151,347; python: 81,280; makefile: 58,564; perl: 34,311; xml: 21,064; cpp: 5,986; yacc: 4,841; lex: 2,901; awk: 1,707; sed: 30; ruby: 25
file content (56 lines) | stat: -rwxr-xr-x 1,552 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# perf kallsyms tests
# SPDX-License-Identifier: GPL-2.0

err=0

test_kallsyms() {
	echo "Basic perf kallsyms test"

	# Check if /proc/kallsyms is readable
	if [ ! -r /proc/kallsyms ]; then
		echo "Basic perf kallsyms test [Skipped: /proc/kallsyms not readable]"
		err=2
		return
	fi

	# Use a symbol that is definitely a function and present in all kernels, e.g. schedule
	symbol="schedule"

	# Run perf kallsyms
	# It prints "address symbol_name"
	output=$(perf kallsyms $symbol 2>&1)
	ret=$?

	if [ $ret -ne 0 ] || [ -z "$output" ]; then
		# If empty or failed, it might be due to permissions (kptr_restrict)
		# Check if we can grep the symbol from /proc/kallsyms directly
		if grep -q "$symbol" /proc/kallsyms 2>/dev/null; then
			# If it's in /proc/kallsyms but perf kallsyms returned empty/error,
			# it likely means perf couldn't parse it or access it correctly (e.g. kptr_restrict=2).
			echo "Basic perf kallsyms test [Skipped: $symbol found in /proc/kallsyms but perf kallsyms failed (output: '$output')]"
			err=2
			return
		else
			echo "Basic perf kallsyms test [Skipped: $symbol not found in /proc/kallsyms]"
			err=2
			return
		fi
	fi

	if echo "$output" | grep -q "not found"; then
		echo "Basic perf kallsyms test [Failed: output '$output' does not contain $symbol]"
		err=1
		return
	fi

	if perf kallsyms ErlingHaaland | grep -vq "not found"; then
		echo "Basic perf kallsyms test [Failed: ErlingHaaland found in the output]"
		err=1
		return
	fi
	echo "Basic perf kallsyms test [Success]"
}

test_kallsyms
exit $err