blob: 90379e6685b466cf8e5e92777a9d296fe741afba [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/*
52echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
53testing "mdev move/symlink rule '>bar/baz'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000054 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000055 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
56"\
57mdev.testdir/dev:
58drwxr-xr-x 2 0 0 disk
59lrwxrwxrwx 1 0 0 sda -> disk/scsiA
60
61mdev.testdir/dev/disk:
62br--r--r-- 1 0 0 scsiA
63" \
64 "" ""
65
66# continuing to use directory structure from prev test
67rm -rf mdev.testdir/dev/*
68echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
69testing "mdev move/symlink rule '>bar/'" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000070 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkocae11b52008-03-29 15:11:07 +000071 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
72"\
73mdev.testdir/dev:
74drwxr-xr-x 2 0 0 disk
75lrwxrwxrwx 1 0 0 sda -> disk/sda
76
77mdev.testdir/dev/disk:
78br--r--r-- 1 0 0 sda
79" \
80 "" ""
81
Denis Vlasenkof2f38682008-03-29 17:26:10 +000082# continuing to use directory structure from prev test
83rm -rf mdev.testdir/dev/*
84# here we complicate things by having non-matching group 1 and using %0
85echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
86testing "mdev regexp substring match + replace" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +000087 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenkof2f38682008-03-29 17:26:10 +000088 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
89"\
90mdev.testdir/dev:
91drwxr-xr-x 2 0 0 sd
92lrwxrwxrwx 1 0 0 sda -> sd/a_sda
93
94mdev.testdir/dev/sd:
95brw-r--r-- 1 0 0 a_sda
96" \
97 "" ""
98
Denis Vlasenko32dcc532008-05-02 13:21:24 +000099# continuing to use directory structure from prev test
100rm -rf mdev.testdir/dev/*
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000101echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
102testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000103 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000104 ls -lnR mdev.testdir/dev | $FILTER_LS" \
105"\
106@echo TEST
107mdev.testdir/dev:
108brw-r--r-- 1 0 0 8,0 sda
109" \
110 "" ""
111
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000112# continuing to use directory structure from prev test
113rm -rf mdev.testdir/dev/*
Denis Vlasenko319fe122009-01-12 07:57:52 +0000114echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf
115testing "mdev move and command" \
116 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
117 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
118"\
119@echo TEST
120mdev.testdir/dev:
121drwxr-xr-x 2 0 0 block
122
123mdev.testdir/dev/block:
124brw-r--r-- 1 0 0 sda
125" \
126 "" ""
127
128# continuing to use directory structure from prev test
129rm -rf mdev.testdir/dev/*
Denis Vlasenko8d89bed2008-09-07 23:22:08 +0000130echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf
131testing "mdev #maj,min and no explicit uid" \
132 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
133 ls -lnR mdev.testdir/dev | $FILTER_LS" \
134"\
135mdev.testdir/dev:
136brw-r--r-- 1 0 1 8,0 sda
137" \
138 "" ""
139
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000140# clean up
141rm -rf mdev.testdir
142
143exit $FAILCOUNT