blob: 81c440d1f050576dbfe1198cd5475d98e1c78756 [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 Vlasenko44615642008-03-29 13:10:57 +000021mkdir mdev.testdir/etc
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000022mkdir mdev.testdir/dev
23mkdir -p mdev.testdir/sys/block/sda
24echo "8:0" >mdev.testdir/sys/block/sda/dev
25
26testing "mdev add /block/sda" \
27 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
28 ls -ln mdev.testdir/dev | $FILTER_LS" \
29"\
30mdev: /etc/mdev.conf: No such file or directory
Denis Vlasenko44615642008-03-29 13:10:57 +000031brw-rw---- 1 0 0 8,0 sda
32" \
33 "" ""
34
35# continuing to use directory structure from prev test
Denis Vlasenkocae11b52008-03-29 15:11:07 +000036rm -rf mdev.testdir/dev/*
Denis Vlasenko44615642008-03-29 13:10:57 +000037echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
38echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
39testing "mdev stops on first rule" \
40 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
41 ls -ln mdev.testdir/dev | $FILTER_LS" \
42"\
43brw-rw-rw- 1 1 1 8,0 sda
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000044" \
45 "" ""
46
Denis Vlasenkocae11b52008-03-29 15:11:07 +000047# continuing to use directory structure from prev test
48rm -rf mdev.testdir/dev/*
49echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
50testing "mdev move/symlink rule '>bar/baz'" \
51 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
52 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
53"\
54mdev.testdir/dev:
55drwxr-xr-x 2 0 0 disk
56lrwxrwxrwx 1 0 0 sda -> disk/scsiA
57
58mdev.testdir/dev/disk:
59br--r--r-- 1 0 0 scsiA
60" \
61 "" ""
62
63# continuing to use directory structure from prev test
64rm -rf mdev.testdir/dev/*
65echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
66testing "mdev move/symlink rule '>bar/'" \
67 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
68 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
69"\
70mdev.testdir/dev:
71drwxr-xr-x 2 0 0 disk
72lrwxrwxrwx 1 0 0 sda -> disk/sda
73
74mdev.testdir/dev/disk:
75br--r--r-- 1 0 0 sda
76" \
77 "" ""
78
Denis Vlasenkof2f38682008-03-29 17:26:10 +000079# continuing to use directory structure from prev test
80rm -rf mdev.testdir/dev/*
81# here we complicate things by having non-matching group 1 and using %0
82echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
83testing "mdev regexp substring match + replace" \
84 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
85 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
86"\
87mdev.testdir/dev:
88drwxr-xr-x 2 0 0 sd
89lrwxrwxrwx 1 0 0 sda -> sd/a_sda
90
91mdev.testdir/dev/sd:
92brw-r--r-- 1 0 0 a_sda
93" \
94 "" ""
95
Denis Vlasenkoe1caabb2008-03-27 20:49:26 +000096# clean up
97rm -rf mdev.testdir
98
99exit $FAILCOUNT