Add GPL license plate to SGI's test files.
[xfstests-dev.git] / 020
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FS QA Test No. 020
22 #
23 # extended attributes
24 #
25 # creator
26 owner=dxm@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=0        # success is the default!
34 trap "_cleanup; rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
35
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
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 $* 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 $* 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 [ -x /usr/bin/attr ] || _notrun "attr is not installed"
87 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
88
89 _setup_testdir
90
91 rm -f $seq.full
92
93 testfile=$testdir/attribute_$$
94
95 echo "*** list non-existant file"
96 _attr_list $testfile
97
98 echo "*** list empty file"
99 touch $testfile
100 _attr_list $testfile
101
102 echo "*** query non-existant attribute"
103 _attr -g "nonexistant" $testfile 2>&1
104
105 echo "*** one attribute"
106 echo "fish" | _attr -s fish $testfile
107 _attr_list $testfile
108
109 echo "*** replace attribute"
110 echo "fish3" | _attr -s fish $testfile
111 _attr_list $testfile
112
113 echo "*** add attribute"
114 echo "fish2" | _attr -s snrub $testfile
115 _attr_list $testfile
116
117 echo "*** remove attribute"
118 _attr -r fish $testfile
119 _attr_list $testfile
120
121 echo "*** add lots of attributes"
122 v=0
123 while [ $v -lt 1000 ]
124 do
125     echo "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
145 echo "*** remove lots of attributes"
146 v=0
147 while [ $v -lt 1000 ]
148 do
149     if ! attr -r "attribute_$v" $testfile >>$seq.full
150     then
151         echo "!!! failed to remove \"attribute_$v\""
152         exit 1
153     fi
154     
155     let "v = v + 1"
156 done
157
158 _attr_list $testfile
159
160 echo "*** really long value"
161 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
162     | _attr -s "long_attr" $testfile >/dev/null
163     
164 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
165 _attr -r "long_attr" $testfile >/dev/null
166
167
168 echo "*** set/get/remove really long names (expect failure)"
169 short="XXXXXXXXXX"
170 long="$short$short$short$short$short$short$short$short$short$short"
171 vlong="$long$long$long"
172
173 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
174 _attr -g $vlong $testfile 2>&1 >/dev/null
175 _attr -r $vlong $testfile 2>&1 >/dev/null
176
177 echo "*** check final"
178
179 _attr_list $testfile
180
181 echo "*** delete"
182 rm -f $testfile
183
184 exit