From: Richard Dawe <rich(at)phekda(dot)gotadsl(dot)co(dot)uk>
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Mar 2005 00:36:05 +0000 (00:36 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Mar 2005 00:36:05 +0000 (00:36 +0000)
Please find attached a patch that allows Fuse.pm's test suite to run as a
non-root user. It will skip all the tests that require root priveleges (giving
away ownership using chown, mknod of character and block devices). The patch
creates a test root and mount point per user.

The patch also uses POSIX::WEXITSTATUS instead of the less portable "$? >> 8"
idiom.

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/fuse/perl/trunk@10 6e4b0b00-1209-0410-87b2-b275959b5705

examples/loopback.pl
test/chown.t
test/helper.pm
test/mknod.t
test/s/mount.t
test/s/umount.t

index bdc8c22..b02f92f 100644 (file)
@@ -7,7 +7,7 @@ use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT);
 use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET);
 require 'syscall.ph'; # for SYS_mknod and SYS_lchown
 
-sub fixup { return "/tmp/fusetest" . shift }
+sub fixup { return "/tmp/fusetest-" . $ENV{LOGNAME} . shift }
 
 sub x_getattr {
        my ($file) = fixup(shift);
index 8ccbb88..45a811f 100644 (file)
@@ -1,14 +1,22 @@
 #!/usr/bin/perl
 use test::helper qw($_real $_point);
 use Test::More;
+use English;
 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");
+
+SKIP: {
+       skip('Need root to give away ownership', 4) unless ($UID == 0);
+
+       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");
index cd2bd55..797b9b8 100644 (file)
@@ -2,14 +2,15 @@
 package test::helper;
 use strict;
 use Exporter;
+use POSIX qw(WEXITSTATUS);
 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
 @ISA = "Exporter";
 @EXPORT_OK = qw($_loop $_point $_pidfile $_real);
-our($_loop, $_point, $_pidfile, $_real) = ("examples/loopback.pl","/mnt","test/s/mounted.pid","/tmp/fusetest");
+our($_loop, $_point, $_pidfile, $_real) = ("examples/loopback.pl","/tmp/fusemnt-".$ENV{LOGNAME},"test/s/mounted.pid","/tmp/fusetest-".$ENV{LOGNAME});
 if($0 !~ qr|s/u?mount\.t$|) {
        my ($reject) = 1;
        if(-f $_pidfile) {
-               unless(system("ps `cat $_pidfile` | grep \"$_loop $_point\" >/dev/null")>>8) {
+               unless(POSIX::WEXITSTATUS(system("ps `cat $_pidfile` | grep \"$_loop $_point\" >/dev/null"))) {
                        if(`mount | grep "on $_point"`) {
                                $reject = 0;
                        } else {
@@ -17,7 +18,8 @@ if($0 !~ qr|s/u?mount\.t$|) {
                        }
                }
        }
-       $reject = 1 if (system("ls $_point >&/dev/null") >> 8);
+       system("ls $_point >&/dev/null");
+       $reject = 1 if (POSIX::WEXITSTATUS($?));
        die "not properly mounted\n" if $reject;
 }
 1;
index 35c5c82..1dd948f 100644 (file)
@@ -2,36 +2,57 @@
 use test::helper qw($_real $_point);
 use Test::More;
 plan tests => 24;
+use English;
+
 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");
+
+SKIP: {
+       skip('Need root to mknod devices', 8) unless ($UID == 0);
+
+       chdir($_point);
+       ok(!(system("mknod chr c 2 3")>>8),"create chrdev");
+       ok(!(system("mknod blk b 2 3")>>8),"create blkdev");
+
+       chdir($_real);
+       ok(-e "chr" ,"chrdev exists");
+       ok(-e "blk" ,"blkdev exists");
+       ok(-c "chr" ,"chrdev is chrdev");
+       ok(-b "blk" ,"blkdev is blkdev");
+
+       @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");
+
+SKIP: {
+       skip('Need root to mknod devices', 6) unless ($UID == 0);
+
+       ok(-e "chr" ,"chrdev exists");
+       ok(-e "blk" ,"blkdev exists");
+       ok(-c "chr" ,"chrdev is chrdev");
+       ok(-b "blk" ,"blkdev is blkdev");
+
+       @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);
index 26f6fc2..b633dce 100644 (file)
@@ -9,6 +9,8 @@ if(!fork()) {
        #close(STDIN);
        close(STDOUT);
        close(STDERR);
+       mkdir $_point;
+       mkdir $_real;
        `echo $$ >test/s/mounted.pid`;
        exec("perl $_loop $_point");
        exit(1);
index da60677..0fec9b3 100644 (file)
@@ -2,6 +2,8 @@
 use test::helper qw($_point $_real $_pidfile);
 use strict;
 use Test::More tests => 1;
-system("umount $_point");
-ok(1,"unmount");
+use POSIX qw(WEXITSTATUS);
+#system("umount $_point");
+system("fusermount -u $_point");
+ok(POSIX::WEXITSTATUS($?) == 0,"unmount");
 system("rm -rf $_real $_pidfile");