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 | |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 28 | # env - PATH=$PATH: on some systems chroot binary won't otherwise be found |
| 29 | |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 30 | testing "mdev add /block/sda" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 31 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 32 | ls -ln mdev.testdir/dev | $FILTER_LS" \ |
| 33 | "\ |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 34 | brw-rw---- 1 0 0 8,0 sda |
| 35 | " \ |
| 36 | "" "" |
| 37 | |
| 38 | # continuing to use directory structure from prev test |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 39 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 40 | echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf |
| 41 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf |
| 42 | testing "mdev stops on first rule" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 43 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | 4461564 | 2008-03-29 13:10:57 +0000 | [diff] [blame] | 44 | ls -ln mdev.testdir/dev | $FILTER_LS" \ |
| 45 | "\ |
| 46 | brw-rw-rw- 1 1 1 8,0 sda |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 47 | " \ |
| 48 | "" "" |
| 49 | |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 50 | # continuing to use directory structure from prev test |
| 51 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 3161b61 | 2009-04-16 22:42:01 +0000 | [diff] [blame] | 52 | echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf |
| 53 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf |
| 54 | testing "mdev does not stop on dash-rule" \ |
| 55 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
| 56 | ls -ln mdev.testdir/dev | $FILTER_LS" \ |
| 57 | "\ |
| 58 | br--r--r-- 1 2 2 8,0 sda |
| 59 | " \ |
| 60 | "" "" |
| 61 | |
| 62 | # continuing to use directory structure from prev test |
| 63 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 3798db5 | 2009-04-19 21:37:07 +0000 | [diff] [blame] | 64 | echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf |
| 65 | echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf |
| 66 | echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf |
| 67 | testing "mdev \$ENVVAR=regex match" \ |
| 68 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1; |
| 69 | ls -ln mdev.testdir/dev | $FILTER_LS" \ |
| 70 | "\ |
| 71 | br--r--r-- 1 2 2 8,0 sda |
| 72 | " \ |
| 73 | "" "" |
| 74 | |
| 75 | # continuing to use directory structure from prev test |
| 76 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 77 | echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf |
| 78 | testing "mdev move/symlink rule '>bar/baz'" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 79 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 80 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 81 | "\ |
| 82 | mdev.testdir/dev: |
| 83 | drwxr-xr-x 2 0 0 disk |
| 84 | lrwxrwxrwx 1 0 0 sda -> disk/scsiA |
| 85 | |
| 86 | mdev.testdir/dev/disk: |
| 87 | br--r--r-- 1 0 0 scsiA |
| 88 | " \ |
| 89 | "" "" |
| 90 | |
| 91 | # continuing to use directory structure from prev test |
| 92 | rm -rf mdev.testdir/dev/* |
| 93 | echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf |
| 94 | testing "mdev move/symlink rule '>bar/'" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 95 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | cae11b5 | 2008-03-29 15:11:07 +0000 | [diff] [blame] | 96 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 97 | "\ |
| 98 | mdev.testdir/dev: |
| 99 | drwxr-xr-x 2 0 0 disk |
| 100 | lrwxrwxrwx 1 0 0 sda -> disk/sda |
| 101 | |
| 102 | mdev.testdir/dev/disk: |
| 103 | br--r--r-- 1 0 0 sda |
| 104 | " \ |
| 105 | "" "" |
| 106 | |
Denis Vlasenko | f2f3868 | 2008-03-29 17:26:10 +0000 | [diff] [blame] | 107 | # continuing to use directory structure from prev test |
| 108 | rm -rf mdev.testdir/dev/* |
| 109 | # here we complicate things by having non-matching group 1 and using %0 |
| 110 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf |
| 111 | testing "mdev regexp substring match + replace" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 112 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | f2f3868 | 2008-03-29 17:26:10 +0000 | [diff] [blame] | 113 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 114 | "\ |
| 115 | mdev.testdir/dev: |
| 116 | drwxr-xr-x 2 0 0 sd |
| 117 | lrwxrwxrwx 1 0 0 sda -> sd/a_sda |
| 118 | |
| 119 | mdev.testdir/dev/sd: |
| 120 | brw-r--r-- 1 0 0 a_sda |
| 121 | " \ |
| 122 | "" "" |
| 123 | |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 124 | # continuing to use directory structure from prev test |
| 125 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 126 | echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf |
| 127 | testing "mdev command" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 128 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 129 | ls -lnR mdev.testdir/dev | $FILTER_LS" \ |
| 130 | "\ |
| 131 | @echo TEST |
| 132 | mdev.testdir/dev: |
| 133 | brw-r--r-- 1 0 0 8,0 sda |
| 134 | " \ |
| 135 | "" "" |
| 136 | |
Denis Vlasenko | 8d89bed | 2008-09-07 23:22:08 +0000 | [diff] [blame] | 137 | # continuing to use directory structure from prev test |
| 138 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 319fe12 | 2009-01-12 07:57:52 +0000 | [diff] [blame] | 139 | echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf |
| 140 | testing "mdev move and command" \ |
| 141 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
| 142 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 143 | "\ |
| 144 | @echo TEST |
| 145 | mdev.testdir/dev: |
| 146 | drwxr-xr-x 2 0 0 block |
| 147 | |
| 148 | mdev.testdir/dev/block: |
| 149 | brw-r--r-- 1 0 0 sda |
| 150 | " \ |
| 151 | "" "" |
| 152 | |
| 153 | # continuing to use directory structure from prev test |
| 154 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 8d89bed | 2008-09-07 23:22:08 +0000 | [diff] [blame] | 155 | echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf |
| 156 | testing "mdev #maj,min and no explicit uid" \ |
| 157 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
| 158 | ls -lnR mdev.testdir/dev | $FILTER_LS" \ |
| 159 | "\ |
| 160 | mdev.testdir/dev: |
| 161 | brw-r--r-- 1 0 1 8,0 sda |
| 162 | " \ |
| 163 | "" "" |
| 164 | |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 165 | # clean up |
| 166 | rm -rf mdev.testdir |
| 167 | |
| 168 | exit $FAILCOUNT |