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