blob: 6d6a21d417c39b4a38354daa753fa819acf046a7 [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
5. testing.sh
6
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
10FILTER_LS="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
12FILTER_LS2="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
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000030testing "mdev add /block/sda" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000031 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000032 ls -ln mdev.testdir/dev | $FILTER_LS" \
33"\
Denis Vlasenko44615642008-03-29 13:10:57 +000034brw-rw---- 1 0 0 8,0 sda
35" \
36 "" ""
37
38# continuing to use directory structure from prev test
Denis Vlasenkocae11b52008-03-29 15:11:07 +000039rm -rf mdev.testdir/dev/*
Denis Vlasenko44615642008-03-29 13:10:57 +000040echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
41echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
42testing "mdev stops on first rule" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000043 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko44615642008-03-29 13:10:57 +000044 ls -ln mdev.testdir/dev | $FILTER_LS" \
45"\
46brw-rw-rw- 1 1 1 8,0 sda
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000047" \
48 "" ""
49
Denis Vlasenkocae11b52008-03-29 15:11:07 +000050# continuing to use directory structure from prev test
51rm -rf mdev.testdir/dev/*
Denis Vlasenko3161b612009-04-16 22:42:01 +000052echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
53echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
54testing "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" \
57"\
58br--r--r-- 1 2 2 8,0 sda
59" \
60 "" ""
61
62# continuing to use directory structure from prev test
63rm -rf mdev.testdir/dev/*
Denis Vlasenko3798db52009-04-19 21:37:07 +000064echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
65echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
66echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
67testing "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" \
70"\
71br--r--r-- 1 2 2 8,0 sda
72" \
73 "" ""
74
75# continuing to use directory structure from prev test
76rm -rf mdev.testdir/dev/*
Denis Vlasenkocae11b52008-03-29 15:11:07 +000077echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
78testing "mdev move/symlink rule '>bar/baz'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000079 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000080 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
81"\
82mdev.testdir/dev:
83drwxr-xr-x 2 0 0 disk
84lrwxrwxrwx 1 0 0 sda -> disk/scsiA
85
86mdev.testdir/dev/disk:
87br--r--r-- 1 0 0 scsiA
88" \
89 "" ""
90
91# continuing to use directory structure from prev test
92rm -rf mdev.testdir/dev/*
93echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
94testing "mdev move/symlink rule '>bar/'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000095 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000096 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
97"\
98mdev.testdir/dev:
99drwxr-xr-x 2 0 0 disk
100lrwxrwxrwx 1 0 0 sda -> disk/sda
101
102mdev.testdir/dev/disk:
103br--r--r-- 1 0 0 sda
104" \
105 "" ""
106
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000107# continuing to use directory structure from prev test
108rm -rf mdev.testdir/dev/*
109# here we complicate things by having non-matching group 1 and using %0
110echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
111testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000112 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000113 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
114"\
115mdev.testdir/dev:
116drwxr-xr-x 2 0 0 sd
117lrwxrwxrwx 1 0 0 sda -> sd/a_sda
118
119mdev.testdir/dev/sd:
120brw-r--r-- 1 0 0 a_sda
121" \
122 "" ""
123
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000124# continuing to use directory structure from prev test
125rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000126echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
127testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000128 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000129 ls -lnR mdev.testdir/dev | $FILTER_LS" \
130"\
131@echo TEST
132mdev.testdir/dev:
133brw-r--r-- 1 0 0 8,0 sda
134" \
135 "" ""
136
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000137# continuing to use directory structure from prev test
138rm -rf mdev.testdir/dev/*
Denis Vlasenko319fe122009-01-12 07:57:52 +0000139echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf
140testing "mdev move and command" \
141 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
142 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
143"\
144@echo TEST
145mdev.testdir/dev:
146drwxr-xr-x 2 0 0 block
147
148mdev.testdir/dev/block:
149brw-r--r-- 1 0 0 sda
150" \
151 "" ""
152
153# continuing to use directory structure from prev test
154rm -rf mdev.testdir/dev/*
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000155echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf
156testing "mdev #maj,min and no explicit uid" \
157 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
158 ls -lnR mdev.testdir/dev | $FILTER_LS" \
159"\
160mdev.testdir/dev:
161brw-r--r-- 1 0 1 8,0 sda
162" \
163 "" ""
164
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000165# clean up
166rm -rf mdev.testdir
167
168exit $FAILCOUNT