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