summaryrefslogtreecommitdiffhomepage
path: root/testsuite/mdev.tests
blob: 6d6a21d417c39b4a38354daa753fa819acf046a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh
# Copyright 2008 by Denys Vlasenko
# Licensed under GPL v2, see file LICENSE for details.

. testing.sh

# ls -ln is showing date. Need to remove that, it's variable
# sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces
# cut: remove date
FILTER_LS="sed -e 's/,  */,/g' -e 's/  */ /g' | cut -d' ' -f 1-5,9-"
# cut: remove size+date
FILTER_LS2="sed -e 's/,  */,/g' -e 's/  */ /g' | cut -d' ' -f 1-4,9-"

# testing "test name" "options" "expected result" "file input" "stdin"

rm -rf mdev.testdir
mkdir mdev.testdir
# We need mdev executable to be in chroot jail!
# (will still fail with dynamically linked one, though...)
cp ../busybox mdev.testdir/mdev
mkdir mdev.testdir/bin
cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature
mkdir mdev.testdir/etc
mkdir mdev.testdir/dev
mkdir -p mdev.testdir/sys/block/sda
echo "8:0" >mdev.testdir/sys/block/sda/dev

# env - PATH=$PATH: on some systems chroot binary won't otherwise be found

testing "mdev add /block/sda" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -ln mdev.testdir/dev | $FILTER_LS" \
"\
brw-rw---- 1 0 0 8,0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
testing "mdev stops on first rule" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -ln mdev.testdir/dev | $FILTER_LS" \
"\
brw-rw-rw- 1 1 1 8,0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
testing "mdev does not stop on dash-rule" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -ln mdev.testdir/dev | $FILTER_LS" \
"\
br--r--r-- 1 2 2 8,0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "\$MODALIAS=qw  1:1 666" >mdev.testdir/etc/mdev.conf
echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
testing "mdev \$ENVVAR=regex match" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
	ls -ln mdev.testdir/dev | $FILTER_LS" \
"\
br--r--r-- 1 2 2 8,0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
testing "mdev move/symlink rule '>bar/baz'" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS2" \
"\
mdev.testdir/dev:
drwxr-xr-x 2 0 0 disk
lrwxrwxrwx 1 0 0 sda -> disk/scsiA

mdev.testdir/dev/disk:
br--r--r-- 1 0 0 scsiA
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
testing "mdev move/symlink rule '>bar/'" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS2" \
"\
mdev.testdir/dev:
drwxr-xr-x 2 0 0 disk
lrwxrwxrwx 1 0 0 sda -> disk/sda

mdev.testdir/dev/disk:
br--r--r-- 1 0 0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
# here we complicate things by having non-matching group 1 and using %0
echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
testing "mdev regexp substring match + replace" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS2" \
"\
mdev.testdir/dev:
drwxr-xr-x 2 0 0 sd
lrwxrwxrwx 1 0 0 sda -> sd/a_sda

mdev.testdir/dev/sd:
brw-r--r-- 1 0 0 a_sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
testing "mdev command" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS" \
"\
@echo TEST
mdev.testdir/dev:
brw-r--r-- 1 0 0 8,0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf
testing "mdev move and command" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS2" \
"\
@echo TEST
mdev.testdir/dev:
drwxr-xr-x 2 0 0 block

mdev.testdir/dev/block:
brw-r--r-- 1 0 0 sda
" \
	"" ""

# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf
testing "mdev #maj,min and no explicit uid" \
	"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
	ls -lnR mdev.testdir/dev | $FILTER_LS" \
"\
mdev.testdir/dev:
brw-r--r-- 1 0 1 8,0 sda
" \
	"" ""

# clean up
rm -rf mdev.testdir

exit $FAILCOUNT