49230da0d6df535af5059b81c25696e42485a73b
[xfstests-dev.git] / tests / generic / 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
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=0        # success is the default!
32 trap "rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/attr
38
39 _filter()
40 {
41     sed "s#$TEST_DIR[^ :]*#<TESTFILE>#g; 
42             s#$tmp[^ :]*#<TMPFILE>#g" $1
43 }
44
45 _attr()
46 {
47     $ATTR_PROG $* 2>$tmp.err >$tmp.out
48     exit=$?
49     _filter $tmp.out
50     _filter $tmp.err 1>&2
51     return $exit
52 }
53
54 _getfattr()
55 {
56     $GETFATTR_PROG $* 2>$tmp.err >$tmp.out
57     exit=$?
58     _filter $tmp.out
59     _filter $tmp.err 1>&2
60     return $exit
61 }
62
63 _attr_list()
64 {
65     file=$1
66     
67     echo "   *** print attributes"
68     if ! _getfattr -d -e text --absolute-names $file
69     then
70         echo "      !!! error return"
71         return 1
72     fi
73 }
74
75 # real QA test starts here
76 _supported_fs generic
77 _supported_os Linux
78
79 _require_test
80 _require_attrs
81
82 rm -f $seqres.full
83
84 testfile=$TEST_DIR/attribute_$$
85
86 echo "*** list non-existant file"
87 _attr_list $testfile
88
89 echo "*** list empty file"
90 touch $testfile
91 _attr_list $testfile
92
93 echo "*** query non-existant attribute"
94 _attr -g "nonexistant" $testfile 2>&1
95
96 echo "*** one attribute"
97 echo "fish" | _attr -s fish $testfile
98 _attr_list $testfile
99
100 echo "*** replace attribute"
101 echo "fish3" | _attr -s fish $testfile
102 _attr_list $testfile
103
104 echo "*** add attribute"
105 echo "fish2" | _attr -s snrub $testfile
106 _attr_list $testfile
107
108 echo "*** remove attribute"
109 _attr -r fish $testfile
110 _attr_list $testfile
111
112 echo "*** add lots of attributes"
113 v=0
114
115 while [ $v -lt $MAX_ATTRS ]
116 do
117     echo -n "value_$v" | attr -s "attribute_$v" $testfile >>$seqres.full
118     if [ $? -ne 0 ]
119     then
120         echo "!!! failed to add \"attribute_$v\""
121         exit 1
122     fi
123     
124     let "v = v + 1"
125 done
126
127 echo "*** check"
128 # don't print it all out...
129 getfattr --absolute-names $testfile \
130     | tee -a $seqres.full \
131     | $AWK_PROG '
132         /^#/ { next }
133         /^[     ]*$/ { next }
134         { l++ } 
135         END {print "   *** " (l - 1) " attribute(s)" }' \
136     | sed s/$MAX_ATTRS/MAX_ATTRS/
137
138 echo "*** remove lots of attributes"
139 v=0
140 while [ $v -lt $MAX_ATTRS ]
141 do
142     if ! $ATTR_PROG -r "attribute_$v" $testfile >>$seqres.full
143     then
144         echo "!!! failed to remove \"attribute_$v\""
145         exit 1
146     fi
147     
148     let "v = v + 1"
149 done
150
151 _attr_list $testfile
152
153 echo "*** really long value"
154 dd if=/dev/zero bs=1 count=$MAX_ATTRVAL_SIZE 2>/dev/null \
155     | _attr -s "long_attr" $testfile >/dev/null
156
157 OCTAL_SIZE=`echo "obase=8; $MAX_ATTRVAL_SIZE" | bc`
158 _attr -q -g "long_attr" $testfile | od -t x1 | sed -e "s/^0*$OCTAL_SIZE$/ATTRSIZE/"    
159 _attr -r "long_attr" $testfile >/dev/null
160
161 echo "*** set/get/remove really long names (expect failure)"
162 short="XXXXXXXXXX"
163 long="$short$short$short$short$short$short$short$short$short$short"
164 vlong="$long$long$long"
165
166 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
167 _attr -g $vlong $testfile 2>&1 >/dev/null
168 _attr -r $vlong $testfile 2>&1 >/dev/null
169
170 echo "*** check final"
171
172 _attr_list $testfile
173
174 echo "*** delete"
175 rm -f $testfile
176
177 exit