From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135235; b=gtCNLOW1RTr/RCpCKqONnNToYMu/zUnN3dK2vmtUGZGYLuPD0EUgRHMhznQ6vOE1A9uW btTlgaf7LK64RCbHozvcPnu6tlKcdZrrDC1Pt9C1tX5WLI7rc+yRZQQocGxbfsVMp5pMf xMWUkid2RhsSKKMzu2+dOe3vvusb7QVugqS6r91W4+6YmxK1YoRor+hBfqc4+ARAscoPi K7d0hs9qU4Xmz1FtCtYlB7PSKDSIRzkbV8AzeAOAY5QUqcW0qa7nKtOs+5dAIdLXhik1U z7A2IpMJVXTfF9WzKOYjeVIgXb4vTuS82UPgBUGvdirtkDKzFPjDdSCmtXc0DUG5Brw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135235; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=hnkf0om1e2qwi4KMPfeiQi3i5uPrZGLwYdha6KIO15o=; b=Y0KZfH/tCCxLHJNnw5a4Gya21KuJZt6uYglB545jJXG8MJhOC/5GE4kAohgETH1BOEd1 x7EyDd/W/aERrboPG3xd4Xf9tTBwgtH8ytKH2hs8qH7DBUyh0AvEAyZTRx/L+PCeLD+64 VxDYpPVgR1m4sc+4e/Fh/JPpHgLzDkZ5ipYubg6toO64NYND2dA4RDo+8H2kUvEn0XL0d yYbWAbZNYYfDvDID08kupVe/0NsFeMJYKC6oRCik+YEQWa0Y/SCYCE49SCidqxY+qhjR/ 8YeZZJzhsKhRjXfV51lDFqsEewTGPdqi1BFVYg5nrNjwvnIWLi9m/x1wAVkARZpwz9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zXnwslvw; arc=none smtp.remote-ip=209.85.210.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E0D7606A6A1 for ; Tue, 1 Dec 2026 14:27:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E0D7606A6A1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zXnwslvw Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8c70c2ab5a2so4698508b3a.3 for ; Tue, 01 Dec 2026 06:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796135233; x=1796740033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hnkf0om1e2qwi4KMPfeiQi3i5uPrZGLwYdha6KIO15o=; b=zXnwslvwggrwuzq8dqUOeDeSImK74O000TIbt4QX6XWxaqcsPCKQfYRsUHLxYqTeDr 6Vt2nwAqn1FcjS0Ue6kQiFhP0uJqHj6JhWjsZBm/7Hxi1fi2ztGFn5l9XwJ5YupmbVQ6 IFOR21PQZmEOIV/OfoyT5NDZnSsShdb/yKSi/XHkurln59GYwGZXCsfDXeKlzUtNRnHV gbXlxwRdJeHQz1yUjByLgGDF0QkFK3PniiAvWarI4AfdMmVq6cPD8qaPX3Mpczvsbj6F qrHxkAeEhst+zRcJ7ShzMWeUwbkgGzwa7nAsi+60oAqnqKxpaiE6a7mPDiAcfltAUjb2 dBCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796135233; x=1796740033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=hnkf0om1e2qwi4KMPfeiQi3i5uPrZGLwYdha6KIO15o=; b=JQR0uqyqbBc0mAixM+8xR2sPs5/h+vL61oksyYncEqhvlqB8JmFIYRQDLtrMd/d42b VEJWw69W40ysEKBY7k96l9wqlrVSbKU7WoBhVGh+em44ZleW3EvGHnwmspNiARZ2r2Kn KzFU54dxItdvPtsDr0a2UDjiOVhSmzNDMbsDG9s1abZ/vE1i4QKSWono4+p49g3BoFwF 6GASKeGXKhWRWKloO0pFnDzDtDyRQgAVjl0eceDFYa9i5BEO6rchn49oOJsBWONqMIMu S9GicR7NMWiQB6xUKnNDGYksu+BCXOQbvO5NQ0PYOhVTyjkV55AXBI7cJVRNDnFsc+A3 yBnw== X-Forwarded-Encrypted: i=1; AL+hErHV1h6KUewp+RHaergfchQFoNmVuUhx584p1+yUJ/57TIpQJqAQM3up0yQ2FK5w5HqBVsVU3+yN2BLu@vger.kernel.org X-Gm-Message-State: APuU4Z+qczz/UWlS/RzYLeTRGH+CKcxmC2oDSC6jp1CuSNyqdB1A7rky X6IHryCopFECIL32lZt9k2NyP2GIydx0F+0CapVvXYoM+UioTAQHv0/B X-Gm-Gg: AZFdTZdqUjr7f+hF/hC0ZJMk60zmQ8qgXPL5zYJqutgJhVlgMAqUHHry+xQFwshQ8M0 2UOOsnZXPiz6+iH23wQ6gl+GiIPdJVdbkr2AoDS8ounpDFieQ1juU6RaAIEvPBTQHSA8iNmJta4 jGtvPsmWJKiWkIRGYdwWP9wszkATnGyAr797K4xKTh8Z6Qon8X2YBSjppvRof09JmC8hHhfEKzg bwU58B5GGclkHugdt7gDMba8Ge4vhdtR/3Xw8mFOktQx6Eg9yRwKOih0+7x2KapC+YK28gmnpSL xxMUy5q+vqOZBWUzi3YqLSlinwzj4iTuqbsweVNs2upAcq3wWRfuCmmP+KpIPDb/SzKhM+wWt+B WIxEX46KcpvZXPBnFNoXwYhaT+fNNNACzcf2fZ2e+xDLwIdiWONK7h0mSYS0lKD8gaKF2JqFJGb F2r8632zhbSiOORyNXeofuugtsYIpXZl952/jd+LAruE8A+H1pWpSHzCQ/JaDwZIZh8HPT5vDTo HefqobS4b8S3oVmzgY+g6IEaBBpt+ttPHFf24eKwnT/GjMCF43H9XrOYD8Jti9+nmVMncQ1rAOl KQfWYeyc8kzauyL0Mfcfdr4q75bTlrpSgjFIILNJGfahJ+FnKAKAvJQibHh/xltcS8hBlyvSInV E/QMLRgMaqY4K64FU25aJ+jLJ1LEa X-Received: by 2002:a05:6a00:17a3:b0:881:cbb0:6a90 with SMTP id d2e1a72fcca58-8c87d80b24bmr34441529b3a.58.1796135232249; Tue, 01 Dec 2026 06:27:12 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077944bsm20280798b3a.2.2026.12.01.06.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 06:27:11 -0800 (PST) From: Lin Tzu Yang To: Linus Walleij , Bartosz Golaszewski , Shuah Khan Cc: Bamvor Jian Zhang , Jonathan Corbet , 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 Message-ID: <20261201142703.900902-3-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 In-Reply-To: <20261201142703.900902-1-rongh7426@gmail.com> References: <20261201142703.900902-1-rongh7426@gmail.com> X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 + +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