xref: /aosp_15_r20/external/toybox/tests/mount.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker# Copyright 2013 Divya Kothari <[email protected]>
4*cf5a6c84SAndroid Build Coastguard Worker# Copyright 2013 Robin Mittal <[email protected]>
5*cf5a6c84SAndroid Build Coastguard Worker
6*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
7*cf5a6c84SAndroid Build Coastguard Worker
8*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
9*cf5a6c84SAndroid Build Coastguard Worker
10*cf5a6c84SAndroid Build Coastguard Workerroot_fs=`df | grep "\/$" | cut -d' ' -f1`
11*cf5a6c84SAndroid Build Coastguard Workerroot_fs_type=`blkid -o value $root_fs | tail -1`
12*cf5a6c84SAndroid Build Coastguard Worker
13*cf5a6c84SAndroid Build Coastguard Workertmp_b_fs="tmp_b_fs"
14*cf5a6c84SAndroid Build Coastguard Workertmp_b_fs_type="ext3"
15*cf5a6c84SAndroid Build Coastguard Worker
16*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs() {
17*cf5a6c84SAndroid Build Coastguard Worker  rm -rf $tmp_b_fs
18*cf5a6c84SAndroid Build Coastguard Worker  mknod $tmp_b_fs b 1 0
19*cf5a6c84SAndroid Build Coastguard Worker  mkfs.ext3 $tmp_b_fs >/dev/null 2>&1
20*cf5a6c84SAndroid Build Coastguard Worker}
21*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
22*cf5a6c84SAndroid Build Coastguard Worker
23*cf5a6c84SAndroid Build Coastguard Worker# TODO: replace /mnt with a directory we know exists. (Android has no /mnt.)
24*cf5a6c84SAndroid Build Coastguard Worker
25*cf5a6c84SAndroid Build Coastguard Workertesting "$root_fs /mnt" \
26*cf5a6c84SAndroid Build Coastguard Worker  "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
27*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
28*cf5a6c84SAndroid Build Coastguard Workertesting "$tmp_b_fs /mnt" \
29*cf5a6c84SAndroid Build Coastguard Worker  "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
30*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
31*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
32*cf5a6c84SAndroid Build Coastguard Worker
33*cf5a6c84SAndroid Build Coastguard Workerchmod 444 /mnt
34*cf5a6c84SAndroid Build Coastguard Workertesting "$root_fs /mnt (read_only dir)" \
35*cf5a6c84SAndroid Build Coastguard Worker  "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
36*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
37*cf5a6c84SAndroid Build Coastguard Workertesting "$tmp_b_fs /mnt (read_only dir)" \
38*cf5a6c84SAndroid Build Coastguard Worker  "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
39*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
40*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
41*cf5a6c84SAndroid Build Coastguard Workerchmod 755 /mnt
42*cf5a6c84SAndroid Build Coastguard Workertesting "-w $root_fs /mnt (write_only mode)" \
43*cf5a6c84SAndroid Build Coastguard Worker  "mount -w $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
44*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" ""
45*cf5a6c84SAndroid Build Coastguard Workertesting "-w $tmp_b_fs /mnt (write_only mode)" \
46*cf5a6c84SAndroid Build Coastguard Worker  "mount -w $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
47*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
48*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
49*cf5a6c84SAndroid Build Coastguard Workertesting "-rw $tmp_b_fs /mnt (read_write mode)" \
50*cf5a6c84SAndroid Build Coastguard Worker  "mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \
51*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && ! test -e /mnt/testDir && umount /mnt" "" "" ""
52*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
53*cf5a6c84SAndroid Build Coastguard Workertesting "$tmp_b_fs /mnt -t fs_type" \
54*cf5a6c84SAndroid Build Coastguard Worker  "mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 &&
55*cf5a6c84SAndroid Build Coastguard Worker   mkdir /mnt/testDir && sleep 1 && umount /mnt &&
56*cf5a6c84SAndroid Build Coastguard Worker   ! test -e /mnt/testDir" "" "" ""
57*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
58*cf5a6c84SAndroid Build Coastguard Workermkdir -p testDir1/testDir2 testDir
59*cf5a6c84SAndroid Build Coastguard Workerecho "abcdefghijklmnopqrstuvwxyz" > testDir1/testDir2/testFile
60*cf5a6c84SAndroid Build Coastguard Workertesting "-o bind dir1 dir2" \
61*cf5a6c84SAndroid Build Coastguard Worker  'mount -o bind testDir1 testDir >/dev/null 2>&1 && \
62*cf5a6c84SAndroid Build Coastguard Worker   cat testDir/testDir2/testFile && sleep 1 && umount testDir' \
63*cf5a6c84SAndroid Build Coastguard Worker  "abcdefghijklmnopqrstuvwxyz\n" "" ""
64*cf5a6c84SAndroid Build Coastguard Workertesting "-o rbind dir1 dir2" \
65*cf5a6c84SAndroid Build Coastguard Worker  'mount -o rbind testDir1 testDir >/dev/null 2>&1 && \
66*cf5a6c84SAndroid Build Coastguard Worker   cat testDir/testDir2/testFile && sleep 1 && umount testDir' \
67*cf5a6c84SAndroid Build Coastguard Worker  "abcdefghijklmnopqrstuvwxyz\n" "" ""
68*cf5a6c84SAndroid Build Coastguard Workertesting "-o loop $tmp_b_fs /mnt" \
69*cf5a6c84SAndroid Build Coastguard Worker  "mount -o loop $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDirp &&
70*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount -d /mnt && ! test -e /mnt/testDirp" "" "" ""
71*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
72*cf5a6c84SAndroid Build Coastguard Worker
73*cf5a6c84SAndroid Build Coastguard Workermkdir testDir2
74*cf5a6c84SAndroid Build Coastguard Workertesting "-o move mount_1 mount_2" \
75*cf5a6c84SAndroid Build Coastguard Worker  "mount $tmp_b_fs testDir1 && mkdir testDir1/testDirr &&
76*cf5a6c84SAndroid Build Coastguard Worker   mount -o move testDir1 testDir2 && test -r testDir2/testDirr &&
77*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount testDir2" "" "" ""
78*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
79*cf5a6c84SAndroid Build Coastguard Workertesting "-o rw $tmp_b_fs /mnt" \
80*cf5a6c84SAndroid Build Coastguard Worker  "mount -o rw $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir &&
81*cf5a6c84SAndroid Build Coastguard Worker   sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
82*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
83*cf5a6c84SAndroid Build Coastguard Workertesting "-o ro $tmp_b_fs /mnt" \
84*cf5a6c84SAndroid Build Coastguard Worker  "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 &&
85*cf5a6c84SAndroid Build Coastguard Worker   mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" ""
86*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
87*cf5a6c84SAndroid Build Coastguard Workertesting "-o ro,remount $tmp_b_fs /mnt" \
88*cf5a6c84SAndroid Build Coastguard Worker  "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 &&
89*cf5a6c84SAndroid Build Coastguard Worker   mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" ""
90*cf5a6c84SAndroid Build Coastguard WorkerreCreateTmpFs
91*cf5a6c84SAndroid Build Coastguard Worker
92*cf5a6c84SAndroid Build Coastguard Workerumount testDir1
93*cf5a6c84SAndroid Build Coastguard Workerrm -f $tmp_b_fs
94