blob: 8515aff319d5e390bf3431db5acdee7089d8cfad [file] [log] [blame]
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +00004
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +00006
7# ls -ln is showing date. Need to remove that, it's variable
8# sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces
Denis Vlasenko44615642008-03-29 13:10:57 +00009# cut: remove date
Denys Vlasenko307b24c2010-01-25 02:00:16 +010010FILTER_LS="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-"
Denis Vlasenkocae11b52008-03-29 15:11:07 +000011# cut: remove size+date
Denys Vlasenko307b24c2010-01-25 02:00:16 +010012FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-"
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000013
Denys Vlasenko4609f472013-01-21 01:22:12 +010014# testing "test name" "commands" "expected result" "file input" "stdin"
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000015
16rm -rf mdev.testdir
17mkdir mdev.testdir
18# We need mdev executable to be in chroot jail!
19# (will still fail with dynamically linked one, though...)
20cp ../busybox mdev.testdir/mdev
Denis Vlasenko32dcc532008-05-02 13:21:24 +000021mkdir mdev.testdir/bin
22cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature
Denis Vlasenko44615642008-03-29 13:10:57 +000023mkdir mdev.testdir/etc
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000024mkdir mdev.testdir/dev
25mkdir -p mdev.testdir/sys/block/sda
26echo "8:0" >mdev.testdir/sys/block/sda/dev
27
Denis Vlasenko5db861a2008-08-04 14:40:58 +000028# env - PATH=$PATH: on some systems chroot binary won't otherwise be found
29
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020030optional STATIC FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000031testing "mdev add /block/sda" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000032 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000033 ls -ln mdev.testdir/dev | $FILTER_LS" \
34"\
Denis Vlasenko44615642008-03-29 13:10:57 +000035brw-rw---- 1 0 0 8,0 sda
36" \
37 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020038SKIP=
Denis Vlasenko44615642008-03-29 13:10:57 +000039
40# continuing to use directory structure from prev test
Denys Vlasenkof2860bf2010-08-16 14:26:15 +020041optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
42testing "mdev deletes /block/sda" \
43 "env - PATH=$PATH ACTION=remove DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
44 ls -ln mdev.testdir/dev | $FILTER_LS" \
45"\
46" \
47 "" ""
48SKIP=
49
50# continuing to use directory structure from prev test
Denis Vlasenkocae11b52008-03-29 15:11:07 +000051rm -rf mdev.testdir/dev/*
Denis Vlasenko44615642008-03-29 13:10:57 +000052echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
53echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020054optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko44615642008-03-29 13:10:57 +000055testing "mdev stops on first rule" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000056 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko44615642008-03-29 13:10:57 +000057 ls -ln mdev.testdir/dev | $FILTER_LS" \
58"\
59brw-rw-rw- 1 1 1 8,0 sda
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000060" \
61 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020062SKIP=
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000063
Denis Vlasenkocae11b52008-03-29 15:11:07 +000064# continuing to use directory structure from prev test
65rm -rf mdev.testdir/dev/*
Denis Vlasenko3161b612009-04-16 22:42:01 +000066echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
67echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020068optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko3161b612009-04-16 22:42:01 +000069testing "mdev does not stop on dash-rule" \
70 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
71 ls -ln mdev.testdir/dev | $FILTER_LS" \
72"\
73br--r--r-- 1 2 2 8,0 sda
74" \
75 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020076SKIP=
Denis Vlasenko3161b612009-04-16 22:42:01 +000077
78# continuing to use directory structure from prev test
79rm -rf mdev.testdir/dev/*
Denis Vlasenko3798db52009-04-19 21:37:07 +000080echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
81echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
82echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020083optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko3798db52009-04-19 21:37:07 +000084testing "mdev \$ENVVAR=regex match" \
85 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
86 ls -ln mdev.testdir/dev | $FILTER_LS" \
87"\
88br--r--r-- 1 2 2 8,0 sda
89" \
90 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020091SKIP=
Denis Vlasenko3798db52009-04-19 21:37:07 +000092
93# continuing to use directory structure from prev test
94rm -rf mdev.testdir/dev/*
Denis Vlasenkocae11b52008-03-29 15:11:07 +000095echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020096optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenkocae11b52008-03-29 15:11:07 +000097testing "mdev move/symlink rule '>bar/baz'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000098 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000099 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
100"\
101mdev.testdir/dev:
102drwxr-xr-x 2 0 0 disk
103lrwxrwxrwx 1 0 0 sda -> disk/scsiA
104
105mdev.testdir/dev/disk:
106br--r--r-- 1 0 0 scsiA
107" \
108 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200109SKIP=
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000110
111# continuing to use directory structure from prev test
112rm -rf mdev.testdir/dev/*
113echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200114optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000115testing "mdev move/symlink rule '>bar/'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000116 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000117 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
118"\
119mdev.testdir/dev:
120drwxr-xr-x 2 0 0 disk
121lrwxrwxrwx 1 0 0 sda -> disk/sda
122
123mdev.testdir/dev/disk:
124br--r--r-- 1 0 0 sda
125" \
126 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200127SKIP=
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000128
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000129# continuing to use directory structure from prev test
130rm -rf mdev.testdir/dev/*
Denys Vlasenko4609f472013-01-21 01:22:12 +0100131echo "sda 0:0 444 =disk/sd/a" >mdev.testdir/etc/mdev.conf
132optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
133testing "mdev move rule '=bar/baz/fname'" \
134 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
135 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
136"\
137mdev.testdir/dev:
138drwxr-xr-x 3 0 0 disk
139
140mdev.testdir/dev/disk:
141drwxr-xr-x 2 0 0 sd
142
143mdev.testdir/dev/disk/sd:
144br--r--r-- 1 0 0 a
145" \
146 "" ""
147SKIP=
148
149# continuing to use directory structure from prev test
150rm -rf mdev.testdir/dev/*
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000151# here we complicate things by having non-matching group 1 and using %0
152echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoda138242010-05-11 12:02:48 +0200153optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000154testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000155 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000156 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
157"\
158mdev.testdir/dev:
159drwxr-xr-x 2 0 0 sd
160lrwxrwxrwx 1 0 0 sda -> sd/a_sda
161
162mdev.testdir/dev/sd:
163brw-r--r-- 1 0 0 a_sda
164" \
165 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200166SKIP=
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000167
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000168# continuing to use directory structure from prev test
169rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000170echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
Denys Vlasenko265062d2017-01-10 15:13:30 +0100171optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_SH_IS_ASH ASH_ECHO
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000172testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000173 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000174 ls -lnR mdev.testdir/dev | $FILTER_LS" \
175"\
176@echo TEST
177mdev.testdir/dev:
178brw-r--r-- 1 0 0 8,0 sda
179" \
180 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200181SKIP=
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000182
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000183# continuing to use directory structure from prev test
184rm -rf mdev.testdir/dev/*
Denys Vlasenko90db3592009-07-02 13:07:11 +0200185echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoc0211e92010-05-11 04:32:04 +0200186optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_SH_IS_ASH
Denis Vlasenko319fe122009-01-12 07:57:52 +0000187testing "mdev move and command" \
188 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
189 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
190"\
Denys Vlasenko90db3592009-07-02 13:07:11 +0200191@echo TEST:block/sda
Denis Vlasenko319fe122009-01-12 07:57:52 +0000192mdev.testdir/dev:
193drwxr-xr-x 2 0 0 block
194
195mdev.testdir/dev/block:
196brw-r--r-- 1 0 0 sda
197" \
198 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200199SKIP=
Denis Vlasenko319fe122009-01-12 07:57:52 +0000200
201# continuing to use directory structure from prev test
202rm -rf mdev.testdir/dev/*
Denys Vlasenko24410602009-06-13 23:41:57 +0200203echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200204optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000205testing "mdev #maj,min and no explicit uid" \
206 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
207 ls -lnR mdev.testdir/dev | $FILTER_LS" \
208"\
209mdev.testdir/dev:
210brw-r--r-- 1 0 1 8,0 sda
211" \
212 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200213SKIP=
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000214
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200215# continuing to use directory structure from prev test
216rm -rf mdev.testdir/dev/*
217mkdir -p mdev.testdir/sys/class/tty/capi
218echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
219mkdir -p mdev.testdir/sys/class/tty/capi1
220echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
221mkdir -p mdev.testdir/sys/class/tty/capi20
222echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
223echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
224echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
225echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
226# mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
Denys Vlasenkoda138242010-05-11 12:02:48 +0200227optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200228testing "move rule does not delete node with name == device_name" \
229 "\
230 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
231 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
232 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
233 ls -lnR mdev.testdir/dev | $FILTER_LS" \
234"\
235mdev.testdir/dev:
236crw-rw---- 1 0 0 191,0 capi20
237crw-rw---- 1 0 0 191,1 capi20.01
238crw-rw---- 1 0 0 191,20 capi20.20
239" \
240 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200241SKIP=
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200242
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000243# clean up
244rm -rf mdev.testdir
245
246exit $FAILCOUNT