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