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 "\/$" | awk '{print $1}'` 11 root_fs_type=`file -sL $root_fs | awk '{print $5}'` 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 testing "mount $root_fs /mnt" \ 24 "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 25 sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" 26 testing "mount $tmp_b_fs /mnt" \ 27 "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 28 sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" 29 reCreateTmpFs 30 31 chmod 444 /mnt 32 testing "mount $root_fs /mnt (read_only dir)" \ 33 "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 34 sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" 35 testing "mount $tmp_b_fs /mnt (read_only dir)" \ 36 "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 37 sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" 38 reCreateTmpFs 39 chmod 755 /mnt 40 testing "mount -w $root_fs /mnt (write_only mode)" \ 41 "mount -w $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 42 sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" 43 testing "mount -w $tmp_b_fs /mnt (write_only mode)" \ 44 "mount -w $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 45 sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" 46 reCreateTmpFs 47 testing "mount -rw $tmp_b_fs /mnt (read_write mode)" \ 48 'mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \ 49 sleep 1 && ! test -e /mnt/testDir && umount /mnt' "" "" "" 50 reCreateTmpFs 51 testing "mount $tmp_b_fs /mnt -t fs_type" \ 52 "mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 && 53 mkdir /mnt/testDir && sleep 1 && umount /mnt && 54 ! test -e /mnt/testDir" "" "" "" 55 reCreateTmpFs 56 mkdir -p testDir1/testDir2 testDir 57 echo "abcdefghijklmnopqrstuvwxyz" > testDir1/testDir2/testFile 58 testing "mount -o bind dir1 dir2" \ 59 'mount -o bind testDir1 testDir >/dev/null 2>&1 && \ 60 cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ 61 "abcdefghijklmnopqrstuvwxyz\n" "" "" 62 testing "mount -o rbind dir1 dir2" \ 63 'mount -o rbind testDir1 testDir >/dev/null 2>&1 && \ 64 cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ 65 "abcdefghijklmnopqrstuvwxyz\n" "" "" 66 testing "mount -o loop $tmp_b_fs /mnt" \ 67 "mount -o loop $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDirp && 68 sleep 1 && umount -d /mnt && ! test -e /mnt/testDirp" "" "" "" 69 reCreateTmpFs 70 71 mkdir testDir2 72 testing "mount -o move mount_1 mount_2" \ 73 "mount $tmp_b_fs testDir1 && mkdir testDir1/testDirr && 74 mount -o move testDir1 testDir2 && test -r testDir2/testDirr && 75 sleep 1 && umount testDir2" "" "" "" 76 reCreateTmpFs 77 testing "mount -o rw $tmp_b_fs /mnt" \ 78 "mount -o rw $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && 79 sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" 80 reCreateTmpFs 81 testing "mount -o ro $tmp_b_fs /mnt" \ 82 "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 && 83 mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" "" 84 reCreateTmpFs 85 testing "mount -o ro,remount $tmp_b_fs /mnt" \ 86 "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 && 87 mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" "" 88 reCreateTmpFs 89 90 umount testDir1 91 rm -f $tmp_b_fs 92