2 # SPDX-License-Identifier: GPL-2.0
6 #2: sysfs/debugfs not mount
7 #3: insert module fail when gpio-mockup is a module.
8 #4: Skip test including run as non-root user.
19 # Kselftest framework requirement - SKIP code is 4.
25 echo "$0 [-f] [-m name] [-t type]"
26 echo "-f: full test. It maybe conflict with existence gpio device."
27 echo "-m: module name, default name is gpio-mockup. It could also test"
28 echo " other gpio device."
29 echo "-t: interface type: chardev(char device) and sysfs(being"
30 echo " deprecated). The first one is default"
39 if [ $UID != 0 ]; then
40 echo $msg must be run as root
>&2
43 SYSFS
=`mount -t sysfs | head -1 | awk '{ print $3 }'`
44 if [ ! -d "$SYSFS" ]; then
45 echo $msg sysfs is not mounted
>&2
48 GPIO_SYSFS
=`echo $SYSFS/class/gpio`
49 GPIO_DRV_SYSFS
=`echo $SYSFS/devices/platform/$module/gpio`
50 DEBUGFS
=`mount -t debugfs | head -1 | awk '{ print $3 }'`
51 if [ ! -d "$DEBUGFS" ]; then
52 echo $msg debugfs is not mounted
>&2
55 GPIO_DEBUGFS
=`echo $DEBUGFS/gpio`
56 source gpio-mockup-sysfs.sh
61 if [ -d "$GPIO_DRV_SYSFS" ]; then
62 echo "$GPIO_DRV_SYSFS exist. Skip insert module"
64 modprobe
-q $module $1
65 if [ X$?
!= X0
]; then
66 echo $msg insmod
$module failed
>&2
74 modprobe
-r -q $module
85 if [ X
$dev_type = Xsysfs
]; then
86 echo "WARNING: sysfs ABI of gpio is going to deprecated."
89 $BASE/gpio-mockup-chardev $
*
98 if [ X
"$param" = X
]; then
101 try_insert_module
"gpio_mockup_ranges=$param"
102 echo -n "GPIO $module test with ranges: <"
104 printf "%-10s %s\n" $param
105 test_chips
$module $valid
112 TEMP
=`getopt -o fhm:t: -n '$0' -- "$@"`
114 if [ "$?" != "0" ]; then
115 echo "Parameter process failed, Terminating..." >&2
119 # Note the quotes around `$TEMP': they are essential!
145 echo "Internal error!"
151 if [ X
"$module" = X
]; then
155 if [ X
$dev_type != Xsysfs
]; then
161 echo "1. Test dynamic allocation of gpio successful means insert gpiochip and"
162 echo " manipulate gpio pin successful"
163 gpio_test
"-1,32" true
164 gpio_test
"-1,32,-1,32" true
165 gpio_test
"-1,32,-1,32,-1,32" true
166 if [ X
$full_test = Xtrue
]; then
167 gpio_test
"-1,32,32,64" true
168 gpio_test
"-1,32,40,64,-1,5" true
169 gpio_test
"-1,32,32,64,-1,32" true
170 gpio_test
"0,32,32,64,-1,32,-1,32" true
171 gpio_test
"-1,32,-1,32,0,32,32,64" true
172 echo "2. Do basic test: successful means insert gpiochip and"
173 echo " manipulate gpio pin successful"
174 gpio_test
"0,32" true
175 gpio_test
"0,32,32,64" true
176 gpio_test
"0,32,40,64,64,96" true
178 echo "3. Error test: successful means insert gpiochip failed"
179 echo "3.1 Test number of gpio overflow"
180 #Currently: The max number of gpio(1024) is defined in arm architecture.
181 gpio_test
"-1,32,-1,1024" false
182 if [ X
$full_test = Xtrue
]; then
183 echo "3.2 Test zero line of gpio"
184 gpio_test
"0,0" false
185 echo "3.3 Test range overlap"
186 echo "3.3.1 Test corner case"
187 gpio_test
"0,32,0,1" false
188 gpio_test
"0,32,32,64,32,40" false
189 gpio_test
"0,32,35,64,35,45" false
190 gpio_test
"0,32,31,32" false
191 gpio_test
"0,32,32,64,36,37" false
192 gpio_test
"0,32,35,64,34,36" false
193 echo "3.3.2 Test inserting invalid second gpiochip"
194 gpio_test
"0,32,30,35" false
195 gpio_test
"0,32,1,5" false
196 gpio_test
"10,32,9,14" false
197 gpio_test
"10,32,30,35" false
198 echo "3.3.3 Test others"
199 gpio_test
"0,32,40,56,39,45" false
200 gpio_test
"0,32,40,56,30,33" false
201 gpio_test
"0,32,40,56,30,41" false
202 gpio_test
"0,32,40,56,20,21" false