WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / gpio / gpio-mockup.sh
blob7f35b9880485648eaa9a8709b88c3b06fa88adab
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 #exit status
5 #1: Internal error
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.
9 #5: other reason.
11 SYSFS=
12 GPIO_SYSFS=
13 GPIO_DRV_SYSFS=
14 DEBUGFS=
15 GPIO_DEBUGFS=
16 dev_type=
17 module=
19 # Kselftest framework requirement - SKIP code is 4.
20 ksft_skip=4
22 usage()
24 echo "Usage:"
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"
31 echo ""
32 echo "$0 -h"
33 echo "This usage"
36 prerequisite()
38 msg="skip all tests:"
39 if [ $UID != 0 ]; then
40 echo $msg must be run as root >&2
41 exit $ksft_skip
43 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
44 if [ ! -d "$SYSFS" ]; then
45 echo $msg sysfs is not mounted >&2
46 exit 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
53 exit 2
55 GPIO_DEBUGFS=`echo $DEBUGFS/gpio`
56 source gpio-mockup-sysfs.sh
59 try_insert_module()
61 if [ -d "$GPIO_DRV_SYSFS" ]; then
62 echo "$GPIO_DRV_SYSFS exist. Skip insert module"
63 else
64 modprobe -q $module $1
65 if [ X$? != X0 ]; then
66 echo $msg insmod $module failed >&2
67 exit 3
72 remove_module()
74 modprobe -r -q $module
77 die()
79 remove_module
80 exit 5
83 test_chips()
85 if [ X$dev_type = Xsysfs ]; then
86 echo "WARNING: sysfs ABI of gpio is going to deprecated."
87 test_chips_sysfs $*
88 else
89 $BASE/gpio-mockup-chardev $*
93 gpio_test()
95 param=$1
96 valid=$2
98 if [ X"$param" = X ]; then
99 die
101 try_insert_module "gpio_mockup_ranges=$param"
102 echo -n "GPIO $module test with ranges: <"
103 echo "$param>: "
104 printf "%-10s %s\n" $param
105 test_chips $module $valid
106 remove_module
109 BASE=`dirname $0`
111 dev_type=
112 TEMP=`getopt -o fhm:t: -n '$0' -- "$@"`
114 if [ "$?" != "0" ]; then
115 echo "Parameter process failed, Terminating..." >&2
116 exit 1
119 # Note the quotes around `$TEMP': they are essential!
120 eval set -- "$TEMP"
122 while true; do
123 case $1 in
125 full_test=true
126 shift
129 usage
130 exit
133 module=$2
134 shift 2
137 dev_type=$2
138 shift 2
141 shift
142 break
145 echo "Internal error!"
146 exit 1
148 esac
149 done
151 if [ X"$module" = X ]; then
152 module="gpio-mockup"
155 if [ X$dev_type != Xsysfs ]; then
156 dev_type="chardev"
159 prerequisite
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
205 echo GPIO test PASS