use _do from common.rc
[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 _attr_list()
71 {
72     file=$1
73     
74     echo "   *** print attributes"
75     if ! _attr -l $file >$tmp.raw
76     then
77         echo "      !!! error return"
78         return 1
79     fi
80     
81     $AWK_PROG -v file=$file '
82         {
83             print substr($2,2,length($2)-2)
84             count++
85         }
86         END { 
87             exit count 
88         }
89         ' <$tmp.raw >$tmp.list
90         
91     echo "      *** $? attribute(s)"
92     for l in `cat $tmp.list`
93     do
94         if ! _attr -g $l $file >$tmp.raw
95         then
96             echo "         *** $l"
97             echo "         !!! error return"
98             return 1
99         fi
100         $AWK_PROG '
101             NR==1 {
102                 print "         *** field: " substr($2,2,length($2)-2) \
103                       " length: " $5
104                 next
105             }
106             {
107                 print "            ::: " $0
108             }
109         ' <$tmp.raw
110         
111     done
112 }
113
114
115 # real QA test starts here
116
117 testfile=$TEST_DIR/attribute_$$
118
119 echo "*** list non-existant file"
120 _attr_list $testfile
121
122 echo "*** list non-xfs file (in /proc)"
123 _attr_list /proc/devices
124
125 echo "*** list empty file"
126 touch $testfile
127 _attr_list $testfile
128
129 echo "*** query non-existant attribute"
130 _attr -g "nonexistant" $testfile 2>&1
131
132 echo "*** one attribute"
133 echo "fish" | _attr -s fish $testfile
134 _attr_list $testfile
135
136 echo "*** replace attribute"
137 echo "fish3" | _attr -s fish $testfile
138 _attr_list $testfile
139
140 echo "*** add attribute"
141 echo "fish2" | _attr -s snrub $testfile
142 _attr_list $testfile
143
144 echo "*** remove attribute"
145 _attr -r fish $testfile
146 _attr_list $testfile
147
148 echo "*** add lots of attributes"
149 v=0
150 while [ $v -lt 1000 ]
151 do
152     echo "value_$v" | attr -s "attribute_$v" $testfile >/dev/null
153     if [ $? -ne 0 ]
154     then
155         echo "!!! failed to add \"attribute_$v\""
156         exit 1
157     fi
158     
159     let "v = v + 1"
160 done
161
162 echo "*** check"
163 # don't print it all out...
164 attr -l $testfile \
165     | $AWK_PROG '{ l++ } END {print "   *** " l " attribute(s)" }'
166
167 echo "*** remove lots of attributes"
168 v=0
169 while [ $v -lt 1000 ]
170 do
171     if ! attr -r "attribute_$v" $testfile >/dev/null
172     then
173         echo "!!! failed to add \"attribute_$v\""
174         exit 1
175     fi
176     
177     let "v = v + 1"
178 done
179
180 _attr_list $testfile
181
182 echo "*** really long value"
183 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
184     | _attr -s "long_attr" $testfile >/dev/null
185     
186 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
187 _attr -r "long_attr" $testfile >/dev/null
188
189
190 echo "*** set/get/remove really long names (expect failure)"
191 short="XXXXXXXXXX"
192 long="$short$short$short$short$short$short$short$short$short$short"
193 vlong="$long$long$long"
194
195 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
196 _attr -g $vlong $testfile 2>&1 >/dev/null
197 _attr -r $vlong $testfile 2>&1 >/dev/null
198
199 echo "*** check final"
200
201 _attr_list $testfile
202
203 echo "*** delete"
204 rm -f $testfile
205
206 exit