xfstests: detect gdbm library correctly
[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 xfs udf
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 while [ $v -lt 1000 ]
123 do
124     echo "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
125     if [ $? -ne 0 ]
126     then
127         echo "!!! failed to add \"attribute_$v\""
128         exit 1
129     fi
130     
131     let "v = v + 1"
132 done
133
134 echo "*** check"
135 # don't print it all out...
136 getfattr --absolute-names $testfile \
137     | tee -a $seq.full \
138     | $AWK_PROG '
139         /^#/ { next }
140         /^[     ]*$/ { next }
141         { l++ } 
142         END {print "   *** " (l - 1) " attribute(s)" }'
143
144 echo "*** remove lots of attributes"
145 v=0
146 while [ $v -lt 1000 ]
147 do
148     if ! $ATTR_PROG -r "attribute_$v" $testfile >>$seq.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=1024 count=100 2>/dev/null \
161     | _attr -s "long_attr" $testfile >/dev/null
162     
163 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
164 _attr -r "long_attr" $testfile >/dev/null
165
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