xfstests: resolve compiler warnings
[xfstests-dev.git] / 020
1 #! /bin/bash
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
10 # modify it under the terms 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,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=dxm@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # success is the default!
33 trap "_cleanup; rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.attr
39
40 _cleanup()
41 {
42     _cleanup_testdir
43 }
44
45 _filter()
46 {
47     sed "s#$testdir[^ :]*#<TESTFILE>#g; 
48             s#$tmp[^ :]*#<TMPFILE>#g" $1
49 }
50
51 _attr()
52 {
53     $ATTR_PROG $* 2>$tmp.err >$tmp.out
54     exit=$?
55     _filter $tmp.out
56     _filter $tmp.err 1>&2
57     return $exit
58 }
59
60 _getfattr()
61 {
62     $GETFATTR_PROG $* 2>$tmp.err >$tmp.out
63     exit=$?
64     _filter $tmp.out
65     _filter $tmp.err 1>&2
66     return $exit
67 }
68
69 _attr_list()
70 {
71     file=$1
72     
73     echo "   *** print attributes"
74     if ! _getfattr -d -e text --absolute-names $file
75     then
76         echo "      !!! error return"
77         return 1
78     fi
79 }
80
81
82 # real QA test starts here
83 _supported_fs generic
84 _supported_os Linux
85
86 _require_attrs
87
88 _setup_testdir
89
90 rm -f $seq.full
91
92 testfile=$testdir/attribute_$$
93
94 echo "*** list non-existant file"
95 _attr_list $testfile
96
97 echo "*** list empty file"
98 touch $testfile
99 _attr_list $testfile
100
101 echo "*** query non-existant attribute"
102 _attr -g "nonexistant" $testfile 2>&1
103
104 echo "*** one attribute"
105 echo "fish" | _attr -s fish $testfile
106 _attr_list $testfile
107
108 echo "*** replace attribute"
109 echo "fish3" | _attr -s fish $testfile
110 _attr_list $testfile
111
112 echo "*** add attribute"
113 echo "fish2" | _attr -s snrub $testfile
114 _attr_list $testfile
115
116 echo "*** remove attribute"
117 _attr -r fish $testfile
118 _attr_list $testfile
119
120 echo "*** add lots of attributes"
121 v=0
122
123 while [ $v -lt $MAX_ATTRS ]
124 do
125     echo -n "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
126     if [ $? -ne 0 ]
127     then
128         echo "!!! failed to add \"attribute_$v\""
129         exit 1
130     fi
131     
132     let "v = v + 1"
133 done
134
135 echo "*** check"
136 # don't print it all out...
137 getfattr --absolute-names $testfile \
138     | tee -a $seq.full \
139     | $AWK_PROG '
140         /^#/ { next }
141         /^[     ]*$/ { next }
142         { l++ } 
143         END {print "   *** " (l - 1) " attribute(s)" }' \
144     | sed s/$MAX_ATTRS/MAX_ATTRS/
145
146 echo "*** remove lots of attributes"
147 v=0
148 while [ $v -lt $MAX_ATTRS ]
149 do
150     if ! $ATTR_PROG -r "attribute_$v" $testfile >>$seq.full
151     then
152         echo "!!! failed to remove \"attribute_$v\""
153         exit 1
154     fi
155     
156     let "v = v + 1"
157 done
158
159 _attr_list $testfile
160
161 echo "*** really long value"
162 dd if=/dev/zero bs=1 count=$MAX_ATTRVAL_SIZE 2>/dev/null \
163     | _attr -s "long_attr" $testfile >/dev/null
164
165 OCTAL_SIZE=`echo "obase=8; $MAX_ATTRVAL_SIZE" | bc`
166 _attr -q -g "long_attr" $testfile | od -t x1 | sed -e "s/^0*$OCTAL_SIZE$/ATTRSIZE/"    
167 _attr -r "long_attr" $testfile >/dev/null
168
169
170 echo "*** set/get/remove really long names (expect failure)"
171 short="XXXXXXXXXX"
172 long="$short$short$short$short$short$short$short$short$short$short"
173 vlong="$long$long$long"
174
175 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
176 _attr -g $vlong $testfile 2>&1 >/dev/null
177 _attr -r $vlong $testfile 2>&1 >/dev/null
178
179 echo "*** check final"
180
181 _attr_list $testfile
182
183 echo "*** delete"
184 rm -f $testfile
185
186 exit