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