2 # Copyright 2008 by Denys Vlasenko
3 # Licensed under GPL v2, see file LICENSE for details.
7 # ls -ln is showing date. Need to remove that, it's variable
8 # sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces
10 FILTER_LS="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-"
11 # cut: remove size+date
12 FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-"
14 # testing "test name" "options" "expected result" "file input" "stdin"
18 # We need mdev executable to be in chroot jail!
19 # (will still fail with dynamically linked one, though...)
20 cp ../busybox mdev.testdir/mdev
21 mkdir mdev.testdir/bin
22 cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature
23 mkdir mdev.testdir/etc
24 mkdir mdev.testdir/dev
25 mkdir -p mdev.testdir/sys/block/sda
26 echo "8:0" >mdev.testdir/sys/block/sda/dev
28 # env - PATH=$PATH: on some systems chroot binary won't otherwise be found
30 testing "mdev add /block/sda" \
31 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
32 ls -ln mdev.testdir/dev | $FILTER_LS" \
34 brw-rw---- 1 0 0 8,0 sda
38 # continuing to use directory structure from prev test
39 rm -rf mdev.testdir/dev/*
40 echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
41 echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
42 testing "mdev stops on first rule" \
43 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
44 ls -ln mdev.testdir/dev | $FILTER_LS" \
46 brw-rw-rw- 1 1 1 8,0 sda
50 # continuing to use directory structure from prev test
51 rm -rf mdev.testdir/dev/*
52 echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
53 echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
54 testing "mdev does not stop on dash-rule" \
55 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
56 ls -ln mdev.testdir/dev | $FILTER_LS" \
58 br--r--r-- 1 2 2 8,0 sda
62 # continuing to use directory structure from prev test
63 rm -rf mdev.testdir/dev/*
64 echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
65 echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
66 echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
67 testing "mdev \$ENVVAR=regex match" \
68 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
69 ls -ln mdev.testdir/dev | $FILTER_LS" \
71 br--r--r-- 1 2 2 8,0 sda
75 # continuing to use directory structure from prev test
76 rm -rf mdev.testdir/dev/*
77 echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
78 optional FEATURE_LS_RECURSIVE
79 testing "mdev move/symlink rule '>bar/baz'" \
80 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
81 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
85 lrwxrwxrwx 1 0 0 sda -> disk/scsiA
87 mdev.testdir/dev/disk:
88 br--r--r-- 1 0 0 scsiA
93 # continuing to use directory structure from prev test
94 rm -rf mdev.testdir/dev/*
95 echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
96 optional FEATURE_LS_RECURSIVE
97 testing "mdev move/symlink rule '>bar/'" \
98 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
99 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
102 drwxr-xr-x 2 0 0 disk
103 lrwxrwxrwx 1 0 0 sda -> disk/sda
105 mdev.testdir/dev/disk:
111 # continuing to use directory structure from prev test
112 rm -rf mdev.testdir/dev/*
113 # here we complicate things by having non-matching group 1 and using %0
114 echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
115 optional FEATURE_LS_RECURSIVE
116 testing "mdev regexp substring match + replace" \
117 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
118 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
122 lrwxrwxrwx 1 0 0 sda -> sd/a_sda
125 brw-r--r-- 1 0 0 a_sda
130 # continuing to use directory structure from prev test
131 rm -rf mdev.testdir/dev/*
132 echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
133 optional FEATURE_LS_RECURSIVE
134 testing "mdev command" \
135 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
136 ls -lnR mdev.testdir/dev | $FILTER_LS" \
140 brw-r--r-- 1 0 0 8,0 sda
145 # continuing to use directory structure from prev test
146 rm -rf mdev.testdir/dev/*
147 echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
148 optional FEATURE_LS_RECURSIVE
149 testing "mdev move and command" \
150 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
151 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
155 drwxr-xr-x 2 0 0 block
157 mdev.testdir/dev/block:
163 # continuing to use directory structure from prev test
164 rm -rf mdev.testdir/dev/*
165 echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
166 optional FEATURE_LS_RECURSIVE
167 testing "mdev #maj,min and no explicit uid" \
168 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
169 ls -lnR mdev.testdir/dev | $FILTER_LS" \
172 brw-r--r-- 1 0 1 8,0 sda
177 # continuing to use directory structure from prev test
178 rm -rf mdev.testdir/dev/*
179 mkdir -p mdev.testdir/sys/class/tty/capi
180 echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
181 mkdir -p mdev.testdir/sys/class/tty/capi1
182 echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
183 mkdir -p mdev.testdir/sys/class/tty/capi20
184 echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
185 echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
186 echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
187 echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
188 # mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
189 optional FEATURE_LS_RECURSIVE
190 testing "move rule does not delete node with name == device_name" \
192 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
193 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
194 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
195 ls -lnR mdev.testdir/dev | $FILTER_LS" \
198 crw-rw---- 1 0 0 191,0 capi20
199 crw-rw---- 1 0 0 191,1 capi20.01
200 crw-rw---- 1 0 0 191,20 capi20.20