tools/testing/selftests/gpio/gpio-aggregator.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/gpio/gpio-aggregator.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/gpio/gpio-aggregator.sh
Extension
.sh
Size
23382 bytes
Lines
728
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
# Copyright (C) 2025 Bartosz Golaszewski <brgl@bgdev.pl>
# Copyright (C) 2025 Koichiro Den <koichiro.den@canonical.com>

BASE_DIR=$(dirname "$0")
CONFIGFS_SIM_DIR="/sys/kernel/config/gpio-sim"
CONFIGFS_AGG_DIR="/sys/kernel/config/gpio-aggregator"
SYSFS_AGG_DIR="/sys/bus/platform/drivers/gpio-aggregator"
MODULE="gpio-aggregator"

fail() {
	echo "$*" >&2
	echo "GPIO $MODULE test FAIL"
	exit 1
}

skip() {
	echo "$*" >&2
	echo "GPIO $MODULE test SKIP"
	exit 4
}

# gpio-sim
sim_enable_chip() {
	local CHIP=$1

	echo 1 > "$CONFIGFS_SIM_DIR/$CHIP/live" || fail "Unable to enable the chip"
}

sim_disable_chip() {
	local CHIP=$1

	echo 0 > "$CONFIGFS_SIM_DIR/$CHIP/live" || fail "Unable to disable the chip"
}

sim_configfs_cleanup() {
	local NOCHECK=${1:-0}

	for CHIP_DIR in "$CONFIGFS_SIM_DIR"/*; do
		[ -d "$CHIP_DIR" ] || continue
		echo 0 > "$CHIP_DIR/live"
		find "$CHIP_DIR" -depth -type d -exec rmdir {} \;
	done
	[ "$NOCHECK" -eq 1 ] && return;
	remaining=$(find "$CONFIGFS_SIM_DIR" -mindepth 1 -type d 2> /dev/null)
	if [ -n "$remaining" ]; then
		fail "Directories remain in $CONFIGFS_SIM_DIR: $remaining"
	fi
}

sim_get_chip_label() {
	local CHIP=$1
	local BANK=$2
	local CHIP_NAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/$BANK/chip_name" 2> /dev/null) || \
		fail "Unable to read the chip name from configfs"

	$BASE_DIR/gpio-chip-info "/dev/$CHIP_NAME" label || \
		fail "Unable to read the chip label from the character device"
}

# gpio-aggregator
agg_create_chip() {
	local CHIP=$1

	mkdir "$CONFIGFS_AGG_DIR/$CHIP"
}

agg_remove_chip() {
	local CHIP=$1

Annotation

Implementation Notes