tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/gpio/gpio-mockup-sysfs.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/gpio/gpio-mockup-sysfs.sh- Extension
.sh- Size
- 1694 bytes
- Lines
- 78
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
# Overrides functions in gpio-mockup.sh to test using the GPIO SYSFS uAPI
SYSFS=`grep -w sysfs /proc/mounts | cut -f2 -d' '`
[ -d "$SYSFS" ] || skip "sysfs is not mounted"
GPIO_SYSFS="${SYSFS}/class/gpio"
[ -d "$GPIO_SYSFS" ] || skip "CONFIG_GPIO_SYSFS is not selected"
PLATFORM_SYSFS=$SYSFS/devices/platform
sysfs_nr=
sysfs_ldir=
# determine the sysfs GPIO number given the $chip and $offset
# e.g. gpiochip1:32
find_sysfs_nr()
{
# e.g. /sys/devices/platform/gpio-mockup.1/gpiochip1
local platform=$(find $PLATFORM_SYSFS -mindepth 2 -maxdepth 2 -type d -name $chip)
[ "$platform" ] || fail "can't find platform of $chip"
# e.g. /sys/devices/platform/gpio-mockup.1/gpio/gpiochip508/base
local base=$(find ${platform%/*}/gpio/ -mindepth 2 -maxdepth 2 -type f -name base)
[ "$base" ] || fail "can't find base of $chip"
sysfs_nr=$(($(< "$base") + $offset))
sysfs_ldir="$GPIO_SYSFS/gpio$sysfs_nr"
}
acquire_line()
{
[ "$sysfs_nr" ] && return
find_sysfs_nr
echo "$sysfs_nr" > "$GPIO_SYSFS/export"
}
# The helpers being overridden...
get_line()
{
[ -e "$sysfs_ldir/value" ] && echo $(< "$sysfs_ldir/value")
}
set_line()
{
acquire_line
for option in $*; do
case $option in
active-high)
echo 0 > "$sysfs_ldir/active_low"
;;
active-low)
echo 1 > "$sysfs_ldir/active_low"
;;
input)
echo "in" > "$sysfs_ldir/direction"
;;
0)
echo "out" > "$sysfs_ldir/direction"
echo 0 > "$sysfs_ldir/value"
;;
1)
echo "out" > "$sysfs_ldir/direction"
echo 1 > "$sysfs_ldir/value"
;;
esac
done
}
release_line()
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.