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 | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 21 | mkdir mdev.testdir/bin |
| 22 | cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 23 | mkdir mdev.testdir/etc |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 24 | mkdir mdev.testdir/dev |
| 25 | mkdir -p mdev.testdir/sys/block/sda |
| 26 | echo "8:0" >mdev.testdir/sys/block/sda/dev |
| 27 | |
| 28 | testing "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 | "\ |
| 32 | mdev: /etc/mdev.conf: No such file or directory |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 33 | brw-rw---- 1 0 0 8,0 sda |
| 34 | " \ |
| 35 | "" "" |
| 36 | |
| 37 | # continuing to use directory structure from prev test |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 38 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 39 | echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf |
| 40 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf |
| 41 | testing "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 | "\ |
| 45 | brw-rw-rw- 1 1 1 8,0 sda |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 46 | " \ |
| 47 | "" "" |
| 48 | |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 49 | # continuing to use directory structure from prev test |
| 50 | rm -rf mdev.testdir/dev/* |
| 51 | echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf |
| 52 | testing "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 | "\ |
| 56 | mdev.testdir/dev: |
| 57 | drwxr-xr-x 2 0 0 disk |
| 58 | lrwxrwxrwx 1 0 0 sda -> disk/scsiA |
| 59 | |
| 60 | mdev.testdir/dev/disk: |
| 61 | br--r--r-- 1 0 0 scsiA |
| 62 | " \ |
| 63 | "" "" |
| 64 | |
| 65 | # continuing to use directory structure from prev test |
| 66 | rm -rf mdev.testdir/dev/* |
| 67 | echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf |
| 68 | testing "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 | "\ |
| 72 | mdev.testdir/dev: |
| 73 | drwxr-xr-x 2 0 0 disk |
| 74 | lrwxrwxrwx 1 0 0 sda -> disk/sda |
| 75 | |
| 76 | mdev.testdir/dev/disk: |
| 77 | br--r--r-- 1 0 0 sda |
| 78 | " \ |
| 79 | "" "" |
| 80 | |
Denis Vlasenko | f2f3868 | 2008-03-29 17:26:10 +0000 | [diff] [blame] | 81 | # continuing to use directory structure from prev test |
| 82 | rm -rf mdev.testdir/dev/* |
| 83 | # here we complicate things by having non-matching group 1 and using %0 |
| 84 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf |
| 85 | testing "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 | "\ |
| 89 | mdev.testdir/dev: |
| 90 | drwxr-xr-x 2 0 0 sd |
| 91 | lrwxrwxrwx 1 0 0 sda -> sd/a_sda |
| 92 | |
| 93 | mdev.testdir/dev/sd: |
| 94 | brw-r--r-- 1 0 0 a_sda |
| 95 | " \ |
| 96 | "" "" |
| 97 | |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 98 | # continuing to use directory structure from prev test |
| 99 | rm -rf mdev.testdir/dev/* |
| 100 | # here we complicate things by having non-matching group 1 and using %0 |
| 101 | echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf |
| 102 | testing "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 |
| 107 | mdev.testdir/dev: |
| 108 | brw-r--r-- 1 0 0 8,0 sda |
| 109 | " \ |
| 110 | "" "" |
| 111 | |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 112 | # clean up |
| 113 | rm -rf mdev.testdir |
| 114 | |
| 115 | exit $FAILCOUNT |