mount.testroot 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/sh
  2. # SUSv3 compliant mount and umount tests.
  3. # Copyright 2005 by Rob Landley <rob@landley.net>
  4. # Licensed under GPL v2, see file LICENSE for details.
  5. if [ -z "$TESTDIR" ]
  6. then
  7. echo 'Need $TESTDIR'
  8. exit 1
  9. fi
  10. cd "$TESTDIR"
  11. . testing.sh
  12. # If we aren't PID 1, barf.
  13. #if [ $$ -ne 1 ]
  14. #then
  15. # echo "SKIPPED: mount test requires emulation environment"
  16. # exit 0
  17. #fi
  18. # Run tests within the chroot environment.
  19. dochroot bash rm ls ln cat ps mknod mkdir dd grep cmp diff tail \
  20. mkfs.ext2 mkfs.vfat mount umount losetup wc << EOF
  21. #!/bin/bash
  22. . /testing.sh
  23. mknod /dev/loop0 b 7 0
  24. mknod /dev/loop1 b 7 1
  25. # We need /proc to do much. Make sure we can mount it explicitly.
  26. testing "mount no proc [GNUFAIL]" "mount 2> /dev/null || echo yes" "yes\n" "" ""
  27. testing "mount /proc" "mount -t proc /proc /proc && ls -d /proc/1" \
  28. "/proc/1\n" "" ""
  29. # Make sure the last thing in the list is /proc
  30. testing "mount list1" "mount | tail -n 1" "/proc on /proc type proc (rw)\n" \
  31. "" ""
  32. # Create an ext2 image
  33. mkdir -p images/{ext2.dir,vfat.dir,test1,test2,test3}
  34. dd if=/dev/zero of=images/ext2.img bs=1M count=1 2> /dev/null
  35. mkfs.ext2 -F -b 1024 images/ext2.img > /dev/null 2> /dev/null
  36. dd if=/dev/zero of=images/vfat.img bs=1M count=1 2> /dev/null
  37. mkfs.vfat images/vfat.img > /dev/null
  38. # Test mount it
  39. testing "mount vfat image (explicitly autodetect type)" \
  40. "mount -t auto images/vfat.img images/vfat.dir && mount | tail -n 1 | grep -o 'vfat.dir type vfat'" \
  41. "vfat.dir type vfat\n" "" ""
  42. testing "mount ext2 image (autodetect type)" \
  43. "mount images/ext2.img images/ext2.dir 2> /dev/null && mount | tail -n 1" \
  44. "/dev/loop1 on /images/ext2.dir type ext2 (rw)\n" "" ""
  45. testing "mount remount ext2 image noatime" \
  46. "mount -o remount,noatime images/ext2.dir && mount | tail -n 1" \
  47. "/dev/loop1 on /images/ext2.dir type ext2 (rw,noatime)\n" "" ""
  48. testing "mount remount ext2 image ro remembers noatime" \
  49. "mount -o remount,ro images/ext2.dir && mount | tail -n 1" \
  50. "/dev/loop1 on /images/ext2.dir type ext2 (ro,noatime)\n" "" ""
  51. umount -d images/vfat.dir
  52. umount -d images/ext2.dir
  53. testing "mount umount freed loop device" \
  54. "mount images/ext2.img images/ext2.dir && mount | tail -n 1" \
  55. "/dev/loop0 on /images/ext2.dir type ext2 (rw)\n" "" ""
  56. testing "mount block device" \
  57. "mount -t ext2 /dev/loop0 images/test1 && mount | tail -n 1" \
  58. "/dev/loop0 on /images/test1 type ext2 (rw)\n" "" ""
  59. umount -d images/ext2.dir images/test1
  60. testing "mount remount nonexistent directory" \
  61. "mount -o remount,noatime images/ext2.dir 2> /dev/null || echo yes" \
  62. "yes\n" "" ""
  63. # Fun with mount -a
  64. testing "mount -a no fstab" "mount -a 2>/dev/null || echo yes" "yes\n" "" ""
  65. umount /proc
  66. # The first field is space delimited, the rest tabs.
  67. cat > /etc/fstab << FSTAB
  68. /proc /proc proc defaults 0 0
  69. # Autodetect loop, and provide flags with commas in them.
  70. /images/ext2.img /images/ext2.dir ext2 noatime,nodev 0 0
  71. # autodetect filesystem, flags without commas.
  72. /images/vfat.img /images/vfat.dir auto ro 0 0
  73. # A block device
  74. /dev/loop2 /images/test1 auto defaults 0 0
  75. # tmpfs, filesystem specific flag.
  76. walrus /images/test2 tmpfs size=42 0 0
  77. # Autodetect a bind mount.
  78. /images/test2 /images/test3 auto defaults 0 0
  79. FSTAB
  80. # Put something on loop2.
  81. mknod /dev/loop2 b 7 2
  82. cat images/ext2.img > images/ext2-2.img
  83. losetup /dev/loop2 images/ext2-2.img
  84. testing "mount -a" "mount -a && echo hello > /images/test2/abc && cat /images/test3/abc && (mount | wc -l)" "hello\n8\n" "" ""
  85. testing "umount -a" "umount -a && ls /proc" "" "" ""
  86. #/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
  87. mknod /dev/console c 5 1
  88. /bin/bash < /dev/console > /dev/console 2> /dev/console
  89. EOF
  90. exit 0
  91. # Run some tests
  92. losetup nonexistent device (should return error 2)
  93. losetup unbound loop device (should return error 1)
  94. losetup bind file to loop device
  95. losetup bound loop device (display) (should return error 0)
  96. losetup filename (error)
  97. losetup nofile (file not found)
  98. losetup -d
  99. losetup bind with offset
  100. losetup -f (print first loop device)
  101. losetup -f filename (associate file with first loop device)
  102. losetup -o (past end of file) -f filename
  103. mount -a
  104. with multiple entries in fstab
  105. with duplicate entries in fstab
  106. with relative paths in fstab
  107. with user entries in fstab
  108. mount -o async,sync,atime,noatime,dev,nodev,exec,noexec,loop,suid,nosuid,remount,ro,rw,bind,move
  109. mount -r
  110. mount -o rw -r
  111. mount -w -o ro
  112. mount -t auto
  113. mount with relative path in fstab
  114. mount block device
  115. mount char device
  116. mount file (autoloop)
  117. mount directory (autobind)
  118. testing "umount with no /proc"
  119. testing "umount curdir"
  120. # The basic tests. These should work even with the small busybox.
  121. testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" ""
  122. testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" ""
  123. testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n"
  124. testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" ""
  125. testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \
  126. "point\nwook\npabst\naargh\nwalrus\n" ""
  127. optional FEATURE_MOUNT_LOOP
  128. testing "umount -D"
  129. optional FEATURE_MTAB_SUPPORT
  130. optional FEATURE_MOUNT_NFS
  131. # No idea what to test here.
  132. optional UMOUNT
  133. optional FEATURE_UMOUNT_ALL
  134. testing "umount -a"
  135. testing "umount -r"
  136. testing "umount -l"
  137. testing "umount -f"
  138. exit $FAILCOUNT