@@ -46,12 +46,6 @@ remove_chip() {
4646 rmdir $CONFIGFS_DIR /$CHIP || fail " Unable to remove the chip"
4747}
4848
49- configfs_cleanup () {
50- for CHIP in ` ls $CONFIGFS_DIR /` ; do
51- remove_chip $CHIP
52- done
53- }
54-
5549create_chip () {
5650 local CHIP=$1
5751
@@ -105,6 +99,13 @@ disable_chip() {
10599 echo 0 > $CONFIGFS_DIR /$CHIP /live || fail " Unable to disable the chip"
106100}
107101
102+ configfs_cleanup () {
103+ for CHIP in ` ls $CONFIGFS_DIR /` ; do
104+ disable_chip $CHIP
105+ remove_chip $CHIP
106+ done
107+ }
108+
108109configfs_chip_name () {
109110 local CHIP=$1
110111 local BANK=$2
@@ -181,6 +182,7 @@ create_chip chip
181182create_bank chip bank
182183enable_chip chip
183184test -n ` cat $CONFIGFS_DIR /chip/bank/chip_name` || fail " chip_name doesn't work"
185+ disable_chip chip
184186remove_chip chip
185187
186188echo " 1.2. chip_name returns 'none' if the chip is still pending"
@@ -195,6 +197,7 @@ create_chip chip
195197create_bank chip bank
196198enable_chip chip
197199test -n ` cat $CONFIGFS_DIR /chip/dev_name` || fail " dev_name doesn't work"
200+ disable_chip chip
198201remove_chip chip
199202
200203echo " 2. Creating and configuring simulated chips"
@@ -204,6 +207,7 @@ create_chip chip
204207create_bank chip bank
205208enable_chip chip
206209test " ` get_chip_num_lines chip bank` " = " 1" || fail " default number of lines is not 1"
210+ disable_chip chip
207211remove_chip chip
208212
209213echo " 2.2. Number of lines can be specified"
@@ -212,6 +216,7 @@ create_bank chip bank
212216set_num_lines chip bank 16
213217enable_chip chip
214218test " ` get_chip_num_lines chip bank` " = " 16" || fail " number of lines is not 16"
219+ disable_chip chip
215220remove_chip chip
216221
217222echo " 2.3. Label can be set"
@@ -220,13 +225,15 @@ create_bank chip bank
220225set_label chip bank foobar
221226enable_chip chip
222227test " ` get_chip_label chip bank` " = " foobar" || fail " label is incorrect"
228+ disable_chip chip
223229remove_chip chip
224230
225231echo " 2.4. Label can be left empty"
226232create_chip chip
227233create_bank chip bank
228234enable_chip chip
229235test -z " ` cat $CONFIGFS_DIR /chip/bank/label` " || fail " label is not empty"
236+ disable_chip chip
230237remove_chip chip
231238
232239echo " 2.5. Line names can be configured"
@@ -238,6 +245,7 @@ set_line_name chip bank 2 bar
238245enable_chip chip
239246test " ` get_line_name chip bank 0` " = " foo" || fail " line name is incorrect"
240247test " ` get_line_name chip bank 2` " = " bar" || fail " line name is incorrect"
248+ disable_chip chip
241249remove_chip chip
242250
243251echo " 2.6. Line config can remain unused if offset is greater than number of lines"
@@ -248,6 +256,7 @@ set_line_name chip bank 5 foobar
248256enable_chip chip
249257test " ` get_line_name chip bank 0` " = " " || fail " line name is incorrect"
250258test " ` get_line_name chip bank 1` " = " " || fail " line name is incorrect"
259+ disable_chip chip
251260remove_chip chip
252261
253262echo " 2.7. Line configfs directory names are sanitized"
@@ -267,6 +276,7 @@ for CHIP in $CHIPS; do
267276 enable_chip $CHIP
268277done
269278for CHIP in $CHIPS ; do
279+ disable_chip $CHIP
270280 remove_chip $CHIP
271281done
272282
@@ -278,13 +288,15 @@ echo foobar > $CONFIGFS_DIR/chip/bank/label 2> /dev/null && \
278288 fail " Setting label of a live chip should fail"
279289echo 8 > $CONFIGFS_DIR /chip/bank/num_lines 2> /dev/null && \
280290 fail " Setting number of lines of a live chip should fail"
291+ disable_chip chip
281292remove_chip chip
282293
283294echo " 2.10. Can't create line items when chip is live"
284295create_chip chip
285296create_bank chip bank
286297enable_chip chip
287298mkdir $CONFIGFS_DIR /chip/bank/line0 2> /dev/null && fail " Creating line item should fail"
299+ disable_chip chip
288300remove_chip chip
289301
290302echo " 2.11. Probe errors are propagated to user-space"
@@ -316,6 +328,7 @@ mkdir -p $CONFIGFS_DIR/chip/bank/line4/hog
316328enable_chip chip
317329$BASE_DIR /gpio-mockup-cdev -s 1 /dev/` configfs_chip_name chip bank` 4 2> /dev/null && \
318330 fail " Setting the value of a hogged line shouldn't succeed"
331+ disable_chip chip
319332remove_chip chip
320333
321334echo " 3. Controlling simulated chips"
@@ -331,6 +344,7 @@ test "$?" = "1" || fail "pull set incorrectly"
331344sysfs_set_pull chip bank 0 pull-down
332345$BASE_DIR /gpio-mockup-cdev /dev/` configfs_chip_name chip bank` 1
333346test " $? " = " 0" || fail " pull set incorrectly"
347+ disable_chip chip
334348remove_chip chip
335349
336350echo " 3.2. Pull can be read from sysfs"
@@ -344,6 +358,7 @@ SYSFS_PATH=/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio0/pull
344358test ` cat $SYSFS_PATH ` = " pull-down" || fail " reading the pull failed"
345359sysfs_set_pull chip bank 0 pull-up
346360test ` cat $SYSFS_PATH ` = " pull-up" || fail " reading the pull failed"
361+ disable_chip chip
347362remove_chip chip
348363
349364echo " 3.3. Incorrect input in sysfs is rejected"
@@ -355,6 +370,7 @@ DEVNAME=`configfs_dev_name chip`
355370CHIPNAME=` configfs_chip_name chip bank`
356371SYSFS_PATH=" /sys/devices/platform/$DEVNAME /$CHIPNAME /sim_gpio0/pull"
357372echo foobar > $SYSFS_PATH 2> /dev/null && fail " invalid input not detected"
373+ disable_chip chip
358374remove_chip chip
359375
360376echo " 3.4. Can't write to value"
@@ -365,6 +381,7 @@ DEVNAME=`configfs_dev_name chip`
365381CHIPNAME=` configfs_chip_name chip bank`
366382SYSFS_PATH=" /sys/devices/platform/$DEVNAME /$CHIPNAME /sim_gpio0/value"
367383echo 1 > $SYSFS_PATH 2> /dev/null && fail " writing to 'value' succeeded unexpectedly"
384+ disable_chip chip
368385remove_chip chip
369386
370387echo " 4. Simulated GPIO chips are functional"
@@ -382,6 +399,7 @@ $BASE_DIR/gpio-mockup-cdev -s 1 /dev/`configfs_chip_name chip bank` 0 &
382399sleep 0.1 # FIXME Any better way?
383400test ` cat $SYSFS_PATH ` = " 1" || fail " incorrect value read from sysfs"
384401kill $!
402+ disable_chip chip
385403remove_chip chip
386404
387405echo " 4.2. Bias settings work correctly"
@@ -394,6 +412,7 @@ CHIPNAME=`configfs_chip_name chip bank`
394412SYSFS_PATH=" /sys/devices/platform/$DEVNAME /$CHIPNAME /sim_gpio0/value"
395413$BASE_DIR /gpio-mockup-cdev -b pull-up /dev/` configfs_chip_name chip bank` 0
396414test ` cat $SYSFS_PATH ` = " 1" || fail " bias setting does not work"
415+ disable_chip chip
397416remove_chip chip
398417
399418echo " GPIO $MODULE test PASS"
0 commit comments