blob: 7320e17ddbcafb3f74bb1dfd5ba08c5bcabe8ccf [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
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
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/*
131# here we complicate things by having non-matching group 1 and using %0
132echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoda138242010-05-11 12:02:48 +0200133optional 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 +0000134testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000135 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000136 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
137"\
138mdev.testdir/dev:
139drwxr-xr-x 2 0 0 sd
140lrwxrwxrwx 1 0 0 sda -> sd/a_sda
141
142mdev.testdir/dev/sd:
143brw-r--r-- 1 0 0 a_sda
144" \
145 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200146SKIP=
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000147
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000148# continuing to use directory structure from prev test
149rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000150echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoc0211e92010-05-11 04:32:04 +0200151optional 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 +0000152testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000153 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000154 ls -lnR mdev.testdir/dev | $FILTER_LS" \
155"\
156@echo TEST
157mdev.testdir/dev:
158brw-r--r-- 1 0 0 8,0 sda
159" \
160 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200161SKIP=
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000162
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000163# continuing to use directory structure from prev test
164rm -rf mdev.testdir/dev/*
Denys Vlasenko90db3592009-07-02 13:07:11 +0200165echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
Denys Vlasenkoc0211e92010-05-11 04:32:04 +0200166optional 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 +0000167testing "mdev move and command" \
168 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
169 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
170"\
Denys Vlasenko90db3592009-07-02 13:07:11 +0200171@echo TEST:block/sda
Denis Vlasenko319fe122009-01-12 07:57:52 +0000172mdev.testdir/dev:
173drwxr-xr-x 2 0 0 block
174
175mdev.testdir/dev/block:
176brw-r--r-- 1 0 0 sda
177" \
178 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200179SKIP=
Denis Vlasenko319fe122009-01-12 07:57:52 +0000180
181# continuing to use directory structure from prev test
182rm -rf mdev.testdir/dev/*
Denys Vlasenko24410602009-06-13 23:41:57 +0200183echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +0200184optional 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 +0000185testing "mdev #maj,min and no explicit uid" \
186 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
187 ls -lnR mdev.testdir/dev | $FILTER_LS" \
188"\
189mdev.testdir/dev:
190brw-r--r-- 1 0 1 8,0 sda
191" \
192 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200193SKIP=
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000194
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200195# continuing to use directory structure from prev test
196rm -rf mdev.testdir/dev/*
197mkdir -p mdev.testdir/sys/class/tty/capi
198echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
199mkdir -p mdev.testdir/sys/class/tty/capi1
200echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
201mkdir -p mdev.testdir/sys/class/tty/capi20
202echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
203echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
204echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
205echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
206# mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
Denys Vlasenkoda138242010-05-11 12:02:48 +0200207optional 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 +0200208testing "move rule does not delete node with name == device_name" \
209 "\
210 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
211 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
212 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
213 ls -lnR mdev.testdir/dev | $FILTER_LS" \
214"\
215mdev.testdir/dev:
216crw-rw---- 1 0 0 191,0 capi20
217crw-rw---- 1 0 0 191,1 capi20.01
218crw-rw---- 1 0 0 191,20 capi20.20
219" \
220 "" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200221SKIP=
Denys Vlasenko2f86ca12009-06-22 01:31:12 +0200222
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000223# clean up
224rm -rf mdev.testdir
225
226exit $FAILCOUNT