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/* |
| 52 | echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf |
| 53 | testing "mdev move/symlink rule '>bar/baz'" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 54 | "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] | 55 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 56 | "\ |
| 57 | mdev.testdir/dev: |
| 58 | drwxr-xr-x 2 0 0 disk |
| 59 | lrwxrwxrwx 1 0 0 sda -> disk/scsiA |
| 60 | |
| 61 | mdev.testdir/dev/disk: |
| 62 | br--r--r-- 1 0 0 scsiA |
| 63 | " \ |
| 64 | "" "" |
| 65 | |
| 66 | # continuing to use directory structure from prev test |
| 67 | rm -rf mdev.testdir/dev/* |
| 68 | echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf |
| 69 | testing "mdev move/symlink rule '>bar/'" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 70 | "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] | 71 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 72 | "\ |
| 73 | mdev.testdir/dev: |
| 74 | drwxr-xr-x 2 0 0 disk |
| 75 | lrwxrwxrwx 1 0 0 sda -> disk/sda |
| 76 | |
| 77 | mdev.testdir/dev/disk: |
| 78 | br--r--r-- 1 0 0 sda |
| 79 | " \ |
| 80 | "" "" |
| 81 | |
Denis Vlasenko | f2f3868 | 2008-03-29 17:26:10 +0000 | [diff] [blame] | 82 | # continuing to use directory structure from prev test |
| 83 | rm -rf mdev.testdir/dev/* |
| 84 | # here we complicate things by having non-matching group 1 and using %0 |
| 85 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf |
| 86 | testing "mdev regexp substring match + replace" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 87 | "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] | 88 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 89 | "\ |
| 90 | mdev.testdir/dev: |
| 91 | drwxr-xr-x 2 0 0 sd |
| 92 | lrwxrwxrwx 1 0 0 sda -> sd/a_sda |
| 93 | |
| 94 | mdev.testdir/dev/sd: |
| 95 | brw-r--r-- 1 0 0 a_sda |
| 96 | " \ |
| 97 | "" "" |
| 98 | |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 99 | # continuing to use directory structure from prev test |
| 100 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 32dcc53 | 2008-05-02 13:21:24 +0000 | [diff] [blame] | 101 | echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf |
| 102 | testing "mdev command" \ |
Denis Vlasenko | 5db861a | 2008-08-04 14:40:58 +0000 | [diff] [blame] | 103 | "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] | 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 | 8d89bed | 2008-09-07 23:22:08 +0000 | [diff] [blame] | 112 | # continuing to use directory structure from prev test |
| 113 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 319fe12 | 2009-01-12 07:57:52 +0000 | [diff] [blame] | 114 | echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf |
| 115 | testing "mdev move and command" \ |
| 116 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
| 117 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ |
| 118 | "\ |
| 119 | @echo TEST |
| 120 | mdev.testdir/dev: |
| 121 | drwxr-xr-x 2 0 0 block |
| 122 | |
| 123 | mdev.testdir/dev/block: |
| 124 | brw-r--r-- 1 0 0 sda |
| 125 | " \ |
| 126 | "" "" |
| 127 | |
| 128 | # continuing to use directory structure from prev test |
| 129 | rm -rf mdev.testdir/dev/* |
Denis Vlasenko | 8d89bed | 2008-09-07 23:22:08 +0000 | [diff] [blame] | 130 | echo "@8,0 :1 644" >mdev.testdir/etc/mdev.conf |
| 131 | testing "mdev #maj,min and no explicit uid" \ |
| 132 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; |
| 133 | ls -lnR mdev.testdir/dev | $FILTER_LS" \ |
| 134 | "\ |
| 135 | mdev.testdir/dev: |
| 136 | brw-r--r-- 1 0 1 8,0 sda |
| 137 | " \ |
| 138 | "" "" |
| 139 | |
Denis Vlasenko | e1caabb | 2008-03-27 20:49:26 +0000 | [diff] [blame] | 140 | # clean up |
| 141 | rm -rf mdev.testdir |
| 142 | |
| 143 | exit $FAILCOUNT |