blob: 388c41d529fc38634e4e8a65049612a0859082db [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 Vlasenkocae11b52008-03-29 15:11:07 +000064echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
65testing "mdev move/symlink rule '>bar/baz'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000066 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000067 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
68"\
69mdev.testdir/dev:
70drwxr-xr-x 2 0 0 disk
71lrwxrwxrwx 1 0 0 sda -> disk/scsiA
72
73mdev.testdir/dev/disk:
74br--r--r-- 1 0 0 scsiA
75" \
76 "" ""
77
78# continuing to use directory structure from prev test
79rm -rf mdev.testdir/dev/*
80echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
81testing "mdev move/symlink rule '>bar/'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000082 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000083 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
84"\
85mdev.testdir/dev:
86drwxr-xr-x 2 0 0 disk
87lrwxrwxrwx 1 0 0 sda -> disk/sda
88
89mdev.testdir/dev/disk:
90br--r--r-- 1 0 0 sda
91" \
92 "" ""
93
Denis Vlasenkof2f38682008-03-29 17:26:10 +000094# continuing to use directory structure from prev test
95rm -rf mdev.testdir/dev/*
96# here we complicate things by having non-matching group 1 and using %0
97echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
98testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000099 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +0000100 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
101"\
102mdev.testdir/dev:
103drwxr-xr-x 2 0 0 sd
104lrwxrwxrwx 1 0 0 sda -> sd/a_sda
105
106mdev.testdir/dev/sd:
107brw-r--r-- 1 0 0 a_sda
108" \
109 "" ""
110
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000111# continuing to use directory structure from prev test
112rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000113echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
114testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000115 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000116 ls -lnR mdev.testdir/dev | $FILTER_LS" \
117"\
118@echo TEST
119mdev.testdir/dev:
120brw-r--r-- 1 0 0 8,0 sda
121" \
122 "" ""
123
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000124# continuing to use directory structure from prev test
125rm -rf mdev.testdir/dev/*
Denis Vlasenko319fe122009-01-12 07:57:52 +0000126echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf
127testing "mdev move and command" \
128 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
129 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
130"\
131@echo TEST
132mdev.testdir/dev:
133drwxr-xr-x 2 0 0 block
134
135mdev.testdir/dev/block:
136brw-r--r-- 1 0 0 sda
137" \
138 "" ""
139
140# continuing to use directory structure from prev test
141rm -rf mdev.testdir/dev/*
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000142echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf
143testing "mdev #maj,min and no explicit uid" \
144 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
145 ls -lnR mdev.testdir/dev | $FILTER_LS" \
146"\
147mdev.testdir/dev:
148brw-r--r-- 1 0 1 8,0 sda
149" \
150 "" ""
151
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000152# clean up
153rm -rf mdev.testdir
154
155exit $FAILCOUNT