Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1
2is_consistent()
3{
4 val=
5
6 active_low_sysfs=`cat $GPIO_SYSFS/gpio$nr/active_low`
7 val_sysfs=`cat $GPIO_SYSFS/gpio$nr/value`
8 dir_sysfs=`cat $GPIO_SYSFS/gpio$nr/direction`
9
10 gpio_this_debugfs=`cat $GPIO_DEBUGFS |grep "gpio-$nr" | sed "s/(.*)//g"`
11 dir_debugfs=`echo $gpio_this_debugfs | awk '{print $2}'`
12 val_debugfs=`echo $gpio_this_debugfs | awk '{print $3}'`
13 if [ $val_debugfs = "lo" ]; then
14 val=0
15 elif [ $val_debugfs = "hi" ]; then
16 val=1
17 fi
18
19 if [ $active_low_sysfs = "1" ]; then
20 if [ $val = "0" ]; then
21 val="1"
22 else
23 val="0"
24 fi
25 fi
26
27 if [ $val_sysfs = $val ] && [ $dir_sysfs = $dir_debugfs ]; then
28 echo -n "."
29 else
30 echo "test fail, exit"
31 die
32 fi
33}
34
35test_pin_logic()
36{
37 nr=$1
38 direction=$2
39 active_low=$3
40 value=$4
41
42 echo $direction > $GPIO_SYSFS/gpio$nr/direction
43 echo $active_low > $GPIO_SYSFS/gpio$nr/active_low
44 if [ $direction = "out" ]; then
45 echo $value > $GPIO_SYSFS/gpio$nr/value
46 fi
47 is_consistent $nr
48}
49
50test_one_pin()
51{
52 nr=$1
53
54 echo -n "test pin<$nr>"
55
56 echo $nr > $GPIO_SYSFS/export 2>/dev/null
57
58 if [ X$? != X0 ]; then
59 echo "test GPIO pin $nr failed"
60 die
61 fi
62
63 #"Checking if the sysfs is consistent with debugfs: "
64 is_consistent $nr
65
66 #"Checking the logic of active_low: "
67 test_pin_logic $nr out 1 1
68 test_pin_logic $nr out 1 0
69 test_pin_logic $nr out 0 1
70 test_pin_logic $nr out 0 0
71
72 #"Checking the logic of direction: "
73 test_pin_logic $nr in 1 1
74 test_pin_logic $nr out 1 0
75 test_pin_logic $nr low 0 1
76 test_pin_logic $nr high 0 0
77
78 echo $nr > $GPIO_SYSFS/unexport
79
80 echo "successful"
81}
82
83test_one_pin_fail()
84{
85 nr=$1
86
87 echo $nr > $GPIO_SYSFS/export 2>/dev/null
88
89 if [ X$? != X0 ]; then
90 echo "test invalid pin $nr successful"
91 else
92 echo "test invalid pin $nr failed"
93 echo $nr > $GPIO_SYSFS/unexport 2>/dev/null
94 die
95 fi
96}
97
98list_chip()
99{
100 echo `ls -d $GPIO_DRV_SYSFS/gpiochip* 2>/dev/null`
101}
102
103test_chip()
104{
105 chip=$1
106 name=`basename $chip`
107 base=`cat $chip/base`
108 ngpio=`cat $chip/ngpio`
109 printf "%-10s %-5s %-5s\n" $name $base $ngpio
110 if [ $ngpio = "0" ]; then
111 echo "number of gpio is zero is not allowed".
112 fi
113 test_one_pin $base
114 test_one_pin $(($base + $ngpio - 1))
115 test_one_pin $((( RANDOM % $ngpio ) + $base ))
116}
117
118test_chips_sysfs()
119{
120 gpiochip=`list_chip $module`
121 if [ X"$gpiochip" = X ]; then
122 if [ X"$valid" = Xfalse ]; then
123 echo "successful"
124 else
125 echo "fail"
126 die
127 fi
128 else
129 for chip in $gpiochip; do
130 test_chip $chip
131 done
132 fi
133}
134