tools/testing/selftests/memory-hotplug/mem-on-off-test.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
Extension
.sh
Size
6593 bytes
Lines
313
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
# SPDX-License-Identifier: GPL-2.0

SYSFS=

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

prerequisite()
{
	msg="skip all tests:"

	if [ $UID != 0 ]; then
		echo $msg must be run as root >&2
		exit $ksft_skip
	fi

	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`

	if [ ! -d "$SYSFS" ]; then
		echo $msg sysfs is not mounted >&2
		exit $ksft_skip
	fi

	if ! ls $SYSFS/devices/system/memory/memory* > /dev/null 2>&1; then
		echo $msg memory hotplug is not supported >&2
		exit $ksft_skip
	fi

	if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
		echo $msg no hot-pluggable memory >&2
		exit $ksft_skip
	fi
}

#
# list all hot-pluggable memory
#
hotpluggable_memory()
{
	local state=${1:-.\*}

	for memory in $SYSFS/devices/system/memory/memory*; do
		if grep -q 1 $memory/removable &&
		   grep -q $state $memory/state; then
			echo ${memory##/*/memory}
		fi
	done
}

hotpluggable_offline_memory()
{
	hotpluggable_memory offline
}

hotpluggable_online_memory()
{
	hotpluggable_memory online
}

memory_is_online()
{
	grep -q online $SYSFS/devices/system/memory/memory$1/state
}

memory_is_offline()
{
	grep -q offline $SYSFS/devices/system/memory/memory$1/state
}

Annotation

Implementation Notes