mdev.tests 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPL v2, see file LICENSE for details.
  4. . ./testing.sh
  5. # ls -ln is showing date. Need to remove that, it's variable
  6. # sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces
  7. # cut: remove date
  8. FILTER_LS="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-"
  9. # cut: remove size+date
  10. FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-"
  11. # testing "test name" "options" "expected result" "file input" "stdin"
  12. rm -rf mdev.testdir
  13. mkdir mdev.testdir
  14. # We need mdev executable to be in chroot jail!
  15. # (will still fail with dynamically linked one, though...)
  16. cp ../busybox mdev.testdir/mdev
  17. mkdir mdev.testdir/bin
  18. cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature
  19. mkdir mdev.testdir/etc
  20. mkdir mdev.testdir/dev
  21. mkdir -p mdev.testdir/sys/block/sda
  22. echo "8:0" >mdev.testdir/sys/block/sda/dev
  23. # env - PATH=$PATH: on some systems chroot binary won't otherwise be found
  24. testing "mdev add /block/sda" \
  25. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  26. ls -ln mdev.testdir/dev | $FILTER_LS" \
  27. "\
  28. brw-rw---- 1 0 0 8,0 sda
  29. " \
  30. "" ""
  31. # continuing to use directory structure from prev test
  32. rm -rf mdev.testdir/dev/*
  33. echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
  34. echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
  35. testing "mdev stops on first rule" \
  36. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  37. ls -ln mdev.testdir/dev | $FILTER_LS" \
  38. "\
  39. brw-rw-rw- 1 1 1 8,0 sda
  40. " \
  41. "" ""
  42. # continuing to use directory structure from prev test
  43. rm -rf mdev.testdir/dev/*
  44. echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
  45. echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
  46. testing "mdev does not stop on dash-rule" \
  47. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  48. ls -ln mdev.testdir/dev | $FILTER_LS" \
  49. "\
  50. br--r--r-- 1 2 2 8,0 sda
  51. " \
  52. "" ""
  53. # continuing to use directory structure from prev test
  54. rm -rf mdev.testdir/dev/*
  55. echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
  56. echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
  57. echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
  58. testing "mdev \$ENVVAR=regex match" \
  59. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
  60. ls -ln mdev.testdir/dev | $FILTER_LS" \
  61. "\
  62. br--r--r-- 1 2 2 8,0 sda
  63. " \
  64. "" ""
  65. # continuing to use directory structure from prev test
  66. rm -rf mdev.testdir/dev/*
  67. echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
  68. testing "mdev move/symlink rule '>bar/baz'" \
  69. "env - PATH=$PATH 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/scsiA
  75. mdev.testdir/dev/disk:
  76. br--r--r-- 1 0 0 scsiA
  77. " \
  78. "" ""
  79. # continuing to use directory structure from prev test
  80. rm -rf mdev.testdir/dev/*
  81. echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
  82. testing "mdev move/symlink rule '>bar/'" \
  83. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  84. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  85. "\
  86. mdev.testdir/dev:
  87. drwxr-xr-x 2 0 0 disk
  88. lrwxrwxrwx 1 0 0 sda -> disk/sda
  89. mdev.testdir/dev/disk:
  90. br--r--r-- 1 0 0 sda
  91. " \
  92. "" ""
  93. # continuing to use directory structure from prev test
  94. rm -rf mdev.testdir/dev/*
  95. # here we complicate things by having non-matching group 1 and using %0
  96. echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
  97. testing "mdev regexp substring match + replace" \
  98. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  99. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  100. "\
  101. mdev.testdir/dev:
  102. drwxr-xr-x 2 0 0 sd
  103. lrwxrwxrwx 1 0 0 sda -> sd/a_sda
  104. mdev.testdir/dev/sd:
  105. brw-r--r-- 1 0 0 a_sda
  106. " \
  107. "" ""
  108. # continuing to use directory structure from prev test
  109. rm -rf mdev.testdir/dev/*
  110. echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
  111. testing "mdev command" \
  112. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  113. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  114. "\
  115. @echo TEST
  116. mdev.testdir/dev:
  117. brw-r--r-- 1 0 0 8,0 sda
  118. " \
  119. "" ""
  120. # continuing to use directory structure from prev test
  121. rm -rf mdev.testdir/dev/*
  122. echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
  123. testing "mdev move and command" \
  124. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  125. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  126. "\
  127. @echo TEST:block/sda
  128. mdev.testdir/dev:
  129. drwxr-xr-x 2 0 0 block
  130. mdev.testdir/dev/block:
  131. brw-r--r-- 1 0 0 sda
  132. " \
  133. "" ""
  134. # continuing to use directory structure from prev test
  135. rm -rf mdev.testdir/dev/*
  136. echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
  137. testing "mdev #maj,min and no explicit uid" \
  138. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  139. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  140. "\
  141. mdev.testdir/dev:
  142. brw-r--r-- 1 0 1 8,0 sda
  143. " \
  144. "" ""
  145. # continuing to use directory structure from prev test
  146. rm -rf mdev.testdir/dev/*
  147. mkdir -p mdev.testdir/sys/class/tty/capi
  148. echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
  149. mkdir -p mdev.testdir/sys/class/tty/capi1
  150. echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
  151. mkdir -p mdev.testdir/sys/class/tty/capi20
  152. echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
  153. echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
  154. echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
  155. echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
  156. # mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
  157. testing "move rule does not delete node with name == device_name" \
  158. "\
  159. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
  160. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
  161. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
  162. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  163. "\
  164. mdev.testdir/dev:
  165. crw-rw---- 1 0 0 191,0 capi20
  166. crw-rw---- 1 0 0 191,1 capi20.01
  167. crw-rw---- 1 0 0 191,20 capi20.20
  168. " \
  169. "" ""
  170. # clean up
  171. rm -rf mdev.testdir
  172. exit $FAILCOUNT