blob: 572609e11d45ce87c0bfbaf29573164579c10d2b [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
28testing "mdev add /block/sda" \
29 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
30 ls -ln mdev.testdir/dev | $FILTER_LS" \
31"\
32mdev: /etc/mdev.conf: No such file or directory
Denis Vlasenko44615642008-03-29 13:10:57 +000033brw-rw---- 1 0 0 8,0 sda
34" \
35 "" ""
36
37# continuing to use directory structure from prev test
Denis Vlasenkocae11b52008-03-29 15:11:07 +000038rm -rf mdev.testdir/dev/*
Denis Vlasenko44615642008-03-29 13:10:57 +000039echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
40echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
41testing "mdev stops on first rule" \
42 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
43 ls -ln mdev.testdir/dev | $FILTER_LS" \
44"\
45brw-rw-rw- 1 1 1 8,0 sda
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000046" \
47 "" ""
48
Denis Vlasenkocae11b52008-03-29 15:11:07 +000049# continuing to use directory structure from prev test
50rm -rf mdev.testdir/dev/*
51echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
52testing "mdev move/symlink rule '>bar/baz'" \
53 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
54 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
55"\
56mdev.testdir/dev:
57drwxr-xr-x 2 0 0 disk
58lrwxrwxrwx 1 0 0 sda -> disk/scsiA
59
60mdev.testdir/dev/disk:
61br--r--r-- 1 0 0 scsiA
62" \
63 "" ""
64
65# continuing to use directory structure from prev test
66rm -rf mdev.testdir/dev/*
67echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
68testing "mdev move/symlink rule '>bar/'" \
69 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
70 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
71"\
72mdev.testdir/dev:
73drwxr-xr-x 2 0 0 disk
74lrwxrwxrwx 1 0 0 sda -> disk/sda
75
76mdev.testdir/dev/disk:
77br--r--r-- 1 0 0 sda
78" \
79 "" ""
80
Denis Vlasenkof2f38682008-03-29 17:26:10 +000081# continuing to use directory structure from prev test
82rm -rf mdev.testdir/dev/*
83# here we complicate things by having non-matching group 1 and using %0
84echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
85testing "mdev regexp substring match + replace" \
86 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
87 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
88"\
89mdev.testdir/dev:
90drwxr-xr-x 2 0 0 sd
91lrwxrwxrwx 1 0 0 sda -> sd/a_sda
92
93mdev.testdir/dev/sd:
94brw-r--r-- 1 0 0 a_sda
95" \
96 "" ""
97
Denis Vlasenko32dcc532008-05-02 13:21:24 +000098# continuing to use directory structure from prev test
99rm -rf mdev.testdir/dev/*
100# here we complicate things by having non-matching group 1 and using %0
101echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
102testing "mdev command" \
103 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
104 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 Vlasenkoe1caabb2008-03-27 20:49:26 +0000112# clean up
113rm -rf mdev.testdir
114
115exit $FAILCOUNT