mdev.tests 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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" "commands" "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 FEATURE_LS_SORTFILES
  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 FEATURE_LS_SORTFILES
  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. echo "sda 0:0 444 =disk/sd/a" >mdev.testdir/etc/mdev.conf
  117. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  118. testing "mdev move rule '=bar/baz/fname'" \
  119. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  120. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  121. "\
  122. mdev.testdir/dev:
  123. drwxr-xr-x 3 0 0 disk
  124. mdev.testdir/dev/disk:
  125. drwxr-xr-x 2 0 0 sd
  126. mdev.testdir/dev/disk/sd:
  127. br--r--r-- 1 0 0 a
  128. " \
  129. "" ""
  130. SKIP=
  131. # continuing to use directory structure from prev test
  132. rm -rf mdev.testdir/dev/*
  133. # here we complicate things by having non-matching group 1 and using %0
  134. echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
  135. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
  136. testing "mdev regexp substring match + replace" \
  137. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  138. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  139. "\
  140. mdev.testdir/dev:
  141. drwxr-xr-x 2 0 0 sd
  142. lrwxrwxrwx 1 0 0 sda -> sd/a_sda
  143. mdev.testdir/dev/sd:
  144. brw-r--r-- 1 0 0 a_sda
  145. " \
  146. "" ""
  147. SKIP=
  148. # continuing to use directory structure from prev test
  149. rm -rf mdev.testdir/dev/*
  150. echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
  151. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME SH_IS_ASH ASH_ECHO
  152. testing "mdev command" \
  153. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  154. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  155. "\
  156. @echo TEST
  157. mdev.testdir/dev:
  158. brw-r--r-- 1 0 0 8,0 sda
  159. " \
  160. "" ""
  161. SKIP=
  162. # continuing to use directory structure from prev test
  163. rm -rf mdev.testdir/dev/*
  164. echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
  165. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_EXEC FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME SH_IS_ASH
  166. testing "mdev move and command" \
  167. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  168. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  169. "\
  170. @echo TEST:block/sda
  171. mdev.testdir/dev:
  172. drwxr-xr-x 2 0 0 block
  173. mdev.testdir/dev/block:
  174. brw-r--r-- 1 0 0 sda
  175. " \
  176. "" ""
  177. SKIP=
  178. # continuing to use directory structure from prev test
  179. rm -rf mdev.testdir/dev/*
  180. echo "@8,0 0:1 644" >mdev.testdir/etc/mdev.conf
  181. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME
  182. testing "mdev #maj,min and no explicit uid" \
  183. "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  184. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  185. "\
  186. mdev.testdir/dev:
  187. brw-r--r-- 1 0 1 8,0 sda
  188. " \
  189. "" ""
  190. SKIP=
  191. # continuing to use directory structure from prev test
  192. rm -rf mdev.testdir/dev/*
  193. mkdir -p mdev.testdir/sys/class/tty/capi
  194. echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
  195. mkdir -p mdev.testdir/sys/class/tty/capi1
  196. echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
  197. mkdir -p mdev.testdir/sys/class/tty/capi20
  198. echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
  199. echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
  200. echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
  201. echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
  202. # mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
  203. optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES
  204. testing "move rule does not delete node with name == device_name" \
  205. "\
  206. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
  207. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
  208. env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
  209. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  210. "\
  211. mdev.testdir/dev:
  212. crw-rw---- 1 0 0 191,0 capi20
  213. crw-rw---- 1 0 0 191,1 capi20.01
  214. crw-rw---- 1 0 0 191,20 capi20.20
  215. " \
  216. "" ""
  217. SKIP=
  218. # clean up
  219. rm -rf mdev.testdir
  220. exit $FAILCOUNT