mdev.tests 7.4 KB

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