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