Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: gpio: gpio-sim: Fix missing chip disablements

Since upstream commit 8bd76b3d3f3a ("gpio: sim: lock up configfs that an
instantiated device depends on"), rmdir for an active virtual devices
been prohibited.

Update gpio-sim selftest to align with the change.

Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202501221006.a1ca5dfa-lkp@intel.com
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Link: https://lore.kernel.org/r/20250122043309.304621-1-koichiro.den@canonical.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Koichiro Den and committed by
Bartosz Golaszewski
f8524ac3 b049e7ab

+25 -6
+25 -6
tools/testing/selftests/gpio/gpio-sim.sh
··· 46 46 rmdir $CONFIGFS_DIR/$CHIP || fail "Unable to remove the chip" 47 47 } 48 48 49 - configfs_cleanup() { 50 - for CHIP in `ls $CONFIGFS_DIR/`; do 51 - remove_chip $CHIP 52 - done 53 - } 54 - 55 49 create_chip() { 56 50 local CHIP=$1 57 51 ··· 97 103 local CHIP=$1 98 104 99 105 echo 0 > $CONFIGFS_DIR/$CHIP/live || fail "Unable to disable the chip" 106 + } 107 + 108 + configfs_cleanup() { 109 + for CHIP in `ls $CONFIGFS_DIR/`; do 110 + disable_chip $CHIP 111 + remove_chip $CHIP 112 + done 100 113 } 101 114 102 115 configfs_chip_name() { ··· 182 181 create_bank chip bank 183 182 enable_chip chip 184 183 test -n `cat $CONFIGFS_DIR/chip/bank/chip_name` || fail "chip_name doesn't work" 184 + disable_chip chip 185 185 remove_chip chip 186 186 187 187 echo "1.2. chip_name returns 'none' if the chip is still pending" ··· 197 195 create_bank chip bank 198 196 enable_chip chip 199 197 test -n `cat $CONFIGFS_DIR/chip/dev_name` || fail "dev_name doesn't work" 198 + disable_chip chip 200 199 remove_chip chip 201 200 202 201 echo "2. Creating and configuring simulated chips" ··· 207 204 create_bank chip bank 208 205 enable_chip chip 209 206 test "`get_chip_num_lines chip bank`" = "1" || fail "default number of lines is not 1" 207 + disable_chip chip 210 208 remove_chip chip 211 209 212 210 echo "2.2. Number of lines can be specified" ··· 216 212 set_num_lines chip bank 16 217 213 enable_chip chip 218 214 test "`get_chip_num_lines chip bank`" = "16" || fail "number of lines is not 16" 215 + disable_chip chip 219 216 remove_chip chip 220 217 221 218 echo "2.3. Label can be set" ··· 225 220 set_label chip bank foobar 226 221 enable_chip chip 227 222 test "`get_chip_label chip bank`" = "foobar" || fail "label is incorrect" 223 + disable_chip chip 228 224 remove_chip chip 229 225 230 226 echo "2.4. Label can be left empty" ··· 233 227 create_bank chip bank 234 228 enable_chip chip 235 229 test -z "`cat $CONFIGFS_DIR/chip/bank/label`" || fail "label is not empty" 230 + disable_chip chip 236 231 remove_chip chip 237 232 238 233 echo "2.5. Line names can be configured" ··· 245 238 enable_chip chip 246 239 test "`get_line_name chip bank 0`" = "foo" || fail "line name is incorrect" 247 240 test "`get_line_name chip bank 2`" = "bar" || fail "line name is incorrect" 241 + disable_chip chip 248 242 remove_chip chip 249 243 250 244 echo "2.6. Line config can remain unused if offset is greater than number of lines" ··· 256 248 enable_chip chip 257 249 test "`get_line_name chip bank 0`" = "" || fail "line name is incorrect" 258 250 test "`get_line_name chip bank 1`" = "" || fail "line name is incorrect" 251 + disable_chip chip 259 252 remove_chip chip 260 253 261 254 echo "2.7. Line configfs directory names are sanitized" ··· 276 267 enable_chip $CHIP 277 268 done 278 269 for CHIP in $CHIPS; do 270 + disable_chip $CHIP 279 271 remove_chip $CHIP 280 272 done 281 273 ··· 288 278 fail "Setting label of a live chip should fail" 289 279 echo 8 > $CONFIGFS_DIR/chip/bank/num_lines 2> /dev/null && \ 290 280 fail "Setting number of lines of a live chip should fail" 281 + disable_chip chip 291 282 remove_chip chip 292 283 293 284 echo "2.10. Can't create line items when chip is live" ··· 296 285 create_bank chip bank 297 286 enable_chip chip 298 287 mkdir $CONFIGFS_DIR/chip/bank/line0 2> /dev/null && fail "Creating line item should fail" 288 + disable_chip chip 299 289 remove_chip chip 300 290 301 291 echo "2.11. Probe errors are propagated to user-space" ··· 328 316 enable_chip chip 329 317 $BASE_DIR/gpio-mockup-cdev -s 1 /dev/`configfs_chip_name chip bank` 4 2> /dev/null && \ 330 318 fail "Setting the value of a hogged line shouldn't succeed" 319 + disable_chip chip 331 320 remove_chip chip 332 321 333 322 echo "3. Controlling simulated chips" ··· 344 331 sysfs_set_pull chip bank 0 pull-down 345 332 $BASE_DIR/gpio-mockup-cdev /dev/`configfs_chip_name chip bank` 1 346 333 test "$?" = "0" || fail "pull set incorrectly" 334 + disable_chip chip 347 335 remove_chip chip 348 336 349 337 echo "3.2. Pull can be read from sysfs" ··· 358 344 test `cat $SYSFS_PATH` = "pull-down" || fail "reading the pull failed" 359 345 sysfs_set_pull chip bank 0 pull-up 360 346 test `cat $SYSFS_PATH` = "pull-up" || fail "reading the pull failed" 347 + disable_chip chip 361 348 remove_chip chip 362 349 363 350 echo "3.3. Incorrect input in sysfs is rejected" ··· 370 355 CHIPNAME=`configfs_chip_name chip bank` 371 356 SYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/pull" 372 357 echo foobar > $SYSFS_PATH 2> /dev/null && fail "invalid input not detected" 358 + disable_chip chip 373 359 remove_chip chip 374 360 375 361 echo "3.4. Can't write to value" ··· 381 365 CHIPNAME=`configfs_chip_name chip bank` 382 366 SYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/value" 383 367 echo 1 > $SYSFS_PATH 2> /dev/null && fail "writing to 'value' succeeded unexpectedly" 368 + disable_chip chip 384 369 remove_chip chip 385 370 386 371 echo "4. Simulated GPIO chips are functional" ··· 399 382 sleep 0.1 # FIXME Any better way? 400 383 test `cat $SYSFS_PATH` = "1" || fail "incorrect value read from sysfs" 401 384 kill $! 385 + disable_chip chip 402 386 remove_chip chip 403 387 404 388 echo "4.2. Bias settings work correctly" ··· 412 394 SYSFS_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/value" 413 395 $BASE_DIR/gpio-mockup-cdev -b pull-up /dev/`configfs_chip_name chip bank` 0 414 396 test `cat $SYSFS_PATH` = "1" || fail "bias setting does not work" 397 + disable_chip chip 415 398 remove_chip chip 416 399 417 400 echo "GPIO $MODULE test PASS"