vi: fixes to string search in colon commands, closes 10321
[oweals/busybox.git] / testsuite / mount.tests
1 #!/bin/sh
2 # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com>
3 # Licensed under GPLv2, see file LICENSE in this source tree.
4
5 . ./testing.sh
6 test -f "$bindir/.config" && . "$bindir/.config"
7
8 test "`id -u`" = 0 || {
9         echo "SKIPPED: mount (must be root to test this)"
10         exit 0
11 }
12
13 # Without MOUNT_LOOP_CREATE, the test will fail if /dev/loopN's do not exist
14 if test x"$CONFIG_MKFS_MINIX" != x"y" \
15 || test x"$CONFIG_FEATURE_MINIX2" != x"y" \
16 || test x"$CONFIG_FEATURE_MOUNT_LOOP" != x"y" \
17 || test x"$CONFIG_FEATURE_MOUNT_LOOP_CREATE" != x"y" \
18 || test x"$CONFIG_FEATURE_MOUNT_FLAGS" != x"y" \
19 || test x"$CONFIG_FEATURE_DEVFS" = x"y" \
20 ; then
21         echo "SKIPPED: mount"
22         exit 0
23 fi
24
25 testdir="$PWD/mount.testdir"
26
27 dd if=/dev/zero of=mount.image1m count=1 bs=1M 2>/dev/null || { echo "dd error"; exit 1; }
28 mkfs.minix -v mount.image1m >/dev/null 2>&1 || { echo "mkfs.minix error"; exit 1; }
29 modprobe minix 2>/dev/null
30 mkdir "$testdir" 2>/dev/null
31 umount -d "$testdir" 2>/dev/null
32
33 # testing "test name" "command" "expected result" "file input" "stdin"
34 #   file input will be file called "input"
35 #   test can create a file "actual" instead of writing to stdout
36
37 testing "mount -o remount,mand" \
38 "mount -o loop mount.image1m $testdir "\
39 "&& grep -Fc $testdir </proc/mounts "\
40 "&& mount -o remount,mand $testdir "\
41 "&& grep -F $testdir </proc/mounts | grep -c '[, ]mand[, ]'"\
42 "|| grep -F $testdir </proc/mounts" \
43         "1\n""1\n" \
44         "" ""
45
46 umount -d "$testdir"
47 rmdir "$testdir"
48 rm mount.image1m
49
50
51 # Bug: mount.shared1 directory shows no files (has to show files a and b)
52 optional FEATURE_LS_RECURSIVE FEATURE_LS_SORTFILES
53 testing "mount bind+rshared" "\
54 mkdir -p mount.dir mount.shared1 mount.shared2
55 touch mount.dir/a mount.dir/b
56
57 mount --bind         mount.shared1 mount.shared1 2>&1
58 mount --make-rshared mount.shared1               2>&1
59 mount --bind         mount.shared2 mount.shared2 2>&1
60 mount --make-rshared mount.shared2               2>&1
61
62 mount --bind mount.shared2 mount.shared1         2>&1
63 mount --bind mount.dir     mount.shared2         2>&1
64
65 ls -R mount.dir mount.shared1 mount.shared2      2>&1
66
67 umount mount.dir mount.shared1 mount.shared2 2>/dev/null
68 umount mount.dir mount.shared1 mount.shared2 2>/dev/null
69 umount mount.dir mount.shared1 mount.shared2 2>/dev/null
70 rm -f mount.dir/a mount.dir/b mount.dir/c
71 rmdir mount.dir mount.shared1 mount.shared2
72 " \
73 "\
74 mount.dir:
75 a
76 b
77
78 mount.shared1:
79 a
80 b
81
82 mount.shared2:
83 a
84 b
85 " \
86         "" ""
87 SKIP=
88
89
90 testing "mount RO loop" "\
91 exec 2>&1
92 umount -d mount.dir 2>/dev/null
93 rmdir mount.dir     2>/dev/null
94 mkdir -p mount.dir
95 (
96 cd mount.dir                               || { echo 'cd error'; exit 1; }
97 mkdir z1 z2                                || { echo 'mkdir error'; exit 1; }
98 mount -t tmpfs tmpfs z1                    || { echo 'mount tmpfs error'; exit 1; }
99 dd if=/dev/zero of=z1/e2img count=10 bs=1M 2>/dev/null || { echo 'dd error'; exit 1; }
100 mke2fs -F z1/e2img                         2>/dev/null >&2 || { echo 'mke2fs error'; exit 1; }
101 mount -r -o loop -t ext2 z1/e2img z2       || { echo 'mount -r -o loop error'; exit 1; }
102 mount -o remount,ro z1                     || { echo 'mount -o remount,ro error'; exit 1; }
103 )
104 umount -d mount.dir/z2
105 ##losetup -d /dev/loop*
106 umount -d mount.dir/z1
107 rm -rf mount.dir
108 echo DONE
109 " \
110 "DONE\n" "" ""
111
112
113 exit $FAILCOUNT