# once it exits as the COPROC_PID will be cleared.
COPROC_SAVED_PID=""
+GPIOSIM_CHIPS=""
+GPIOSIM_CONFIGFS="/sys/kernel/config/gpio-sim/"
+GPIOSIM_SYSFS="/sys/devices/platform/"
+
# Run the command in $* and return 0 if the command failed. The way we do it
# here is a workaround for the way bats handles failing processes.
assert_fail() {
return 1
}
-# Probe the gpio-mockup kernel module. The routine expects a list of chip
-# sizes and optionally the 'named-lines' flag.
-gpio_mockup_probe() {
- local CMDLINE="gpio_mockup_ranges="
+random_name() {
+ cat /proc/sys/kernel/random/uuid
+}
+
+gpiosim_chip() {
+ local VAR=$1
+ local NAME=$(random_name)
+ local DEVPATH=$GPIOSIM_CONFIGFS/$NAME
+ local BANKPATH=$DEVPATH/$NAME
+
+ mkdir -p $BANKPATH
for ARG in $*
do
- if [ $ARG = "named-lines" ]
+ local KEY=$(echo $ARG | cut -d"=" -f1)
+ local VAL=$(echo $ARG | cut -d"=" -f2)
+
+ if [ "$KEY" = "num_lines" ]
then
- CMDLINE="gpio_mockup_named_lines $CMDLINE"
- continue
+ echo $VAL > $BANKPATH/num_lines
+ elif [ "$KEY" = "line_name" ]
+ then
+ local OFFSET=$(echo $VAL | cut -d":" -f1)
+ local LINENAME=$(echo $VAL | cut -d":" -f2)
+ local LINEPATH=$BANKPATH/line$OFFSET
+
+ mkdir -p $LINEPATH
+ echo $LINENAME > $LINEPATH/name
fi
+ done
- regex_matches "[0-9]+" "$ARG"
+ echo 1 > $DEVPATH/live
- CMDLINE="$CMDLINE-1,$ARG,"
- done
+ GPIOSIM_CHIPS="$VAR:$NAME $GPIOSIM_CHIPS"
+}
+
+gpiosim_chip_map_name() {
+ local VAR=$1
- CMDLINE=${CMDLINE%?}
+ for CHIP in $GPIOSIM_CHIPS
+ do
+ KEY=$(echo $CHIP | cut -d":" -f1)
+ VAL=$(echo $CHIP | cut -d":" -f2)
- modprobe gpio-mockup $CMDLINE
- udevadm settle
+ if [ "$KEY" = "$VAR" ]
+ then
+ echo $VAL
+ fi
+ done
}
-gpio_mockup_remove() {
- if [ -d /sys/module/gpio_mockup ]
- then
- rmmod gpio-mockup
- fi
+gpiosim_chip_name() {
+ local VAR=$1
+ local NAME=$(gpiosim_chip_map_name $VAR)
+
+ cat $GPIOSIM_CONFIGFS/$NAME/$NAME/chip_name
}
-gpio_mockup_chip_name() {
- local CHIPNUM=$1
+gpiosim_dev_name() {
+ local VAR=$1
+ local NAME=$(gpiosim_chip_map_name $VAR)
- test -d /sys/devices/platform/gpio-mockup.$CHIPNUM/ || return 1
- echo $(ls /sys/devices/platform/gpio-mockup.$CHIPNUM/ | grep gpiochip)
+ cat $GPIOSIM_CONFIGFS/$NAME/dev_name
}
-gpio_mockup_set_pull() {
- local CHIPNUM=$1
- local LINE=$2
+gpiosim_set_pull() {
+ local VAR=$1
+ local OFFSET=$2
local PULL=$3
+ local DEVNAME=$(gpiosim_dev_name $VAR)
+ local CHIPNAME=$(gpiosim_chip_name $VAR)
- FILE="/sys/kernel/debug/gpio-mockup/$(gpio_mockup_chip_name $CHIPNUM)/$LINE"
- test -f $FILE || return 1
- echo "$PULL" > $FILE
+ echo $PULL > $GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/pull
}
-gpio_mockup_check_value() {
- local CHIPNUM=$1
- local LINE=$2
+gpiosim_check_value() {
+ local VAR=$1
+ local OFFSET=$2
local EXPECTED=$3
+ local DEVNAME=$(gpiosim_dev_name $VAR)
+ local CHIPNAME=$(gpiosim_chip_name $VAR)
- FILE="/sys/kernel/debug/gpio-mockup/$(gpio_mockup_chip_name $CHIPNUM)/$LINE"
- test -f $FILE || return 1
+ VAL=$(cat $GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/value)
+ if [ "$VAL" = "$EXPECTED" ]
+ then
+ return 0
+ fi
- VAL=$(cat $FILE)
- test $VAL -eq $EXPECTED || return 1
+ return 1
+}
+
+gpiosim_cleanup() {
+ for CHIP in $GPIOSIM_CHIPS
+ do
+ local NAME=$(echo $CHIP | cut -d":" -f2)
+
+ local DEVPATH=$GPIOSIM_CONFIGFS/$NAME
+ local BANKPATH=$DEVPATH/$NAME
+
+ echo 0 > $DEVPATH/live
+
+ ls $BANKPATH/line* 2> /dev/null
+ if [ "$?" = "0" ]
+ then
+ for LINE in $(find $BANKPATH/ | egrep "line[0-9]+$")
+ do
+ test -e $LINE/hog && rmdir $LINE/hog
+ rmdir $LINE
+ done
+ fi
+
+ rmdir $BANKPATH
+ rmdir $DEVPATH
+ done
+
+ GPIOSIM_CHIPS=""
}
run_tool() {
rm -f $COPROC_OUTPUT
}
-setup() {
- gpio_mockup_remove
-}
-
teardown() {
if [ -n "$BG_PROC_PID" ]
then
BG_PROC_PID=""
fi
- gpio_mockup_remove
+ gpiosim_cleanup
}
#
#
@test "gpiodetect: list chips" {
- gpio_mockup_probe 4 8 16
+ gpiosim_chip sim0 num_lines=4
+ gpiosim_chip sim1 num_lines=8
+ gpiosim_chip sim2 num_lines=16
run_tool gpiodetect
test "$status" -eq 0
- output_contains_line "$(gpio_mockup_chip_name 0) [gpio-mockup-A] (4 lines)"
- output_contains_line "$(gpio_mockup_chip_name 1) [gpio-mockup-B] (8 lines)"
- output_contains_line "$(gpio_mockup_chip_name 2) [gpio-mockup-C] (16 lines)"
+ output_contains_line "$(gpiosim_chip_name sim0) [$(gpiosim_dev_name sim0)-node0] (4 lines)"
+ output_contains_line "$(gpiosim_chip_name sim1) [$(gpiosim_dev_name sim1)-node0] (8 lines)"
+ output_contains_line "$(gpiosim_chip_name sim2) [$(gpiosim_dev_name sim2)-node0] (16 lines)"
}
@test "gpiodetect: invalid args" {
#
@test "gpioinfo: dump all chips" {
- gpio_mockup_probe 4 8
+ gpiosim_chip sim0 num_lines=4
+ gpiosim_chip sim1 num_lines=8
run_tool gpioinfo
test "$status" -eq 0
- output_contains_line "$(gpio_mockup_chip_name 0) - 4 lines:"
- output_contains_line "$(gpio_mockup_chip_name 1) - 8 lines:"
+ output_contains_line "$(gpiosim_chip_name sim0) - 4 lines:"
+ output_contains_line "$(gpiosim_chip_name sim1) - 8 lines:"
output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+input\\s+active-high"
output_regex_match "\\s+line\\s+7:\\s+unnamed\\s+unused\\s+input\\s+active-high"
}
@test "gpioinfo: dump all chips with one line exported" {
- gpio_mockup_probe 4 8
+ gpiosim_chip sim0 num_lines=4
+ gpiosim_chip sim1 num_lines=8
- coproc_run_tool gpioset --mode=signal --active-low "$(gpio_mockup_chip_name 1)" 7=1
+ coproc_run_tool gpioset --mode=signal --active-low "$(gpiosim_chip_name sim1)" 7=1
run_tool gpioinfo
test "$status" -eq 0
- output_contains_line "$(gpio_mockup_chip_name 0) - 4 lines:"
- output_contains_line "$(gpio_mockup_chip_name 1) - 8 lines:"
+ output_contains_line "$(gpiosim_chip_name sim0) - 4 lines:"
+ output_contains_line "$(gpiosim_chip_name sim1) - 8 lines:"
output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+input\\s+active-high"
output_regex_match "\\s+line\\s+7:\\s+unnamed\\s+\\\"gpioset\\\"\\s+output\\s+active-low"
}
@test "gpioinfo: dump one chip" {
- gpio_mockup_probe 8 4
+ gpiosim_chip sim0 num_lines=8
+ gpiosim_chip sim1 num_lines=4
- run_tool gpioinfo "$(gpio_mockup_chip_name 1)"
+ run_tool gpioinfo "$(gpiosim_chip_name sim1)"
test "$status" -eq 0
- assert_fail output_contains_line "$(gpio_mockup_chip_name 0) - 8 lines:"
- output_contains_line "$(gpio_mockup_chip_name 1) - 4 lines:"
+ assert_fail output_contains_line "$(gpiosim_chip_name sim0) - 8 lines:"
+ output_contains_line "$(gpiosim_chip_name sim1) - 4 lines:"
output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+input\\s+active-high"
assert_fail output_regex_match "\\s+line\\s+7:\\s+unnamed\\s+unused\\s+input\\s+active-high"
}
@test "gpioinfo: dump all but one chip" {
- gpio_mockup_probe 4 4 8 4
+ gpiosim_chip sim0 num_lines=4
+ gpiosim_chip sim1 num_lines=4
+ gpiosim_chip sim2 num_lines=8
+ gpiosim_chip sim3 num_lines=4
- run_tool gpioinfo "$(gpio_mockup_chip_name 0)" \
- "$(gpio_mockup_chip_name 1)" "$(gpio_mockup_chip_name 3)"
+ run_tool gpioinfo "$(gpiosim_chip_name sim0)" \
+ "$(gpiosim_chip_name sim1)" "$(gpiosim_chip_name sim3)"
test "$status" -eq 0
- output_contains_line "$(gpio_mockup_chip_name 0) - 4 lines:"
- output_contains_line "$(gpio_mockup_chip_name 1) - 4 lines:"
- assert_fail output_contains_line "$(gpio_mockup_chip_name 2) - 8 lines:"
- output_contains_line "$(gpio_mockup_chip_name 3) - 4 lines:"
+ output_contains_line "$(gpiosim_chip_name sim0) - 4 lines:"
+ output_contains_line "$(gpiosim_chip_name sim1) - 4 lines:"
+ assert_fail output_contains_line "$(gpiosim_chip_name sim2) - 8 lines:"
+ output_contains_line "$(gpiosim_chip_name sim3) - 4 lines:"
output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+input\\s+active-high"
assert_fail output_regex_match "\\s+line\\s+7:\\s+unnamed\\s+unused\\s+input\\s+active-high"
}
#
@test "gpiofind: line found" {
- gpio_mockup_probe named-lines 4 8 16
+ gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=3:bar
+ gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz line_name=7:foobar
+ gpiosim_chip sim2 num_lines=16
- run_tool gpiofind gpio-mockup-B-7
+ run_tool gpiofind foobar
test "$status" -eq "0"
- test "$output" = "$(gpio_mockup_chip_name 1) 7"
+ test "$output" = "$(gpiosim_chip_name sim1) 7"
}
@test "gpiofind: line not found" {
- gpio_mockup_probe named-lines 4 8 16
+ gpiosim_chip sim0 num_lines=4
+ gpiosim_chip sim1 num_lines=8
+ gpiosim_chip sim2 num_lines=16
run_tool gpiofind nonexistent-line
#
@test "gpioget: read all lines" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 3 1
- gpio_mockup_set_pull 1 5 1
- gpio_mockup_set_pull 1 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- run_tool gpioget "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7
+ run_tool gpioget "$(gpiosim_chip_name sim0)" 0 1 2 3 4 5 6 7
test "$status" -eq "0"
test "$output" = "0 0 1 1 0 1 0 1"
}
@test "gpioget: read all lines (active-low)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 3 1
- gpio_mockup_set_pull 1 5 1
- gpio_mockup_set_pull 1 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- run_tool gpioget --active-low "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7
+ run_tool gpioget --active-low "$(gpiosim_chip_name sim0)" 0 1 2 3 4 5 6 7
test "$status" -eq "0"
test "$output" = "1 1 0 0 1 0 1 0"
}
@test "gpioget: read all lines (pull-up)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 3 1
- gpio_mockup_set_pull 1 5 1
- gpio_mockup_set_pull 1 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- run_tool gpioget --bias=pull-up "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7
+ run_tool gpioget --bias=pull-up "$(gpiosim_chip_name sim0)" 0 1 2 3 4 5 6 7
test "$status" -eq "0"
test "$output" = "1 1 1 1 1 1 1 1"
}
@test "gpioget: read all lines (pull-down)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 3 1
- gpio_mockup_set_pull 1 5 1
- gpio_mockup_set_pull 1 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- run_tool gpioget --bias=pull-down "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7
+ run_tool gpioget --bias=pull-down "$(gpiosim_chip_name sim0)" 0 1 2 3 4 5 6 7
test "$status" -eq "0"
test "$output" = "0 0 0 0 0 0 0 0"
}
@test "gpioget: read some lines" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 1 1
- gpio_mockup_set_pull 1 4 1
- gpio_mockup_set_pull 1 6 1
+ gpiosim_set_pull sim0 1 pull-up
+ gpiosim_set_pull sim0 4 pull-up
+ gpiosim_set_pull sim0 6 pull-up
- run_tool gpioget "$(gpio_mockup_chip_name 1)" 0 1 4 6
+ run_tool gpioget "$(gpiosim_chip_name sim0)" 0 1 4 6
test "$status" -eq "0"
test "$output" = "0 1 1 1"
}
@test "gpioget: no lines specified" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioget "$(gpio_mockup_chip_name 1)"
+ run_tool gpioget "$(gpiosim_chip_name sim0)"
test "$status" -eq "1"
output_regex_match ".*at least one GPIO line offset must be specified"
}
@test "gpioget: too many lines specified" {
- gpio_mockup_probe 4
+ gpiosim_chip sim0 num_lines=4
- run_tool gpioget "$(gpio_mockup_chip_name 1)" 0 1 2 3 4
+ run_tool gpioget "$(gpiosim_chip_name sim0)" 0 1 2 3 4
test "$status" -eq "1"
output_regex_match ".*unable to retrieve GPIO lines from chip"
}
@test "gpioget: same line twice" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioget "$(gpio_mockup_chip_name 1)" 0 0
+ run_tool gpioget "$(gpiosim_chip_name sim0)" 0 0
test "$status" -eq "1"
output_regex_match ".*unable to request lines.*"
}
@test "gpioget: invalid bias" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioget --bias=bad "$(gpio_mockup_chip_name 1)" 0 1
+ run_tool gpioget --bias=bad "$(gpiosim_chip_name sim0)" 0 1
test "$status" -eq "1"
output_regex_match ".*invalid bias.*"
#
@test "gpioset: set lines and wait for SIGTERM" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpioset --mode=signal "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --mode=signal "$(gpiosim_chip_name sim0)" \
0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 0 0
- gpio_mockup_check_value 2 1 0
- gpio_mockup_check_value 2 2 1
- gpio_mockup_check_value 2 3 1
- gpio_mockup_check_value 2 4 1
- gpio_mockup_check_value 2 5 1
- gpio_mockup_check_value 2 6 0
- gpio_mockup_check_value 2 7 1
+ gpiosim_check_value sim0 0 0
+ gpiosim_check_value sim0 1 0
+ gpiosim_check_value sim0 2 1
+ gpiosim_check_value sim0 3 1
+ gpiosim_check_value sim0 4 1
+ gpiosim_check_value sim0 5 1
+ gpiosim_check_value sim0 6 0
+ gpiosim_check_value sim0 7 1
coproc_tool_kill
coproc_tool_wait
}
@test "gpioset: set lines and wait for SIGTERM (active-low)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpioset --active-low --mode=signal "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --active-low --mode=signal "$(gpiosim_chip_name sim0)" \
0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 0 1
- gpio_mockup_check_value 2 1 1
- gpio_mockup_check_value 2 2 0
- gpio_mockup_check_value 2 3 0
- gpio_mockup_check_value 2 4 0
- gpio_mockup_check_value 2 5 0
- gpio_mockup_check_value 2 6 1
- gpio_mockup_check_value 2 7 0
+ gpiosim_check_value sim0 0 1
+ gpiosim_check_value sim0 1 1
+ gpiosim_check_value sim0 2 0
+ gpiosim_check_value sim0 3 0
+ gpiosim_check_value sim0 4 0
+ gpiosim_check_value sim0 5 0
+ gpiosim_check_value sim0 6 1
+ gpiosim_check_value sim0 7 0
coproc_tool_kill
coproc_tool_wait
}
@test "gpioset: set lines and wait for SIGTERM (push-pull)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpioset --drive=push-pull --mode=signal "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --drive=push-pull --mode=signal "$(gpiosim_chip_name sim0)" \
0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 0 0
- gpio_mockup_check_value 2 1 0
- gpio_mockup_check_value 2 2 1
- gpio_mockup_check_value 2 3 1
- gpio_mockup_check_value 2 4 1
- gpio_mockup_check_value 2 5 1
- gpio_mockup_check_value 2 6 0
- gpio_mockup_check_value 2 7 1
+ gpiosim_check_value sim0 0 0
+ gpiosim_check_value sim0 1 0
+ gpiosim_check_value sim0 2 1
+ gpiosim_check_value sim0 3 1
+ gpiosim_check_value sim0 4 1
+ gpiosim_check_value sim0 5 1
+ gpiosim_check_value sim0 6 0
+ gpiosim_check_value sim0 7 1
coproc_tool_kill
coproc_tool_wait
}
@test "gpioset: set lines and wait for SIGTERM (open-drain)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 2 2 1
- gpio_mockup_set_pull 2 3 1
- gpio_mockup_set_pull 2 5 1
- gpio_mockup_set_pull 2 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- coproc_run_tool gpioset --drive=open-drain --mode=signal "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --drive=open-drain --mode=signal "$(gpiosim_chip_name sim0)" \
0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 0 0
- gpio_mockup_check_value 2 1 0
- gpio_mockup_check_value 2 2 1
- gpio_mockup_check_value 2 3 1
- gpio_mockup_check_value 2 4 0
- gpio_mockup_check_value 2 5 1
- gpio_mockup_check_value 2 6 0
- gpio_mockup_check_value 2 7 1
+ gpiosim_check_value sim0 0 0
+ gpiosim_check_value sim0 1 0
+ gpiosim_check_value sim0 2 1
+ gpiosim_check_value sim0 3 1
+ gpiosim_check_value sim0 4 0
+ gpiosim_check_value sim0 5 1
+ gpiosim_check_value sim0 6 0
+ gpiosim_check_value sim0 7 1
coproc_tool_kill
coproc_tool_wait
}
@test "gpioset: set lines and wait for SIGTERM (open-source)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 2 2 1
- gpio_mockup_set_pull 2 3 1
- gpio_mockup_set_pull 2 5 1
- gpio_mockup_set_pull 2 7 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 5 pull-up
+ gpiosim_set_pull sim0 7 pull-up
- coproc_run_tool gpioset --drive=open-source --mode=signal "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --drive=open-source --mode=signal "$(gpiosim_chip_name sim0)" \
0=0 1=0 2=1 3=0 4=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 0 0
- gpio_mockup_check_value 2 1 0
- gpio_mockup_check_value 2 2 1
- gpio_mockup_check_value 2 3 1
- gpio_mockup_check_value 2 4 1
- gpio_mockup_check_value 2 5 1
- gpio_mockup_check_value 2 6 0
- gpio_mockup_check_value 2 7 1
+ gpiosim_check_value sim0 0 0
+ gpiosim_check_value sim0 1 0
+ gpiosim_check_value sim0 2 1
+ gpiosim_check_value sim0 3 1
+ gpiosim_check_value sim0 4 1
+ gpiosim_check_value sim0 5 1
+ gpiosim_check_value sim0 6 0
+ gpiosim_check_value sim0 7 1
coproc_tool_kill
coproc_tool_wait
}
@test "gpioset: set some lines and wait for ENTER" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpioset --mode=wait "$(gpio_mockup_chip_name 2)" \
+ coproc_run_tool gpioset --mode=wait "$(gpiosim_chip_name sim0)" \
1=0 2=1 5=1 6=0 7=1
- gpio_mockup_check_value 2 1 0
- gpio_mockup_check_value 2 2 1
- gpio_mockup_check_value 2 5 1
- gpio_mockup_check_value 2 6 0
- gpio_mockup_check_value 2 7 1
+ gpiosim_check_value sim0 1 0
+ gpiosim_check_value sim0 2 1
+ gpiosim_check_value sim0 5 1
+ gpiosim_check_value sim0 6 0
+ gpiosim_check_value sim0 7 1
coproc_tool_stdin_write ""
coproc_tool_wait
}
@test "gpioset: set some lines and wait for SIGINT" {
- gpio_mockup_probe 8
+ gpiosim_chip sim0 num_lines=4
- coproc_run_tool gpioset --mode=signal "$(gpio_mockup_chip_name 0)" 0=1
+ coproc_run_tool gpioset --mode=signal "$(gpiosim_chip_name sim0)" 0=1
- gpio_mockup_check_value 0 0 1
+ gpiosim_check_value sim0 0 1
coproc_tool_kill -SIGINT
coproc_tool_wait
}
@test "gpioset: set some lines and wait with --mode=time" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
coproc_run_tool gpioset --mode=time --sec=1 --usec=200000 \
- "$(gpio_mockup_chip_name 1)" 0=1 5=0 7=1
+ "$(gpiosim_chip_name sim0)" 0=1 5=0 7=1
- gpio_mockup_check_value 1 0 1
- gpio_mockup_check_value 1 5 0
- gpio_mockup_check_value 1 7 1
+ gpiosim_check_value sim0 0 1
+ gpiosim_check_value sim0 5 0
+ gpiosim_check_value sim0 7 1
coproc_tool_wait
}
@test "gpioset: no lines specified" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)"
+ run_tool gpioset "$(gpiosim_chip_name sim1)"
test "$status" -eq "1"
output_regex_match ".*at least one GPIO line offset to value mapping must be specified"
}
@test "gpioset: too many lines specified" {
- gpio_mockup_probe 4
+ gpiosim_chip sim0 num_lines=4
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=1 1=1 2=1 3=1 4=1 5=1
+ run_tool gpioset "$(gpiosim_chip_name sim0)" 0=1 1=1 2=1 3=1 4=1 5=1
test "$status" -eq "1"
output_regex_match ".*unable to retrieve GPIO lines from chip"
}
@test "gpioset: use --sec without --mode=time" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset --mode=exit --sec=1 "$(gpio_mockup_chip_name 1)" 0=1
+ run_tool gpioset --mode=exit --sec=1 "$(gpiosim_chip_name sim0)" 0=1
test "$status" -eq "1"
output_regex_match ".*can't specify wait time in this mode"
}
@test "gpioset: use --usec without --mode=time" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset --mode=exit --usec=1 "$(gpio_mockup_chip_name 1)" 0=1
+ run_tool gpioset --mode=exit --usec=1 "$(gpiosim_chip_name sim1)" 0=1
test "$status" -eq "1"
output_regex_match ".*can't specify wait time in this mode"
}
@test "gpioset: default mode" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=1
+ run_tool gpioset "$(gpiosim_chip_name sim0)" 0=1
test "$status" -eq "0"
}
@test "gpioset: invalid mapping" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=c
+ run_tool gpioset "$(gpiosim_chip_name sim1)" 0=c
test "$status" -eq "1"
output_regex_match ".*invalid offset<->value mapping"
}
@test "gpioset: invalid value" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=3
+ run_tool gpioset "$(gpiosim_chip_name sim1)" 0=3
test "$status" -eq "1"
output_regex_match ".*value must be 0 or 1"
}
@test "gpioset: invalid offset" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 4000000000=0
+ run_tool gpioset "$(gpiosim_chip_name sim1)" 4000000000=0
test "$status" -eq "1"
output_regex_match ".*invalid offset"
}
@test "gpioset: invalid bias" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset --bias=bad "$(gpio_mockup_chip_name 1)" 0=1 1=1
+ run_tool gpioset --bias=bad "$(gpiosim_chip_name sim1)" 0=1 1=1
test "$status" -eq "1"
output_regex_match ".*invalid bias.*"
}
@test "gpioset: invalid drive" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset --drive=bad "$(gpio_mockup_chip_name 1)" 0=1 1=1
+ run_tool gpioset --drive=bad "$(gpiosim_chip_name sim1)" 0=1 1=1
test "$status" -eq "1"
output_regex_match ".*invalid drive.*"
}
@test "gpioset: daemonize in invalid mode" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset --background "$(gpio_mockup_chip_name 1)" 0=1
+ run_tool gpioset --background "$(gpiosim_chip_name sim1)" 0=1
test "$status" -eq "1"
output_regex_match ".*can't daemonize in this mode"
}
@test "gpioset: same line twice" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpioset "$(gpio_mockup_chip_name 1)" 0=1 0=1
+ run_tool gpioset "$(gpiosim_chip_name sim0)" 0=1 0=1
test "$status" -eq "1"
output_regex_match ".*unable to request lines.*"
#
@test "gpiomon: single rising edge event" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --rising-edge "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --rising-edge "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: single falling edge event" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --falling-edge "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --falling-edge "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-up
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: single falling edge event (pull-up)" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
- coproc_run_tool gpiomon --bias=pull-up "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --bias=pull-up "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: single rising edge event (pull-down)" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
- coproc_run_tool gpiomon --bias=pull-down "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --bias=pull-down "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: single rising edge event (active-low)" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
- coproc_run_tool gpiomon --rising-edge --active-low "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --rising-edge --active-low "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: single rising edge event (silent mode)" {
- gpio_mockup_probe 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --rising-edge --silent "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --rising-edge --silent "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: four alternating events" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --num-events=4 "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --num-events=4 "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
coproc_tool_wait
}
@test "gpiomon: exit after SIGINT" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "$(gpiosim_chip_name sim0)" 4
coproc_tool_kill -SIGINT
coproc_tool_wait
}
@test "gpiomon: exit after SIGTERM" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "$(gpiosim_chip_name sim0)" 4
coproc_tool_kill -SIGTERM
coproc_tool_wait
}
@test "gpiomon: both event flags" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --falling-edge --rising-edge "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon --falling-edge --rising-edge "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
- gpio_mockup_set_pull 1 4 0
+ gpiosim_set_pull sim0 4 pull-down
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: watch multiple lines" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --format=%o "$(gpio_mockup_chip_name 1)" 1 2 3 4 5
+ coproc_run_tool gpiomon --format=%o "$(gpiosim_chip_name sim0)" 1 2 3 4 5
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 3 1
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 3 pull-up
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: watch multiple lines (lines in mixed-up order)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon --format=%o "$(gpio_mockup_chip_name 1)" 5 2 7 1 6
+ coproc_run_tool gpiomon --format=%o "$(gpiosim_chip_name sim0)" 5 2 7 1 6
- gpio_mockup_set_pull 1 2 1
- gpio_mockup_set_pull 1 1 1
- gpio_mockup_set_pull 1 6 1
+ gpiosim_set_pull sim0 2 pull-up
+ gpiosim_set_pull sim0 1 pull-up
+ gpiosim_set_pull sim0 6 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: same line twice" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpiomon "$(gpio_mockup_chip_name 1)" 0 0
+ run_tool gpiomon "$(gpiosim_chip_name sim0)" 0 0
test "$status" -eq "1"
output_regex_match ".*unable to request GPIO lines for events"
}
@test "gpiomon: line not specified" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpiomon "$(gpio_mockup_chip_name 1)"
+ run_tool gpiomon "$(gpiosim_chip_name sim0)"
test "$status" -eq "1"
output_regex_match ".*GPIO line offset must be specified"
}
@test "gpiomon: line out of range" {
- gpio_mockup_probe 4
+ gpiosim_chip sim0 num_lines=4
- run_tool gpiomon "$(gpio_mockup_chip_name 0)" 5
+ run_tool gpiomon "$(gpiosim_chip_name sim0)" 5
test "$status" -eq "1"
output_regex_match ".*unable to retrieve GPIO lines from chip"
}
@test "gpiomon: invalid bias" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- run_tool gpiomon --bias=bad "$(gpio_mockup_chip_name 1)" 0 1
+ run_tool gpiomon --bias=bad "$(gpiosim_chip_name sim0)" 0 1
test "$status" -eq "1"
output_regex_match ".*invalid bias.*"
}
@test "gpiomon: custom format (event type + offset)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%e %o" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%e %o" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (event type + offset joined)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%e%o" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%e%o" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (timestamp)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%e %o %s.%n" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%e %o %s.%n" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (double percent sign)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%%" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%%" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (double percent sign + event type specifier)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%%e" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%%e" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (single percent sign)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (single percent sign between other characters)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=foo % bar" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=foo % bar" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill
}
@test "gpiomon: custom format (unknown specifier)" {
- gpio_mockup_probe 8 8 8
+ gpiosim_chip sim0 num_lines=8
- coproc_run_tool gpiomon "--format=%x" "$(gpio_mockup_chip_name 1)" 4
+ coproc_run_tool gpiomon "--format=%x" "$(gpiosim_chip_name sim0)" 4
- gpio_mockup_set_pull 1 4 1
+ gpiosim_set_pull sim0 4 pull-up
sleep 0.2
coproc_tool_kill