WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / gpio / gpio-mockup-sysfs.sh
blobdd269d877562409e929b3665488a1df64e2cbd56
2 # SPDX-License-Identifier: GPL-2.0
3 is_consistent()
5 val=
7 active_low_sysfs=`cat $GPIO_SYSFS/gpio$nr/active_low`
8 val_sysfs=`cat $GPIO_SYSFS/gpio$nr/value`
9 dir_sysfs=`cat $GPIO_SYSFS/gpio$nr/direction`
11 gpio_this_debugfs=`cat $GPIO_DEBUGFS |grep "gpio-$nr" | sed "s/(.*)//g"`
12 dir_debugfs=`echo $gpio_this_debugfs | awk '{print $2}'`
13 val_debugfs=`echo $gpio_this_debugfs | awk '{print $3}'`
14 if [ $val_debugfs = "lo" ]; then
15 val=0
16 elif [ $val_debugfs = "hi" ]; then
17 val=1
20 if [ $active_low_sysfs = "1" ]; then
21 if [ $val = "0" ]; then
22 val="1"
23 else
24 val="0"
28 if [ $val_sysfs = $val ] && [ $dir_sysfs = $dir_debugfs ]; then
29 echo -n "."
30 else
31 echo "test fail, exit"
32 die
36 test_pin_logic()
38 nr=$1
39 direction=$2
40 active_low=$3
41 value=$4
43 echo $direction > $GPIO_SYSFS/gpio$nr/direction
44 echo $active_low > $GPIO_SYSFS/gpio$nr/active_low
45 if [ $direction = "out" ]; then
46 echo $value > $GPIO_SYSFS/gpio$nr/value
48 is_consistent $nr
51 test_one_pin()
53 nr=$1
55 echo -n "test pin<$nr>"
57 echo $nr > $GPIO_SYSFS/export 2>/dev/null
59 if [ X$? != X0 ]; then
60 echo "test GPIO pin $nr failed"
61 die
64 #"Checking if the sysfs is consistent with debugfs: "
65 is_consistent $nr
67 #"Checking the logic of active_low: "
68 test_pin_logic $nr out 1 1
69 test_pin_logic $nr out 1 0
70 test_pin_logic $nr out 0 1
71 test_pin_logic $nr out 0 0
73 #"Checking the logic of direction: "
74 test_pin_logic $nr in 1 1
75 test_pin_logic $nr out 1 0
76 test_pin_logic $nr low 0 1
77 test_pin_logic $nr high 0 0
79 echo $nr > $GPIO_SYSFS/unexport
81 echo "successful"
84 test_one_pin_fail()
86 nr=$1
88 echo $nr > $GPIO_SYSFS/export 2>/dev/null
90 if [ X$? != X0 ]; then
91 echo "test invalid pin $nr successful"
92 else
93 echo "test invalid pin $nr failed"
94 echo $nr > $GPIO_SYSFS/unexport 2>/dev/null
95 die
99 list_chip()
101 echo `ls -d $GPIO_DRV_SYSFS/gpiochip* 2>/dev/null`
104 test_chip()
106 chip=$1
107 name=`basename $chip`
108 base=`cat $chip/base`
109 ngpio=`cat $chip/ngpio`
110 printf "%-10s %-5s %-5s\n" $name $base $ngpio
111 if [ $ngpio = "0" ]; then
112 echo "number of gpio is zero is not allowed".
114 test_one_pin $base
115 test_one_pin $(($base + $ngpio - 1))
116 test_one_pin $((( RANDOM % $ngpio ) + $base ))
119 test_chips_sysfs()
121 gpiochip=`list_chip $module`
122 if [ X"$gpiochip" = X ]; then
123 if [ X"$valid" = Xfalse ]; then
124 echo "successful"
125 else
126 echo "fail"
129 else
130 for chip in $gpiochip; do
131 test_chip $chip
132 done