blob: dad5bddb864da1cb90e8764c55e18853cfce7823 [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/*
101# here we complicate things by having non-matching group 1 and using %0
102echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
103testing "mdev command" \
Denis Vlasenko5db861a2008-08-04 14:40:58 +0000104 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
Denis Vlasenko32dcc532008-05-02 13:21:24 +0000105 ls -lnR mdev.testdir/dev | $FILTER_LS" \
106"\
107@echo TEST
108mdev.testdir/dev:
109brw-r--r-- 1 0 0 8,0 sda
110" \
111 "" ""
112
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +0000113# clean up
114rm -rf mdev.testdir
115
116exit $FAILCOUNT