mount.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
  3. # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
  4. [ -f testing.sh ] && . testing.sh
  5. #testing "name" "command" "result" "infile" "stdin"
  6. root_fs=`df | grep "\/$" | cut -d' ' -f1`
  7. root_fs_type=`blkid -o value $root_fs | tail -1`
  8. tmp_b_fs="tmp_b_fs"
  9. tmp_b_fs_type="ext3"
  10. reCreateTmpFs() {
  11. rm -rf $tmp_b_fs
  12. mknod $tmp_b_fs b 1 0
  13. mkfs.ext3 $tmp_b_fs >/dev/null 2>&1
  14. }
  15. reCreateTmpFs
  16. # TODO: replace /mnt with a directory we know exists. (Android has no /mnt.)
  17. testing "$root_fs /mnt" \
  18. "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  19. sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
  20. testing "$tmp_b_fs /mnt" \
  21. "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  22. sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
  23. reCreateTmpFs
  24. chmod 444 /mnt
  25. testing "$root_fs /mnt (read_only dir)" \
  26. "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  27. sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
  28. testing "$tmp_b_fs /mnt (read_only dir)" \
  29. "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  30. sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
  31. reCreateTmpFs
  32. chmod 755 /mnt
  33. testing "-w $root_fs /mnt (write_only mode)" \
  34. "mount -w $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  35. sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
  36. testing "-w $tmp_b_fs /mnt (write_only mode)" \
  37. "mount -w $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  38. sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
  39. reCreateTmpFs
  40. testing "-rw $tmp_b_fs /mnt (read_write mode)" \
  41. "mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \
  42. sleep 1 && ! test -e /mnt/testDir && umount /mnt" "" "" ""
  43. reCreateTmpFs
  44. testing "$tmp_b_fs /mnt -t fs_type" \
  45. "mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 &&
  46. mkdir /mnt/testDir && sleep 1 && umount /mnt &&
  47. ! test -e /mnt/testDir" "" "" ""
  48. reCreateTmpFs
  49. mkdir -p testDir1/testDir2 testDir
  50. echo "abcdefghijklmnopqrstuvwxyz" > testDir1/testDir2/testFile
  51. testing "-o bind dir1 dir2" \
  52. 'mount -o bind testDir1 testDir >/dev/null 2>&1 && \
  53. cat testDir/testDir2/testFile && sleep 1 && umount testDir' \
  54. "abcdefghijklmnopqrstuvwxyz\n" "" ""
  55. testing "-o rbind dir1 dir2" \
  56. 'mount -o rbind testDir1 testDir >/dev/null 2>&1 && \
  57. cat testDir/testDir2/testFile && sleep 1 && umount testDir' \
  58. "abcdefghijklmnopqrstuvwxyz\n" "" ""
  59. testing "-o loop $tmp_b_fs /mnt" \
  60. "mount -o loop $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDirp &&
  61. sleep 1 && umount -d /mnt && ! test -e /mnt/testDirp" "" "" ""
  62. reCreateTmpFs
  63. mkdir testDir2
  64. testing "-o move mount_1 mount_2" \
  65. "mount $tmp_b_fs testDir1 && mkdir testDir1/testDirr &&
  66. mount -o move testDir1 testDir2 && test -r testDir2/testDirr &&
  67. sleep 1 && umount testDir2" "" "" ""
  68. reCreateTmpFs
  69. testing "-o rw $tmp_b_fs /mnt" \
  70. "mount -o rw $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
  71. sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
  72. reCreateTmpFs
  73. testing "-o ro $tmp_b_fs /mnt" \
  74. "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 &&
  75. mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" ""
  76. reCreateTmpFs
  77. testing "-o ro,remount $tmp_b_fs /mnt" \
  78. "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 &&
  79. mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" ""
  80. reCreateTmpFs
  81. umount testDir1
  82. rm -f $tmp_b_fs