diff options
author | Mark Glines <mark@glines.org> | 2002-04-22 02:24:28 +0000 |
---|---|---|
committer | Mark Glines <mark@glines.org> | 2002-04-22 02:24:28 +0000 |
commit | 8811161f67657253d11214ede54857f810662a91 (patch) | |
tree | 1f555243af88b77fcea3d256f6f7b8b5f1c05548 /perl/test | |
parent | 7574b0559706597058a9cb3c056204935f9b00c5 (diff) | |
download | libfuse-8811161f67657253d11214ede54857f810662a91.tar.gz |
added a test framework
updated README
fixed a couple of bugs in loopback.pl
Diffstat (limited to 'perl/test')
-rw-r--r-- | perl/test/chmod.t | 11 | ||||
-rw-r--r-- | perl/test/chown.t | 14 | ||||
-rw-r--r-- | perl/test/getattr.t | 42 | ||||
-rw-r--r-- | perl/test/getdir.t | 33 | ||||
-rw-r--r-- | perl/test/helper.pm | 23 | ||||
-rw-r--r-- | perl/test/link.t | 16 | ||||
-rw-r--r-- | perl/test/mkdir.t | 11 | ||||
-rw-r--r-- | perl/test/mknod.t | 37 | ||||
-rw-r--r-- | perl/test/open.t | 10 | ||||
-rw-r--r-- | perl/test/read.t | 13 | ||||
-rw-r--r-- | perl/test/readlink.t | 11 | ||||
-rw-r--r-- | perl/test/rename.t | 12 | ||||
-rw-r--r-- | perl/test/rmdir.t | 13 | ||||
-rw-r--r-- | perl/test/s/mount.t | 26 | ||||
-rw-r--r-- | perl/test/s/umount.t | 7 | ||||
-rw-r--r-- | perl/test/statfs.t | 21 | ||||
-rw-r--r-- | perl/test/symlink.t | 12 | ||||
-rw-r--r-- | perl/test/test-template | 5 | ||||
-rw-r--r-- | perl/test/truncate.t | 12 | ||||
-rw-r--r-- | perl/test/unlink.t | 14 | ||||
-rw-r--r-- | perl/test/utime.t | 13 | ||||
-rw-r--r-- | perl/test/write.t | 45 |
22 files changed, 401 insertions, 0 deletions
diff --git a/perl/test/chmod.t b/perl/test/chmod.t new file mode 100644 index 0000000..366f89b --- /dev/null +++ b/perl/test/chmod.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 4; +chdir($_point); +system("echo frog >file"); +ok(chmod(0644,"file"),"set unexecutable"); +ok(!-x "file","unexecutable"); +ok(chmod(0755,"file"),"set executable"); +ok(-x "file","executable"); +unlink("file"); diff --git a/perl/test/chown.t b/perl/test/chown.t new file mode 100644 index 0000000..8ccbb88 --- /dev/null +++ b/perl/test/chown.t @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 4; +my (@stat); +chdir($_point); +system("echo frog >file"); +ok(chown(0,0,"file"),"set 0,0"); +@stat = stat("file"); +ok($stat[4] == 0 && $stat[5] == 0,"0,0"); +ok(chown(1,1,"file"),"set 1,1"); +@stat = stat("file"); +ok($stat[4] == 1 && $stat[5] == 1,"1,1"); +unlink("file"); diff --git a/perl/test/getattr.t b/perl/test/getattr.t new file mode 100644 index 0000000..49eef14 --- /dev/null +++ b/perl/test/getattr.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +use Data::Dumper; +plan tests => 28; +my ($a, $b) = ("$_real/wibble","$_point/wibble"); +`touch $a; sleep 1; cat $a >/dev/null`; +is(-A "$a", -A "$b", '-A'); # 1 +is(-B "$a", -B "$b", '-B'); # 2 +is(-C "$a", -C "$b", '-C'); # 3 +is(-M "$a", -M "$b", '-M'); # 4 +is(-O "$a", -O "$b", '-O'); # 5 +is(-R "$a", -R "$b", '-R'); # 6 +is(-S "$a", -S "$b", '-S'); # 7 +is(-T "$a", -T "$b", '-T'); # 8 +is(-W "$a", -W "$b", '-W'); # 9 +is(-X "$a", -X "$b", '-X'); # 10 +is(-b "$a", -b "$b", '-b'); # 11 +is(-c "$a", -c "$b", '-c'); # 12 +is(-d "$a", -d "$b", '-d'); # 13 +is(-e "$a", -e "$b", '-e'); # 14 +is(-f "$a", -f "$b", '-f'); # 15 +is(-g "$a", -g "$b", '-g'); # 16 +is(-k "$a", -k "$b", '-k'); # 17 +is(-l "$a", -l "$b", '-l'); # 18 +is(-o "$a", -o "$b", '-o'); # 19 +is(-p "$a", -p "$b", '-p'); # 20 +is(-r "$a", -r "$b", '-r'); # 21 +is(-s "$a", -s "$b", '-s'); # 22 +is(-t "$a", -t "$b", '-t'); # 23 +is(-u "$a", -u "$b", '-u'); # 24 +is(-w "$a", -w "$b", '-w'); # 25 +is(-x "$a", -x "$b", '-x'); # 26 +is(-z "$a", -z "$b", '-z'); # 27 +my (@astat, @bstat); +@astat = stat("$a"); +@bstat = stat("$b"); +# dev and inode can legally change +shift(@astat); shift(@astat); +shift(@bstat); shift(@bstat); +is(join(" ",@astat),join(" ",@bstat),"stat()"); +`rm -f $a`; diff --git a/perl/test/getdir.t b/perl/test/getdir.t new file mode 100644 index 0000000..1d60561 --- /dev/null +++ b/perl/test/getdir.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +my (@names) = qw(abc def ghi jkl mno pqr stu jlk sfdaljk sdfakjlsdfa kjldsf kjl;sdf akjl;asdf klj;asdf lkjsdflkjsdfkjlsdfakjsdfakjlsadfkjl;asdfklj;asdfkjl;asdfklj;asdfkjl;asdfkjlasdflkj;sadf); +@names = sort(@names); +plan tests => 2 * scalar @names; +chdir($_real); + +# create entries +map { system("touch \"$_\"") } @names; + +# make sure they exist in real dir +opendir(REAL,$_real); +my (@ents) = readdir(REAL); +closedir(REAL); +@ents = sort(@ents); +map { + shift(@ents) while($ents[0] eq '.' || $ents[0] eq '..'); + is(shift(@ents),$_,"ent $_") +} @names; + +# make sure they exist in fuse dir +opendir(POINT,$_point); +@ents = readdir(POINT); +closedir(POINT); +@ents = sort(@ents); +map { + shift(@ents) while($ents[0] eq '.' || $ents[0] eq '..'); + is(shift(@ents),$_,"ent $_") +} @names; + +# remove them +map { unlink } @names; diff --git a/perl/test/helper.pm b/perl/test/helper.pm new file mode 100644 index 0000000..3d980ec --- /dev/null +++ b/perl/test/helper.pm @@ -0,0 +1,23 @@ +#!/usr/bin/perl +package test::helper; +use strict; +use Exporter; +our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); +@ISA = "Exporter"; +@EXPORT_OK = qw($_loop $_point $_pidfile $_real); +our($_loop, $_point, $_pidfile, $_real) = ("loopback.pl","/mnt","test/s/mounted.pid","/tmp/fusetest"); +if($0 !~ qr|s/u?mount\.t$|) { + my ($reject) = 1; + if(-f $_pidfile) { + unless(system("ps `cat $_pidfile` | grep \"$_loop $_point\" >/dev/null")>>8) { + if(`mount | grep "on $_point"`) { + $reject = 0; + } else { + system("kill `cat $_pidfile`"); + } + } + } + $reject = 0 if (system("ls $_point >&/dev/null") >> 8); + die "not properly mounted\n" if $reject; +} +1; diff --git a/perl/test/link.t b/perl/test/link.t new file mode 100644 index 0000000..391b2f0 --- /dev/null +++ b/perl/test/link.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 8; +chdir($_point); +system("echo hippity >womble"); +ok(-f "womble","exists"); +ok(!-f "rabbit","target file doesn't exist"); +is(-s "womble",8,"right size"); +ok(link("womble","rabbit"),"link"); +ok(-f "womble","old file exists"); +ok(-f "rabbit","target file exists"); +is(-s "womble",8,"right size"); +is(-s "rabbit",8,"right size"); +unlink("womble"); +unlink("rabbit"); diff --git a/perl/test/mkdir.t b/perl/test/mkdir.t new file mode 100644 index 0000000..90ec6f3 --- /dev/null +++ b/perl/test/mkdir.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 3; +chdir($_point); +ok(mkdir("dir"),"mkdir"); +ok(-d "dir","dir exists"); +chdir($_real); +ok(-d "dir","dir really exists"); +chdir($_point); +rmdir("dir"); diff --git a/perl/test/mknod.t b/perl/test/mknod.t new file mode 100644 index 0000000..35c5c82 --- /dev/null +++ b/perl/test/mknod.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 24; +my (@stat); +chdir($_point); +ok(!(system("touch reg" )>>8),"create normal file"); +ok(!(system("mknod chr c 2 3")>>8),"create chrdev"); +ok(!(system("mknod blk b 2 3")>>8),"create blkdev"); +ok(!(system("mknod fifo p" )>>8),"create fifo"); +chdir($_real); +ok(-e "reg" ,"normal file exists"); +ok(-e "chr" ,"chrdev exists"); +ok(-e "blk" ,"blkdev exists"); +ok(-e "fifo","fifo exists"); +ok(-f "reg" ,"normal file is normal file"); +ok(-c "chr" ,"chrdev is chrdev"); +ok(-b "blk" ,"blkdev is blkdev"); +ok(-p "fifo","fifo is fifo"); +@stat = stat("chr"); +is($stat[6],3+(2<<8),"chrdev has right major,minor"); +@stat = stat("blk"); +is($stat[6],3+(2<<8),"blkdev has right major,minor"); +chdir($_point); +ok(-e "reg" ,"normal file exists"); +ok(-e "chr" ,"chrdev exists"); +ok(-e "blk" ,"blkdev exists"); +ok(-e "fifo","fifo exists"); +ok(-f "reg" ,"normal file is normal file"); +ok(-c "chr" ,"chrdev is chrdev"); +ok(-b "blk" ,"blkdev is blkdev"); +ok(-p "fifo","fifo is fifo"); +@stat = stat("chr"); +is($stat[6],3+(2<<8),"chrdev has right major,minor"); +@stat = stat("blk"); +is($stat[6],3+(2<<8),"blkdev has right major,minor"); +map { unlink } qw(reg chr blk fifo); diff --git a/perl/test/open.t b/perl/test/open.t new file mode 100644 index 0000000..030dc1f --- /dev/null +++ b/perl/test/open.t @@ -0,0 +1,10 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 1; +chdir($_real); +system("echo frog >file"); +chdir($_point); +ok(open(FILE,"file"),"open"); +close(FILE); +unlink("file"); diff --git a/perl/test/read.t b/perl/test/read.t new file mode 100644 index 0000000..5eca920 --- /dev/null +++ b/perl/test/read.t @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 3; +chdir($_real); +system("echo frog >file"); +chdir($_point); +ok(open(FILE,"file"),"open"); +my ($data) = <FILE>; +close(FILE); +is(length($data),5,"right amount read"); +is($data,"frog\n","right data read"); +unlink("file"); diff --git a/perl/test/readlink.t b/perl/test/readlink.t new file mode 100644 index 0000000..85b9ffc --- /dev/null +++ b/perl/test/readlink.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use test::helper qw($_point $_real); +use Test::More; +plan tests => 4; +chdir($_real); +ok(symlink("abc","def"),"OS supports symlinks"); +is(readlink("def"),"abc","OS supports symlinks"); +chdir($_point); +ok(-l "def","symlink exists"); +is(readlink("def"),"abc","readlink"); +unlink("def"); diff --git a/perl/test/rename.t b/perl/test/rename.t new file mode 100644 index 0000000..9fbb330 --- /dev/null +++ b/perl/test/rename.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 5; +chdir($_point); +system("echo hippity >frog"); +ok(-f "frog","exists"); +ok(!-f "toad","target file doesn't exist"); +ok(rename("frog","toad"),"rename"); +ok(!-f "frog","old file doesn't exist"); +ok(-f "toad","target file exists"); +unlink("toad"); diff --git a/perl/test/rmdir.t b/perl/test/rmdir.t new file mode 100644 index 0000000..36f0378 --- /dev/null +++ b/perl/test/rmdir.t @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 5; +chdir($_real); +ok(mkdir("dir"),"mkdir"); +ok(-d "dir","dir really exists"); +chdir($_point); +ok(-d "dir","dir exists"); +rmdir("dir"); +ok(! -d "dir","dir removed"); +chdir($_real); +ok(! -d "dir","dir really removed"); diff --git a/perl/test/s/mount.t b/perl/test/s/mount.t new file mode 100644 index 0000000..1deb2c4 --- /dev/null +++ b/perl/test/s/mount.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w +use test::helper qw($_point $_loop $_real $_pidfile); +use strict; +use Test::More tests => 4; +ok(!(scalar grep(/ on $_point /,`cat /proc/mounts`)),"already mounted"); +ok(-f $_loop,"loopback exists"); +ok(-x $_loop,"loopback executable"); + +if(!fork()) { + #close(STDIN); + close(STDOUT); + close(STDERR); + `echo $$ >test/s/mounted.pid`; + exec("perl $_loop $_point"); + exit(1); +} +select(undef, undef, undef, 0.5); +my ($success) = `cat /proc/mounts` =~ / $_point /; +ok($success,"mount succeeded"); +system("rm -rf $_real"); +unless($success) { + kill('INT',`cat $_pidfile`); + unlink($_pidfile); +} else { + mkdir($_real); +} diff --git a/perl/test/s/umount.t b/perl/test/s/umount.t new file mode 100644 index 0000000..da60677 --- /dev/null +++ b/perl/test/s/umount.t @@ -0,0 +1,7 @@ +#!/usr/bin/perl +use test::helper qw($_point $_real $_pidfile); +use strict; +use Test::More tests => 1; +system("umount $_point"); +ok(1,"unmount"); +system("rm -rf $_real $_pidfile"); diff --git a/perl/test/statfs.t b/perl/test/statfs.t new file mode 100644 index 0000000..fb94704 --- /dev/null +++ b/perl/test/statfs.t @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +require 'syscall.ph'; # for SYS_statfs +plan tests => 7; +my ($statfs_data) = " " x 10; +my ($tmp) = $_point; +ok(!syscall(&SYS_statfs,$tmp,$statfs_data),"statfs"); +# FIXME: this is soooooo linux-centric. perhaps parse the output of /bin/df? +my @list = unpack("LSSL8",$statfs_data); +shift(@list); +is(shift(@list),4096,"block size"); +shift(@list); +is(shift(@list),1000000,"blocks"); +is(shift(@list),500000,"blocks free"); +shift(@list); +is(shift(@list),1000000,"files"); +is(shift(@list),500000,"files free"); +shift(@list); +shift(@list); +is(shift(@list),255,"namelen"); diff --git a/perl/test/symlink.t b/perl/test/symlink.t new file mode 100644 index 0000000..faf98e6 --- /dev/null +++ b/perl/test/symlink.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use test::helper qw($_point $_real); +use Test::More; +plan tests => 5; +chdir($_point); +ok(symlink("abc","def"),"symlink created"); +ok(-l "def","symlink exists"); +is(readlink("def"),"abc","it worked"); +chdir($_real); +ok(-l "def","symlink really exists"); +is(readlink("def"),"abc","really worked"); +unlink("def"); diff --git a/perl/test/test-template b/perl/test/test-template new file mode 100644 index 0000000..ef57e08 --- /dev/null +++ b/perl/test/test-template @@ -0,0 +1,5 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 1; +ok(1); diff --git a/perl/test/truncate.t b/perl/test/truncate.t new file mode 100644 index 0000000..8607421 --- /dev/null +++ b/perl/test/truncate.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 5; +chdir($_point); +system("echo hippity >womble"); +ok(-f "womble","exists"); +is(-s "womble",8,"right size"); +ok(truncate("womble",4),"truncate"); +ok(-f "womble","file exists"); +is(-s "womble",4,"right size"); +unlink("womble"); diff --git a/perl/test/unlink.t b/perl/test/unlink.t new file mode 100644 index 0000000..eef8c1a --- /dev/null +++ b/perl/test/unlink.t @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 4; +chdir($_point); +system("touch file"); +ok(-f "file","file exists"); +chdir($_real); +ok(-f "file","file really exists"); +chdir($_point); +unlink("file"); +ok(! -f "file","file unlinked"); +chdir($_real); +ok(! -f "file","file really unlinked"); diff --git a/perl/test/utime.t b/perl/test/utime.t new file mode 100644 index 0000000..0303907 --- /dev/null +++ b/perl/test/utime.t @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 3; +my (@stat); +chdir($_real); +system("echo frog >file"); +chdir($_point); +ok(utime(1,2,"file"),"set utime"); +@stat = stat("file"); +is($stat[9],1,"atime"); +is($stat[10],2,"atime"); +unlink("file"); diff --git a/perl/test/write.t b/perl/test/write.t new file mode 100644 index 0000000..58af2aa --- /dev/null +++ b/perl/test/write.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use test::helper qw($_real $_point); +use Test::More; +plan tests => 15; +my ($data); +chdir($_point); +undef $/; # slurp it all +# create file +system("echo frogbing >writefile"); + +# fetch contents of file +ok(open(FILE,"writefile"),"open"); +$data = <FILE>; +close(FILE); +is(length($data),9,"right amount read"); +is($data,"frogbing\n","right data read"); + +# overwrite part +ok(open(FILE,'+<',"writefile"),"open"); +ok(seek(FILE,2,0),"seek"); +ok(print(FILE "ib"),"print"); +close(FILE); + +# fetch contents of file +ok(open(FILE,"writefile"),"open"); +$data = <FILE>; +close(FILE); +is(length($data),9,"right amount read"); +is($data,"fribbing\n","right data read"); + +# overwrite part, append some +ok(open(FILE,'+<',"writefile"),"open"); +ok(seek(FILE,7,0),"seek"); +ok(print(FILE "gle"),"print"); +close(FILE); + +# fetch contents of file +ok(open(FILE,"writefile"),"open"); +$data = <FILE>; +close(FILE); +is(length($data),10,"right amount read"); +is($data,"fribbingle","right data read"); + +# kill file +unlink("writefile"); |