Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Lin Tzu Yang <rongh7426@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Shuah Khan <shuah@kernel.org>
Cc: Bamvor Jian Zhang <bamv2005@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-gpio@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser
Date: Tue,  1 Dec 2026 22:27:03 +0800	[thread overview]
Message-ID: <20261201142703.900902-3-rongh7426@gmail.com> (raw)
In-Reply-To: <20261201142703.900902-1-rongh7426@gmail.com>

gpio-sim and gpio-aggregator have selftests, gpio-virtuser has none.
Add one that uses a gpio-sim chip as the provider, in the style of
gpio-aggregator.sh. It covers:

- creating and removing consumers, with lookups by chip label and
  offset and by line name, several GPIOs and connector IDs, and the
  cases that must fail: no lookup, a missing chip or offset, a line
  that is already requested, and writing the current state to 'live'
- the configfs attributes: defaults, accepted and rejected values,
  a key of the maximum length, and that the configuration is locked
  while the consumer is live
- driving lines over debugfs and checking them on the gpio-sim side:
  output and input values, array values, active_low, the consumer
  name and edge interrupt counting
- that a consumer can't be enabled while its provider is disabled

The *_atomic debugfs attributes are not tested, because gpio-sim
lines can sleep.

Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
 tools/testing/selftests/gpio/Makefile         |   3 +-
 tools/testing/selftests/gpio/config           |   2 +
 tools/testing/selftests/gpio/gpio-virtuser.sh | 420 ++++++++++++++++++
 3 files changed, 424 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/gpio/gpio-virtuser.sh

diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 741ab21e12..a68b98879e 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
-TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh
+TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh \
+	     gpio-virtuser.sh
 TEST_FILES := gpio-mockup-sysfs.sh
 TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name \
 			   gpio-cdev-uaf
diff --git a/tools/testing/selftests/gpio/config b/tools/testing/selftests/gpio/config
index 1287abeaac..12a6639cc1 100644
--- a/tools/testing/selftests/gpio/config
+++ b/tools/testing/selftests/gpio/config
@@ -3,3 +3,5 @@ CONFIG_GPIO_CDEV=y
 CONFIG_GPIO_MOCKUP=m
 CONFIG_GPIO_SIM=m
 CONFIG_GPIO_AGGREGATOR=m
