Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 1 | #!/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 Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 9 | # cut: remove date |
| 10 | FILTER_LS="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-" |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 11 | # cut: remove size+date |
| 12 | FILTER_LS2="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-" |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 13 | |
| 14 | # testing "test name" "options" "expected result" "file input" "stdin" |
| 15 | |
| 16 | rm -rf mdev.testdir |
| 17 | mkdir mdev.testdir |
| 18 | # We need mdev executable to be in chroot jail! |
| 19 | # (will still fail with dynamically linked one, though...) |
| 20 | cp ../busybox mdev.testdir/mdev |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 21 | mkdir mdev.testdir/etc |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 22 | mkdir mdev.testdir/dev |
| 23 | mkdir -p mdev.testdir/sys/block/sda |
| 24 | echo "8:0" >mdev.testdir/sys/block/sda/dev |
| 25 | |
| 26 | testing "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 | "\ |
| 30 | mdev: /etc/mdev.conf: No such file or directory |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 31 | brw-rw---- 1 0 0 8,0 sda |
| 32 | " \ |
| 33 | "" "" |
| 34 | |
| 35 | # continuing to use directory structure from prev test |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 36 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 37 | echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf |
| 38 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf |
| 39 | testing "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 | "\ |
| 43 | brw-rw-rw- 1 1 1 8,0 sda |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 44 | " \ |
| 45 | "" "" |
| 46 | |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 47 | # continuing to use directory structure from prev test |
| 48 | rm -rf mdev.testdir/dev/* |
| 49 | echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf |
| 50 | testing "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 | "\ |
| 54 | mdev.testdir/dev: |
| 55 | drwxr-xr-x 2 0 0 disk |
| 56 | lrwxrwxrwx 1 0 0 sda -> disk/scsiA |
| 57 | |
| 58 | mdev.testdir/dev/disk: |
| 59 | br--r--r-- 1 0 0 scsiA |
| 60 | " \ |
| 61 | "" "" |
| 62 | |
| 63 | # continuing to use directory structure from prev test |
| 64 | rm -rf mdev.testdir/dev/* |
| 65 | echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf |
| 66 | testing "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 | "\ |
| 70 | mdev.testdir/dev: |
| 71 | drwxr-xr-x 2 0 0 disk |
| 72 | lrwxrwxrwx 1 0 0 sda -> disk/sda |
| 73 | |
| 74 | mdev.testdir/dev/disk: |
| 75 | br--r--r-- 1 0 0 sda |
| 76 | " \ |
| 77 | "" "" |
| 78 | |
Denis Vlasenko | f2f3868 | 2008-03-29 17:26:10 +0000 | [diff] [blame] | 79 | # continuing to use directory structure from prev test |
| 80 | rm -rf mdev.testdir/dev/* |
| 81 | # here we complicate things by having non-matching group 1 and using %0 |
| 82 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf |
| 83 | testing "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 | "\ |
| 87 | mdev.testdir/dev: |
| 88 | drwxr-xr-x 2 0 0 sd |
| 89 | lrwxrwxrwx 1 0 0 sda -> sd/a_sda |
| 90 | |
| 91 | mdev.testdir/dev/sd: |
| 92 | brw-r--r-- 1 0 0 a_sda |
| 93 | " \ |
| 94 | "" "" |
| 95 | |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 96 | # clean up |
| 97 | rm -rf mdev.testdir |
| 98 | |
| 99 | exit $FAILCOUNT |