misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 424
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 424
6 #
7 # Test the statx stx_attribute flags that can be set with chattr
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=1
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22         $CHATTR_PROG -a -i $testfile
23         rm -f $testfile
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 # Modify as appropriate.
36 _supported_fs generic
37 _require_test
38 _require_test_program stat_test
39 _require_statx
40 _require_command "$CHATTR_PROG" chattr
41
42 function check_stat () {
43         $here/src/stat_test $* || echo stat_test failed
44 }
45
46 testfile=$TEST_DIR/$seq-file
47 touch $testfile
48
49 # Work out what chattrs are supported on the fs under test
50 a_supported=""
51 c_supported=""
52 d_supported=""
53 i_supported=""
54 a_list="0"
55 c_list="0"
56 d_list="0"
57 i_list="0"
58
59 if $CHATTR_PROG +a $testfile >&/dev/null; then
60     a_supported=1
61     a_list="+a -a"
62 fi
63
64 if $CHATTR_PROG +c $testfile >&/dev/null; then
65     c_supported=1
66     c_list="+c -c"
67 fi
68
69 if $CHATTR_PROG +d $testfile >&/dev/null; then
70     d_supported=1
71     d_list="+d -d"
72 fi
73
74 if $CHATTR_PROG +i $testfile >&/dev/null; then
75     i_supported=1
76     i_list="+i -i"
77 fi
78
79 echo "a=$a_supported d=$d_supported c=$c_supported i=$i_supported" >>$seqres.full
80
81 if [ "$a_supported$c_supported$d_supported$i_supported" = "" ]; then
82         _notrun "file system doesn't support any of $CHATTR_PROG +a/+c/+d/+i"
83 fi
84
85 $CHATTR_PROG -a -c -d -i $testfile
86
87 ###############################################################################
88 #
89 # Now do the actual test.  We can turn on and off append (a), compressed (c),
90 # immutable (i) and no-dump (d) and theoretically see the output in the
91 # attribute flags.  The following associations can be seen:
92 #
93 #       chattr flag     stx_attributes flag
94 #       +a              STATX_ATTR_APPEND
95 #       +c              STATX_ATTR_COMPRESSED
96 #       +d              STATX_ATTR_NODUMP
97 #       +i              STATX_ATTR_IMMUTABLE
98 #
99 # Note, however, that if the filesystem doesn't paste this information into
100 # stx_attributes, there's no way to tell the difference between cleared and
101 # unset.
102 #
103 ###############################################################################
104 function try () {
105         echo Trying "$*" >>$seqres.full
106         $CHATTR_PROG ${a_supported:+$1} \
107                ${c_supported:+$2} \
108                ${d_supported:+$3} \
109                ${i_supported:+$4} \
110                $testfile
111         check_stat $testfile \
112                ${a_supported:+attr=${1/a/append}} \
113                ${c_supported:+attr=${2/c/compressed}} \
114                ${d_supported:+attr=${3/d/nodump}} \
115                ${i_supported:+attr=${4/i/immutable}} \
116                stx_type=file \
117                stx_size=0 \
118                stx_rdev_major=0 \
119                stx_rdev_minor=0 \
120                stx_nlink=1
121 }
122
123 for a in $a_list; do
124         for c in $c_list; do
125                 for d in $d_list; do
126                         for i in $i_list; do
127                                 try $a $c $d $i
128                         done
129                 done
130         done
131 done
132
133 # For tradition's sake
134 echo "Silence is golden"
135
136 # Done.  We leave the success determination to the output comparator.
137 status=0
138 exit