Make test 005 work on SuSE kernels, cleanup its use on other platforms too.
[xfstests-dev.git] / 020
1 #! /bin/sh
2 # FS QA Test No. 020
3 #
4 # extended attributes
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=dxm@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=0        # success is the default!
47 trap "_cleanup; rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
48
49 # get standard environment, filters and checks
50 . ./common.rc
51 . ./common.filter
52
53 _cleanup()
54 {
55     _cleanup_testdir
56 }
57
58 _filter()
59 {
60     sed "s#$testdir[^ :]*#<TESTFILE>#g; 
61             s#$tmp[^ :]*#<TMPFILE>#g;
62             s#/proc[^ :]*#<PROCFILE>#g" $1
63 }
64
65 _attr()
66 {
67     attr $* 2>$tmp.err >$tmp.out
68     exit=$?
69     _filter $tmp.out
70     _filter $tmp.err 1>&2
71     return $exit
72 }
73
74 _getfattr()
75 {
76     getfattr $* 2>$tmp.err >$tmp.out
77     exit=$?
78     _filter $tmp.out
79     _filter $tmp.err 1>&2
80     return $exit
81 }
82
83 _attr_list()
84 {
85     file=$1
86     
87     echo "   *** print attributes"
88     if ! _getfattr -d -e text --absolute-names $file
89     then
90         echo "      !!! error return"
91         return 1
92     fi
93 }
94
95
96 # real QA test starts here
97 _supported_fs xfs udf
98 _supported_os Linux
99
100 [ -x /usr/bin/attr ] || _notrun "attr is not installed"
101 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
102
103 _setup_testdir
104
105 rm -f $seq.full
106
107 testfile=$testdir/attribute_$$
108
109 echo "*** list non-existant file"
110 _attr_list $testfile
111
112 echo "*** list non-xfs file (in /proc)"
113 _attr_list /proc/devices
114
115 echo "*** list empty file"
116 touch $testfile
117 _attr_list $testfile
118
119 echo "*** query non-existant attribute"
120 _attr -g "nonexistant" $testfile 2>&1
121
122 echo "*** one attribute"
123 echo "fish" | _attr -s fish $testfile
124 _attr_list $testfile
125
126 echo "*** replace attribute"
127 echo "fish3" | _attr -s fish $testfile
128 _attr_list $testfile
129
130 echo "*** add attribute"
131 echo "fish2" | _attr -s snrub $testfile
132 _attr_list $testfile
133
134 echo "*** remove attribute"
135 _attr -r fish $testfile
136 _attr_list $testfile
137
138 echo "*** add lots of attributes"
139 v=0
140 while [ $v -lt 1000 ]
141 do
142     echo "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
143     if [ $? -ne 0 ]
144     then
145         echo "!!! failed to add \"attribute_$v\""
146         exit 1
147     fi
148     
149     let "v = v + 1"
150 done
151
152 echo "*** check"
153 # don't print it all out...
154 getfattr --absolute-names $testfile \
155     | tee -a $seq.full \
156     | $AWK_PROG '
157         /^#/ { next }
158         /^[     ]*$/ { next }
159         { l++ } 
160         END {print "   *** " (l - 1) " attribute(s)" }'
161
162 echo "*** remove lots of attributes"
163 v=0
164 while [ $v -lt 1000 ]
165 do
166     if ! attr -r "attribute_$v" $testfile >>$seq.full
167     then
168         echo "!!! failed to remove \"attribute_$v\""
169         exit 1
170     fi
171     
172     let "v = v + 1"
173 done
174
175 _attr_list $testfile
176
177 echo "*** really long value"
178 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
179     | _attr -s "long_attr" $testfile >/dev/null
180     
181 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
182 _attr -r "long_attr" $testfile >/dev/null
183
184
185 echo "*** set/get/remove really long names (expect failure)"
186 short="XXXXXXXXXX"
187 long="$short$short$short$short$short$short$short$short$short$short"
188 vlong="$long$long$long"
189
190 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
191 _attr -g $vlong $testfile 2>&1 >/dev/null
192 _attr -r $vlong $testfile 2>&1 >/dev/null
193
194 echo "*** check final"
195
196 _attr_list $testfile
197
198 echo "*** delete"
199 rm -f $testfile
200
201 exit