tools/testing/selftests/livepatch/functions.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/livepatch/functions.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/livepatch/functions.sh
Extension
.sh
Size
11397 bytes
Lines
420
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

function log() {
	echo "$1" > /dev/kmsg
}

# skip(msg) - testing can't proceed
#	msg - explanation
function skip() {
	log "SKIP: $1"
	echo "SKIP: $1" >&2
	exit $ksft_skip
}

# root test
function is_root() {
	uid=$(id -u)
	if [ $uid -ne 0 ]; then
		echo "skip all tests: must be run as root" >&2
		exit $ksft_skip
	fi
}

# Check if we can compile the modules before loading them
function has_kdir() {
	if [ -z "$KDIR" ]; then
		KDIR="/lib/modules/$(uname -r)/build"
	fi

	if [ ! -d "$KDIR" ]; then
		echo "skip all tests: KDIR ($KDIR) not available to compile modules."
		exit $ksft_skip
	fi
}

# die(msg) - game over, man
#	msg - dying words
function die() {
	log "ERROR: $1"
	echo "ERROR: $1" >&2
	exit 1
}

function push_config() {
	DYNAMIC_DEBUG=$(grep '^kernel/livepatch' "$SYSFS_DEBUG_DIR/dynamic_debug/control" | \
			awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
	FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
	KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled")
	TRACING_ON=$(cat "$SYSFS_TRACING_DIR/tracing_on")
	CURRENT_TRACER=$(cat "$SYSFS_TRACING_DIR/current_tracer")
	FTRACE_FILTER=$(cat "$SYSFS_TRACING_DIR/set_ftrace_filter")
}

function pop_config() {
	if [[ -n "$DYNAMIC_DEBUG" ]]; then
		echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
	fi
	if [[ -n "$FTRACE_ENABLED" ]]; then
		sysctl kernel.ftrace_enabled="$FTRACE_ENABLED" &> /dev/null
	fi
	if [[ -n "$KPROBE_ENABLED" ]]; then
		echo "$KPROBE_ENABLED" > "$SYSFS_KPROBES_DIR/enabled"
	fi
	if [[ -n "$TRACING_ON" ]]; then
		echo "$TRACING_ON" > "$SYSFS_TRACING_DIR/tracing_on"
	fi
	if [[ -n "$CURRENT_TRACER" ]]; then
		echo "$CURRENT_TRACER" > "$SYSFS_TRACING_DIR/current_tracer"
	fi
	if [[ -n "$FTRACE_FILTER" ]]; then
		echo "$FTRACE_FILTER" \
			| sed -e "/#### all functions enabled ####/d" \

Annotation

Implementation Notes