1#!perl -w 2 3# Before `make install' is performed this script should be runnable with 4# `make test'. After `make install' it should work as `perl Linux-xattr.t' 5 6######################### 7 8# change 'tests => 2' to 'tests => last_test_to_print'; 9 10# XXX: Refactor the common bits between this and 11basic.t 11# into Test::Class classes? 12 13use strict; 14use Test::More; 15 16BEGIN { 17 my $tlib = $0; 18 $tlib =~ s|/[^/]*$|/lib|; 19 push(@INC, $tlib); 20} 21use t::Support; 22 23if (t::Support::should_skip()) { 24 plan skip_all => 'Tests unsupported on this OS/filesystem'; 25} else { 26 plan tests => 24; 27} 28 29use File::Temp qw(tempfile); 30use File::Path; 31use File::ExtAttr qw(setfattr getfattr delfattr); 32use IO::File; 33 34my $TESTDIR = ($ENV{ATTR_TEST_DIR} || '.'); 35my ($fh, $filename) = tempfile( DIR => $TESTDIR ); 36close $fh or die "can't close $filename $!"; 37 38# Create a directory. 39my $dirname = "$filename.dir"; 40eval { mkpath($dirname); }; 41if ($@) { 42 warn "Couldn't create $dirname: $@"; 43} 44 45#todo: try wierd characters in here? 46# try unicode? 47my $key = "alskdfjadf2340zsdflksjdfa09eralsdkfjaldkjsldkfj"; 48my $longval = 'A' x $File::ExtAttr::MAX_INITIAL_VALUELEN; 49my $longval2 = 'A' x ($File::ExtAttr::MAX_INITIAL_VALUELEN + 11); 50 51########################## 52# Filename-based tests # 53########################## 54 55foreach ( $filename, $dirname ) { 56 print "# using $_\n"; 57 58#for (1..30000) { #checking memory leaks 59 #check a really big one, bigger than $File::ExtAttr::MAX_INITIAL_VALUELEN 60 #Hmmm, 3991 is the biggest number that doesn't generate "no space left on device" 61 #on my /var partition, and 920 is the biggest for my loopback partition. 62 #What's up with that? 63 #setfattr($_, "$key-2", ('x' x 3991)) or die "setfattr failed on $_: $!"; 64 setfattr($_, "$key", $longval) or die "setfattr failed on $_: $!"; 65 66 #set it 67 is (setfattr($_, "$key", $longval), 1); 68 69 #read it back 70 is (getfattr($_, "$key"), $longval); 71 72 #delete it 73 ok (delfattr($_, "$key")); 74 75 #check that it's gone 76 is (getfattr($_, "$key"), undef); 77 78 #set it 79 is (setfattr($_, "$key", $longval2), 1); 80 81 #read it back 82 is (getfattr($_, "$key"), $longval2); 83 84 #delete it 85 ok (delfattr($_, "$key")); 86 87 #check that it's gone 88 is (getfattr($_, "$key"), undef); 89#} 90} 91 92########################## 93# IO::Handle-based tests # 94########################## 95 96$fh = new IO::File("<$filename") or die "Unable to open $filename"; 97 98print "# using file descriptor ".$fh->fileno()."\n"; 99 100#for (1..30000) { #checking memory leaks 101 #check a really big one, bigger than $File::ExtAttr::MAX_INITIAL_VALUELEN 102 #Hmmm, 3991 is the biggest number that doesn't generate "no space left on device" 103 #on my /var partition, and 920 is the biggest for my loopback partition. 104 #What's up with that? 105 #setfattr($filename, "$key-2", ('x' x 3991)) or die "setfattr failed on $filename: $!"; 106 setfattr($fh, "$key", $longval) 107 or die "setfattr failed on file descriptor ".$fh->fileno().": $!"; 108 109 #set it 110 is (setfattr($fh, "$key", $longval), 1); 111 112 #read it back 113 is (getfattr($fh, "$key"), $longval); 114 115 #delete it 116 ok (delfattr($fh, "$key")); 117 118 #check that it's gone 119 is (getfattr($fh, "$key"), undef); 120 121 #set it 122 is (setfattr($fh, "$key", $longval2), 1); 123 124 #read it back 125 is (getfattr($fh, "$key"), $longval2); 126 127 #delete it 128 ok (delfattr($fh, "$key")); 129 130 #check that it's gone 131 is (getfattr($fh, "$key"), undef); 132#} 133#print STDERR "done\n"; 134#<STDIN>; 135 136# todo: Add support for IO::Dir handles, and test here. 137 138END { 139 unlink $filename if $filename; 140 rmdir $dirname if $dirname; 141}; 142