+CONFIG_GPIO_VIRTUSER=m
+CONFIG_DEBUG_FS=y
diff --git a/tools/testing/selftests/gpio/gpio-virtuser.sh b/tools/testing/selftests/gpio/gpio-virtuser.sh
new file mode 100755
index 0000000000..f5993904d3
--- /dev/null
+++ b/tools/testing/selftests/gpio/gpio-virtuser.sh
@@ -0,0 +1,420 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2026 Lin Tzu Yang <rongh7426@gmail.com>
+
+CONFIGFS_SIM_DIR="/sys/kernel/config/gpio-sim"
+CONFIGFS_VU_DIR="/sys/kernel/config/gpio-virtuser"
+DEBUGFS_VU_DIR="/sys/kernel/debug/gpio-virtuser"
+MODULE="gpio-virtuser"
+
+fail() {
+	echo "$*" >&2
+	echo "GPIO $MODULE test FAIL"
+	exit 1
+}
+
+skip() {
+	echo "$*" >&2
+	echo "GPIO $MODULE test SKIP"
+	exit 4
+}
+
+# gpio-sim
+
+sim_create_chip() {
+	local CHIP=$1
+	local LABEL=$2
+	local NUM_LINES=$3
+
+	mkdir "$CONFIGFS_SIM_DIR/$CHIP" || fail "Unable to create the chip"
+	mkdir "$CONFIGFS_SIM_DIR/$CHIP/bank0" || fail "Unable to create the bank"
+	echo "$LABEL" > "$CONFIGFS_SIM_DIR/$CHIP/bank0/label" || \
+		fail "Unable to set the chip label"
+	echo "$NUM_LINES" > "$CONFIGFS_SIM_DIR/$CHIP/bank0/num_lines" || \
+		fail "Unable to set the number of lines"
+}
+
+sim_set_line_name() {
+	local CHIP=$1
+	local OFFSET=$2
+	local NAME=$3
+	local LINE_DIR="$CONFIGFS_SIM_DIR/$CHIP/bank0/line$OFFSET"
+
+	mkdir -p "$LINE_DIR" || fail "Unable to create the line"
+	echo "$NAME" > "$LINE_DIR/name" || fail "Unable to set the line name"
+}
+
+sim_enable_chip() {
+	echo 1 > "$CONFIGFS_SIM_DIR/$1/live" || fail "Unable to enable the chip"
+}
+
+sim_disable_chip() {
+	echo 0 > "$CONFIGFS_SIM_DIR/$1/live" || fail "Unable to disable the chip"
+}
+
+sim_sysfs_line() {
+	local CHIP=$1
+	local OFFSET=$2
+	local DEV_NAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/dev_name")
+	local CHIP_NAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/bank0/chip_name")
+
+	echo "/sys/devices/platform/$DEV_NAME/$CHIP_NAME/sim_gpio$OFFSET"
+}
+
+sim_get_value() {
+	cat "$(sim_sysfs_line "$1" "$2")/value" || \
+		fail "Unable to read the simulated line value"
+}
+
+sim_set_pull() {
+	echo "$3" > "$(sim_sysfs_line "$1" "$2")/pull" || \
+		fail "Unable to set the simulated line pull"
+}
+
+sim_configfs_cleanup() {
+	local NOCHECK=${1:-0}
+
+	for CHIP_DIR in "$CONFIGFS_SIM_DIR"/*; do
+		[ -d "$CHIP_DIR" ] || continue
+		echo 0 > "$CHIP_DIR/live" 2> /dev/null
+		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
+}
+
+# gpio-virtuser
+
+vu_create_dev() {
+	mkdir "$CONFIGFS_VU_DIR/$1" || fail "Unable to create the consumer"
+}
+
+vu_remove_dev() {
+	find "$CONFIGFS_VU_DIR/$1" -depth -type d -exec rmdir {} \; || \
+		fail "Unable to remove the consumer"
+}
+
+# Add one GPIO to the lookup for connector ID $2 of consumer $1.
+# $3 is the entry name, $4 the key, $5 the offset (-1 for a line name).
+vu_add_entry() {
+	local ENTRY_DIR="$CONFIGFS_VU_DIR/$1/$2/$3"
+
+	mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+	echo "$4" > "$ENTRY_DIR/key" || fail "Unable to set the lookup key"
+	echo "$5" > "$ENTRY_DIR/offset" || fail "Unable to set the lookup offset"
+}
+
+vu_enable_dev() {
+	echo 1 > "$CONFIGFS_VU_DIR/$1/live" || fail "Unable to enable the consumer"
+}
+
+vu_disable_dev() {
+	echo 0 > "$CONFIGFS_VU_DIR/$1/live" || fail "Unable to disable the consumer"
+}
+
+vu_debugfs_dir() {
+	local DEV_NAME=$(cat "$CONFIGFS_VU_DIR/$1/dev_name")
+
+	echo "$DEBUGFS_VU_DIR/$DEV_NAME"
+}
+
+vu_configfs_cleanup() {
+	local NOCHECK=${1:-0}
+
+	for DEV_DIR in "$CONFIGFS_VU_DIR"/*; do
+		[ -d "$DEV_DIR" ] || continue
+		echo 0 > "$DEV_DIR/live" 2> /dev/null
+		find "$DEV_DIR" -depth -type d -exec rmdir {} \;
+	done
+	[ "$NOCHECK" -eq 1 ] && return
+	remaining=$(find "$CONFIGFS_VU_DIR" -mindepth 1 -type d 2> /dev/null)
+	if [ -n "$remaining" ]; then
+		fail "Directories remain in $CONFIGFS_VU_DIR: $remaining"
+	fi
+}
+
+# Load the modules. This will pull in configfs if needed too.
+modprobe gpio-sim || skip "unable to load the gpio-sim module"
+modprobe gpio-virtuser || skip "unable to load the gpio-virtuser module"
+
+# Make sure configfs is mounted at /sys/kernel/config. Wait a bit if needed.
+for IDX in $(seq 5); do
+	if [ "$IDX" -eq "5" ]; then
+		skip "configfs not mounted at /sys/kernel/config"
+	fi
+
+	mountpoint -q /sys/kernel/config && break
+	sleep 0.1
+done
+
+[ -d "$DEBUGFS_VU_DIR" ] || skip "debugfs not mounted at /sys/kernel/debug"
+
+# If the modules were already loaded: remove all previous devices
+vu_configfs_cleanup
+sim_configfs_cleanup
+
+trap "exit 1" TERM INT
+trap "vu_configfs_cleanup 1; sim_configfs_cleanup 1" EXIT
+
+# Use a gpio-sim chip with named lines as the provider
+sim_create_chip sim0 "gpio-virtuser-test" 8
+for IDX in $(seq 0 7); do
+	sim_set_line_name sim0 "$IDX" "vu-test-line$IDX"
+done
+sim_enable_chip sim0
+
+echo "1. Consumer creation and removal"
+
+echo "1.1. Lookup by chip label and offset"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer is live before enabling"
+DEV_NAME=$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")
+vu_enable_dev dev0
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "1" || fail "consumer is not live"
+test "$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")" = "$DEV_NAME" || \
+	fail "dev_name changed when the consumer was enabled"
+test -d "/sys/bus/platform/devices/$DEV_NAME" || fail "no platform device $DEV_NAME"
+DBG_DIR=$(vu_debugfs_dir dev0)
+test -d "$DBG_DIR/gpiod:foo" || fail "debugfs array directory missing"
+test -d "$DBG_DIR/gpiod:foo:0" || fail "debugfs line directory missing"
+vu_disable_dev dev0
+test -d "$DBG_DIR" && fail "debugfs directory still present after disabling"
+vu_remove_dev dev0
+
+echo "1.2. Lookup by line name"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "vu-test-line5" -1
+vu_enable_dev dev0
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.3. Several GPIOs and several connector IDs"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_add_entry dev0 foo 1 "gpio-virtuser-test" 1
+vu_add_entry dev0 bar 0 "vu-test-line2" -1
+vu_enable_dev dev0
+DBG_DIR=$(vu_debugfs_dir dev0)
+for DIR in gpiod:foo gpiod:foo:0 gpiod:foo:1 gpiod:bar gpiod:bar:0; do
+	test -d "$DBG_DIR/$DIR" || fail "debugfs directory $DIR missing"
+done
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.4. Can't enable a consumer without any lookup"
+vu_create_dev dev0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "consumer without lookups unexpectedly enabled"
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer unexpectedly alive"
+vu_remove_dev dev0
+
+echo "1.5. Can't enable a consumer whose GPIO doesn't exist"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "no-such-chip" 0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "consumer with a missing chip unexpectedly enabled"
+vu_remove_dev dev0
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 8
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "consumer with an out-of-range offset unexpectedly enabled"
+vu_remove_dev dev0
+
+echo "1.6. Can't request a line twice"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 4
+vu_enable_dev dev0
+vu_create_dev dev1
+vu_add_entry dev1 foo 0 "gpio-virtuser-test" 4
+echo 1 > "$CONFIGFS_VU_DIR/dev1/live" 2> /dev/null && \
+	fail "second consumer of the same line unexpectedly enabled"
+vu_remove_dev dev1
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.7. Writing the current state to 'live' fails"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+echo 0 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "disabling a disabled consumer unexpectedly succeeded"
+vu_enable_dev dev0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "enabling an enabled consumer unexpectedly succeeded"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "2. Configfs attributes"
+
+ENTRY_DIR="$CONFIGFS_VU_DIR/dev0/foo/0"
+
+echo "2.1. Default values"
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+test "$(cat "$ENTRY_DIR/key")" = "" || fail "default key is not empty"
+test "$(cat "$ENTRY_DIR/offset")" = "0" || fail "default offset is not 0"
+test "$(cat "$ENTRY_DIR/drive")" = "push-pull" || fail "default drive is not push-pull"
+test "$(cat "$ENTRY_DIR/pull")" = "as-is" || fail "default pull is not as-is"
+test "$(cat "$ENTRY_DIR/active_low")" = "0" || fail "default active_low is not 0"
+test "$(cat "$ENTRY_DIR/transitory")" = "0" || fail "default transitory is not 0"
+vu_remove_dev dev0
+
+echo "2.2. Valid values are accepted and invalid ones rejected"
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+for VAL in open-drain open-source push-pull; do
+	echo "$VAL" > "$ENTRY_DIR/drive" || fail "drive $VAL rejected"
+	test "$(cat "$ENTRY_DIR/drive")" = "$VAL" || fail "drive $VAL not stored"
+done
+echo foobar > "$ENTRY_DIR/drive" 2> /dev/null && fail "invalid drive accepted"
+for VAL in pull-up pull-down pull-disabled as-is; do
+	echo "$VAL" > "$ENTRY_DIR/pull" || fail "pull $VAL rejected"
+	test "$(cat "$ENTRY_DIR/pull")" = "$VAL" || fail "pull $VAL not stored"
+done
+echo foobar > "$ENTRY_DIR/pull" 2> /dev/null && fail "invalid pull accepted"
+echo 65534 > "$ENTRY_DIR/offset" || fail "offset 65534 rejected"
+echo 65535 > "$ENTRY_DIR/offset" 2> /dev/null && fail "offset 65535 accepted"
+echo foo > "$ENTRY_DIR/offset" 2> /dev/null && fail "non-numeric offset accepted"
+echo x > "$ENTRY_DIR/active_low" 2> /dev/null && fail "invalid active_low accepted"
+echo x > "$ENTRY_DIR/transitory" 2> /dev/null && fail "invalid transitory accepted"
+echo 1 > "$ENTRY_DIR/active_low" || fail "active_low 1 rejected"
+test "$(cat "$ENTRY_DIR/active_low")" = "1" || fail "active_low not stored"
+echo 1 > "$ENTRY_DIR/transitory" || fail "transitory 1 rejected"
+test "$(cat "$ENTRY_DIR/transitory")" = "1" || fail "transitory not stored"
+vu_remove_dev dev0
+
+echo "2.3. A key of the maximum length reads back intact"
+# A show that writes past the page for such a key is only caught by KASAN.
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+head -c 4095 /dev/zero | tr '\0' 'k' > "$ENTRY_DIR/key" || fail "long key rejected"
+test "$(cat "$ENTRY_DIR/key" | wc -c)" -ge 4095 || fail "long key truncated"
+test "$(cat "$ENTRY_DIR/key" | tr -d 'k\n' | wc -c)" = "0" || \
+	fail "long key read back corrupted"
+vu_remove_dev dev0
+
+echo "2.4. Configuration is locked while the consumer is live"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_enable_dev dev0
+for ATTR in key offset drive pull active_low transitory; do
+	VAL=$(cat "$ENTRY_DIR/$ATTR")
+	echo "$VAL" > "$ENTRY_DIR/$ATTR" 2> /dev/null && \
+		fail "$ATTR unexpectedly writable while live"
+done
+mkdir "$CONFIGFS_VU_DIR/dev0/foo/1" 2> /dev/null && \
+	fail "entry unexpectedly created while live"
+mkdir "$CONFIGFS_VU_DIR/dev0/bar" 2> /dev/null && \
+	fail "lookup unexpectedly created while live"
+rmdir "$ENTRY_DIR" 2> /dev/null && fail "entry unexpectedly removed while live"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3. Controlling lines over debugfs"
+
+echo "3.1. Output values reach the provider"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 1
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo output-high > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(cat "$LINE_DIR/direction")" = "output" || fail "direction is not output"
+test "$(sim_get_value sim0 1)" = "1" || fail "output-high not seen by the provider"
+echo 0 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 1)" = "0" || fail "value 0 not seen by the provider"
+echo 1 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 1)" = "1" || fail "value 1 not seen by the provider"
+echo 2 > "$LINE_DIR/value" 2> /dev/null && fail "invalid value accepted"
+echo output > "$LINE_DIR/direction" 2> /dev/null && fail "invalid direction accepted"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.2. Input values come from the provider"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 2
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo input > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(cat "$LINE_DIR/direction")" = "input" || fail "direction is not input"
+sim_set_pull sim0 2 pull-up
+test "$(cat "$LINE_DIR/value")" = "1" || fail "pull-up not seen by the consumer"
+sim_set_pull sim0 2 pull-down
+test "$(cat "$LINE_DIR/value")" = "0" || fail "pull-down not seen by the consumer"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.3. Array values"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 5
+vu_add_entry dev0 foo 1 "gpio-virtuser-test" 6
+vu_enable_dev dev0
+DBG_DIR=$(vu_debugfs_dir dev0)
+echo output-low > "$DBG_DIR/gpiod:foo:0/direction" || fail "Unable to set direction"
+echo output-low > "$DBG_DIR/gpiod:foo:1/direction" || fail "Unable to set direction"
+echo 10 > "$DBG_DIR/gpiod:foo/values" || fail "Unable to set array values"
+test "$(sim_get_value sim0 5)$(sim_get_value sim0 6)" = "10" || \
+	fail "array values not seen by the provider"
+test "$(cat "$DBG_DIR/gpiod:foo/values")" = "10" || fail "array values read back wrong"
+echo 01 > "$DBG_DIR/gpiod:foo/values" || fail "Unable to set array values"
+test "$(sim_get_value sim0 5)$(sim_get_value sim0 6)" = "01" || \
+	fail "array values not seen by the provider"
+echo 1 > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "short array accepted"
+echo 111 > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "long array accepted"
+echo 1x > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "invalid array accepted"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.4. active_low inverts the logical value"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 7
+echo 1 > "$ENTRY_DIR/active_low" || fail "Unable to set active_low"
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo output-high > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(sim_get_value sim0 7)" = "0" || fail "active-low output-high is not low"
+echo 0 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 7)" = "1" || fail "active-low value 0 is not high"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.5. Consumer name"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+test "$(cat "$LINE_DIR/consumer")" = "foo" || fail "default consumer name is not foo"
+echo test-consumer > "$LINE_DIR/consumer" || fail "Unable to set the consumer name"
+test "$(cat "$LINE_DIR/consumer")" = "test-consumer" || fail "consumer name not stored"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.6. Edge interrupts are counted"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo input > "$LINE_DIR/direction" || fail "Unable to set direction"
+sim_set_pull sim0 3 pull-down
+echo 1 > "$LINE_DIR/interrupts" || fail "Unable to enable interrupts"
+test "$(cat "$LINE_DIR/interrupts")" = "0" || fail "interrupt count is not 0"
+sim_set_pull sim0 3 pull-up
+sim_set_pull sim0 3 pull-down
+test "$(cat "$LINE_DIR/interrupts")" = "2" || fail "interrupt count is not 2"
+echo 0 > "$LINE_DIR/interrupts" || fail "Unable to disable interrupts"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "4. Provider availability"
+
+echo "4.1. Can't enable a consumer while the provider is disabled"
+sim_disable_chip sim0
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+	fail "consumer unexpectedly enabled with the provider disabled"
+vu_remove_dev dev0
+
+echo "GPIO $MODULE test PASS"
-- 
2.47.3


  parent reply	other threads:[~2026-12-01 14:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:27 [PATCH 0/2] gpio: virtuser: add a selftest Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values Lin Tzu Yang
2026-12-01 14:27 ` Lin Tzu Yang [this message]
2026-12-01 14:39   ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201142703.900902-3-rongh7426@gmail.com \
    --to=rongh7426@gmail.com \
    --cc=bamv2005@gmail.com \
    --cc=brgl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linusw@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox