blob: c375fc7748dcc1049ef82146b170e2038a477dce [file] [log] [blame]
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
3# Licensed under GPL v2, see file LICENSE for details.
4
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
14# testing "test name" "options" "expected result" "file input" "stdin"
15
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
Denis Vlasenkocae11b52008-03-29 15:11:07 +000041rm -rf mdev.testdir/dev/*
Denis Vlasenko44615642008-03-29 13:10:57 +000042echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
43echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020044optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko44615642008-03-29 13:10:57 +000045testing "mdev stops on first rule" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000046 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko44615642008-03-29 13:10:57 +000047 ls -ln mdev.testdir/dev | $FILTER_LS" \
48"\
49brw-rw-rw- 1 1 1 8,0 sda
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000050" \
51 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020052SKIP=
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000053
Denis Vlasenkocae11b52008-03-29 15:11:07 +000054# continuing to use directory structure from prev test
55rm -rf mdev.testdir/dev/*
Denis Vlasenko3161b612009-04-16 22:42:01 +000056echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
57echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020058optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko3161b612009-04-16 22:42:01 +000059testing "mdev does not stop on dash-rule" \
60 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
61 ls -ln mdev.testdir/dev | $FILTER_LS" \
62"\
63br--r--r-- 1 2 2 8,0 sda
64" \
65 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020066SKIP=
Denis Vlasenko3161b612009-04-16 22:42:01 +000067
68# continuing to use directory structure from prev test
69rm -rf mdev.testdir/dev/*
Denis Vlasenko3798db52009-04-19 21:37:07 +000070echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
71echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
72echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020073optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenko3798db52009-04-19 21:37:07 +000074testing "mdev \$ENVVAR=regex match" \
75 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
76 ls -ln mdev.testdir/dev | $FILTER_LS" \
77"\
78br--r--r-- 1 2 2 8,0 sda
79" \
80 "" ""
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020081SKIP=
Denis Vlasenko3798db52009-04-19 21:37:07 +000082
83# continuing to use directory structure from prev test
84rm -rf mdev.testdir/dev/*
Denis Vlasenkocae11b52008-03-29 15:11:07 +000085echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020086optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenkocae11b52008-03-29 15:11:07 +000087testing "mdev move/symlink rule '>bar/baz'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000088 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000089 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
90"\
91mdev.testdir/dev:
92drwxr-xr-x 2 0 0 disk
93lrwxrwxrwx 1 0 0 sda -> disk/scsiA
94
95mdev.testdir/dev/disk:
96br--r--r-- 1 0 0 scsiA
97" \
98 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020099SKIP=
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000100
101# continuing to use directory structure from prev test
102rm -rf mdev.testdir/dev/*
103echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200104optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000105testing "mdev move/symlink rule '>bar/'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000106 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000107 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
108"\
109mdev.testdir/dev:
110drwxr-xr-x 2 0 0 disk
111lrwxrwxrwx 1 0 0 sda -> disk/sda
112
113mdev.testdir/dev/disk:
114br--r--r-- 1 0 0 sda
115" \
116 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200117SKIP=
Denis Vlasenkocae11b52008-03-29 15:11:07 +0000118
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000119# continuing to use directory structure from prev test
120rm -rf mdev.testdir/dev/*
121# here we complicate things by having non-matching group 1 and using %0
122echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoda138242010-05-11 12:02:48 +0200123optional 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 +0000124testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000125 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000126 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
127"\
128mdev.testdir/dev:
129drwxr-xr-x 2 0 0 sd
130lrwxrwxrwx 1 0 0 sda -> sd/a_sda
131
132mdev.testdir/dev/sd:
133brw-r--r-- 1 0 0 a_sda
134" \
135 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200136SKIP=
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000137
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000138# continuing to use directory structure from prev test
139rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000140echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoc0211e92010-05-11 04:32:04 +0200141optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_SH_IS_ASH
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000142testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000143 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000144 ls -lnR mdev.testdir/dev | $FILTER_LS" \
145"\
146@echo TEST
147mdev.testdir/dev:
148brw-r--r-- 1 0 0 8,0 sda
149" \
150 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200151SKIP=
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000152
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000153# continuing to use directory structure from prev test
154rm -rf mdev.testdir/dev/*
Denys Vlasenko90db3592009-07-02 13:07:11 +0200155echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoc0211e92010-05-11 04:32:04 +0200156optional 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 +0000157testing "mdev move and command" \
158 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
159 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
160"\
Denys Vlasenko90db3592009-07-02 13:07:11 +0200161@echo TEST:block/sda
Denis Vlasenko319fe122009-01-12 07:57:52 +0000162mdev.testdir/dev:
163drwxr-xr-x 2 0 0 block
164
165mdev.testdir/dev/block:
166brw-r--r-- 1 0 0 sda
167" \
168 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200169SKIP=
Denis Vlasenko319fe122009-01-12 07:57:52 +0000170
171# continuing to use directory structure from prev test
172rm -rf mdev.testdir/dev/*
Denys Vlasenko24410602009-06-13 23:41:57 +0200173echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200174optional 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 +0000175testing "mdev #maj,min and no explicit uid" \
176 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
177 ls -lnR mdev.testdir/dev | $FILTER_LS" \
178"\
179mdev.testdir/dev:
180brw-r--r-- 1 0 1 8,0 sda
181" \
182 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200183SKIP=
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000184
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200185# continuing to use directory structure from prev test
186rm -rf mdev.testdir/dev/*
187mkdir -p mdev.testdir/sys/class/tty/capi
188echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
189mkdir -p mdev.testdir/sys/class/tty/capi1
190echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
191mkdir -p mdev.testdir/sys/class/tty/capi20
192echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
193echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
194echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
195echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
196# mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
Denys Vlasenkoda138242010-05-11 12:02:48 +0200197optional 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 +0200198testing "move rule does not delete node with name == device_name" \
199 "\
200 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
201 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
202 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
203 ls -lnR mdev.testdir/dev | $FILTER_LS" \
204"\
205mdev.testdir/dev:
206crw-rw---- 1 0 0 191,0 capi20
207crw-rw---- 1 0 0 191,1 capi20.01
208crw-rw---- 1 0 0 191,20 capi20.20
209" \
210 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200211SKIP=
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200212
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000213# clean up
214rm -rf mdev.testdir
215
216exit $FAILCOUNT