mdev.tests 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-"
  9. # cut: remove size+date
  10. FILTER_LS2="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. testing "mdev add /block/sda" \
  24. "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  25. ls -ln mdev.testdir/dev | $FILTER_LS" \
  26. "\
  27. mdev: /etc/mdev.conf: No such file or directory
  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 - 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 "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
  45. testing "mdev move/symlink rule '>bar/baz'" \
  46. "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  47. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  48. "\
  49. mdev.testdir/dev:
  50. drwxr-xr-x 2 0 0 disk
  51. lrwxrwxrwx 1 0 0 sda -> disk/scsiA
  52. mdev.testdir/dev/disk:
  53. br--r--r-- 1 0 0 scsiA
  54. " \
  55. "" ""
  56. # continuing to use directory structure from prev test
  57. rm -rf mdev.testdir/dev/*
  58. echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
  59. testing "mdev move/symlink rule '>bar/'" \
  60. "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  61. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  62. "\
  63. mdev.testdir/dev:
  64. drwxr-xr-x 2 0 0 disk
  65. lrwxrwxrwx 1 0 0 sda -> disk/sda
  66. mdev.testdir/dev/disk:
  67. br--r--r-- 1 0 0 sda
  68. " \
  69. "" ""
  70. # continuing to use directory structure from prev test
  71. rm -rf mdev.testdir/dev/*
  72. # here we complicate things by having non-matching group 1 and using %0
  73. echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf
  74. testing "mdev regexp substring match + replace" \
  75. "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  76. ls -lnR mdev.testdir/dev | $FILTER_LS2" \
  77. "\
  78. mdev.testdir/dev:
  79. drwxr-xr-x 2 0 0 sd
  80. lrwxrwxrwx 1 0 0 sda -> sd/a_sda
  81. mdev.testdir/dev/sd:
  82. brw-r--r-- 1 0 0 a_sda
  83. " \
  84. "" ""
  85. # continuing to use directory structure from prev test
  86. rm -rf mdev.testdir/dev/*
  87. # here we complicate things by having non-matching group 1 and using %0
  88. echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
  89. testing "mdev command" \
  90. "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
  91. ls -lnR mdev.testdir/dev | $FILTER_LS" \
  92. "\
  93. @echo TEST
  94. mdev.testdir/dev:
  95. brw-r--r-- 1 0 0 8,0 sda
  96. " \
  97. "" ""
  98. # clean up
  99. rm -rf mdev.testdir
  100. exit $FAILCOUNT