3
0

mdev.tests 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  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. optional STATIC FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  25. testing "mdev add /block/sda" \
  26. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  27. ls -ln mdev.testdir/dev | $FILTER_LS" \
  28. "\
  29. brw-rw---- 1 0 0 8,0 sda
  30. " \
  31. "" ""
  32. SKIP=
  33. # continuing to use directory structure from prev test
  34. optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  35. testing "mdev deletes /block/sda" \
  36. "env - PATH=$PATH ACTION=remove DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  37. ls -ln mdev.testdir/dev | $FILTER_LS" \
  38. "\
  39. " \
  40. "" ""
  41. SKIP=
  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. optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  47. testing "mdev stops on first rule" \
  48. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  49. ls -ln mdev.testdir/dev | $FILTER_LS" \
  50. "\
  51. brw-rw-rw- 1 1 1 8,0 sda
  52. " \
  53. "" ""
  54. SKIP=
  55. # continuing to use directory structure from prev test
  56. rm -rf mdev.testdir/dev/*
  57. echo "-.* 1:1 666" >mdev.testdir/etc/mdev.conf
  58. echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
  59. optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  60. testing "mdev does not stop on dash-rule" \
  61. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  62. ls -ln mdev.testdir/dev | $FILTER_LS" \
  63. "\
  64. br--r--r-- 1 2 2 8,0 sda
  65. " \
  66. "" ""
  67. SKIP=
  68. # continuing to use directory structure from prev test
  69. rm -rf mdev.testdir/dev/*
  70. echo "\$MODALIAS=qw 1:1 666" >mdev.testdir/etc/mdev.conf
  71. echo "\$MODALIAS=qw. 2:2 444" >>mdev.testdir/etc/mdev.conf
  72. echo "\$MODALIAS=qw. 3:3 400" >>mdev.testdir/etc/mdev.conf
  73. optional STATIC FEATURE_MDEV_CONF FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  74. testing "mdev \$ENVVAR=regex match" \
  75. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda MODALIAS=qwe chroot mdev.testdir /mdev 2>&1;
  76. ls -ln mdev.testdir/dev | $FILTER_LS" \
  77. "\
  78. br--r--r-- 1 2 2 8,0 sda
  79. " \
  80. "" ""
  81. SKIP=
  82. # continuing to use directory structure from prev test
  83. rm -rf mdev.testdir/dev/*
  84. echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
  85. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  86. testing "mdev move/symlink rule '>bar/baz'" \
  87. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  88. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  89. "\
  90. mdev.testdir/dev:
  91. drwxr-xr-x 2 0 0 disk
  92. lrwxrwxrwx 1 0 0 sda -> disk/scsiA
  93. mdev.testdir/dev/disk:
  94. br--r--r-- 1 0 0 scsiA
  95. " \
  96. "" ""
  97. SKIP=
  98. # continuing to use directory structure from prev test
  99. rm -rf mdev.testdir/dev/*
  100. echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
  101. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  102. testing "mdev move/symlink rule '>bar/'" \
  103. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  104. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  105. "\
  106. mdev.testdir/dev:
  107. drwxr-xr-x 2 0 0 disk
  108. lrwxrwxrwx 1 0 0 sda -> disk/sda
  109. mdev.testdir/dev/disk:
  110. br--r--r-- 1 0 0 sda
  111. " \
  112. "" ""
  113. SKIP=
  114. # continuing to use directory structure from prev test
  115. rm -rf mdev.testdir/dev/*
  116. # here we complicate things by having non-matching group 1 and using %0
  117. echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
  118. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
  119. testing "mdev regexp substring match + replace" \
  120. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  121. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  122. "\
  123. mdev.testdir/dev:
  124. drwxr-xr-x 2 0 0 sd
  125. lrwxrwxrwx 1 0 0 sda -> sd/a_sda
  126. mdev.testdir/dev/sd:
  127. brw-r--r-- 1 0 0 a_sda
  128. " \
  129. "" ""
  130. SKIP=
  131. # continuing to use directory structure from prev test
  132. rm -rf mdev.testdir/dev/*
  133. echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
  134. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_SH_IS_ASH
  135. testing "mdev command" \
  136. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  137. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  138. "\
  139. @echo TEST
  140. mdev.testdir/dev:
  141. brw-r--r-- 1 0 0 8,0 sda
  142. " \
  143. "" ""
  144. SKIP=
  145. # continuing to use directory structure from prev test
  146. rm -rf mdev.testdir/dev/*
  147. echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
  148. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_SH_IS_ASH
  149. testing "mdev move and command" \
  150. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  151. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  152. "\
  153. @echo TEST:block/sda
  154. mdev.testdir/dev:
  155. drwxr-xr-x 2 0 0 block
  156. mdev.testdir/dev/block:
  157. brw-r--r-- 1 0 0 sda
  158. " \
  159. "" ""
  160. SKIP=
  161. # continuing to use directory structure from prev test
  162. rm -rf mdev.testdir/dev/*
  163. echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
  164. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  165. testing "mdev #maj,min and no explicit uid" \
  166. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  167. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  168. "\
  169. mdev.testdir/dev:
  170. brw-r--r-- 1 0 1 8,0 sda
  171. " \
  172. "" ""
  173. SKIP=
  174. # continuing to use directory structure from prev test
  175. rm -rf mdev.testdir/dev/*
  176. mkdir -p mdev.testdir/sys/class/tty/capi
  177. echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
  178. mkdir -p mdev.testdir/sys/class/tty/capi1
  179. echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
  180. mkdir -p mdev.testdir/sys/class/tty/capi20
  181. echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
  182. echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
  183. echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
  184. echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
  185. # mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
  186. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
  187. testing "move rule does not delete node with name == device_name" \
  188. "\
  189. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
  190. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
  191. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
  192. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  193. "\
  194. mdev.testdir/dev:
  195. crw-rw---- 1 0 0 191,0 capi20
  196. crw-rw---- 1 0 0 191,1 capi20.01
  197. crw-rw---- 1 0 0 191,20 capi20.20
  198. " \
  199. "" ""
  200. SKIP=
  201. # clean up
  202. rm -rf mdev.testdir
  203. exit $FAILCOUNT