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