misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 423
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 423
6 #
7 # Test the statx system call
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         rm -rf $TEST_DIR/$seq-*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 # Modify as appropriate.
35 _supported_fs generic
36 _require_test
37 _require_test_program "stat_test"
38 _require_test_program "af_unix"
39 _require_statx
40 _require_symlinks
41 _require_mknod
42
43 function check_stat () {
44         $here/src/stat_test $* || echo stat_test failed
45 }
46
47 function create_af_unix () {
48         $here/src/af_unix $* || echo af_unix failed
49 }
50
51 ###############################################################################
52 #
53 # Check statx'ing of various types of object
54 #
55 # After each object is created, barring the first, we check that the creation
56 # time and the change time of the new object as same as or later than the
57 # corresponding timestamps on the previous object created.
58 #
59 ###############################################################################
60 echo "Test statx on a fifo"
61 mkfifo -m 0600 $TEST_DIR/$seq-fifo
62 check_stat $TEST_DIR/$seq-fifo \
63            ts_order \
64            stx_type=fifo \
65            stx_mode=0600 \
66            stx_rdev_major=0 \
67            stx_rdev_minor=0 \
68            stx_nlink=1
69
70 echo "Test statx on a chardev"
71 mknod -m 0600 $TEST_DIR/$seq-null c 1 3
72 check_stat $TEST_DIR/$seq-null \
73            ts_order \
74            ref=$TEST_DIR/$seq-fifo \
75            ts=B,b \
76            ts=M,m \
77            stx_type=char \
78            stx_mode=0600 \
79            stx_rdev_major=1 \
80            stx_rdev_minor=3 \
81            stx_nlink=1
82
83 echo "Test statx on a directory"
84 mkdir $TEST_DIR/$seq-dir
85 check_stat $TEST_DIR/$seq-dir \
86            ts_order \
87            ref=$TEST_DIR/$seq-null \
88            ts=B,b \
89            ts=M,m \
90            stx_type=dir \
91            stx_mode=0755 \
92            stx_rdev_major=0 \
93            stx_rdev_minor=0
94
95 echo "Test statx on a blockdev"
96 mknod -m 0600 $TEST_DIR/$seq-loopy b 7 123
97 check_stat $TEST_DIR/$seq-loopy \
98            ts_order \
99            ref=$TEST_DIR/$seq-dir \
100            ts=B,b \
101            ts=M,m \
102            stx_type=block \
103            stx_mode=0600 \
104            stx_rdev_major=7 \
105            stx_rdev_minor=123 \
106            stx_nlink=1
107
108 echo "Test statx on a file"
109 dd if=/dev/zero of=$TEST_DIR/$seq-file bs=1024 count=20
110 check_stat $TEST_DIR/$seq-file \
111            ts_order \
112            ref=$TEST_DIR/$seq-loopy \
113            ts=B,b \
114            ts=M,m \
115            stx_type=file \
116            stx_size=20480 \
117            stx_rdev_major=0 \
118            stx_rdev_minor=0 \
119            stx_nlink=1
120
121 echo "Test statx on a symlink"
122 ln -s $TEST_DIR/$seq-nowhere $TEST_DIR/$seq-symlink
123 check_stat $TEST_DIR/$seq-symlink \
124            ts_order \
125            ref=$TEST_DIR/$seq-file \
126            ts=B,b \
127            ts=M,m \
128            stx_type=sym \
129            stx_rdev_major=0 \
130            stx_rdev_minor=0 \
131            stx_nlink=1
132
133 echo "Test statx on an AF_UNIX socket"
134 create_af_unix $TEST_DIR/$seq-sock
135 check_stat $TEST_DIR/$seq-sock \
136            ts_order \
137            ref=$TEST_DIR/$seq-symlink \
138            ts=B,b \
139            ts=M,m \
140            stx_type=sock \
141            stx_rdev_major=0 \
142            stx_rdev_minor=0 \
143            stx_nlink=1
144
145 #
146 # Test hard link creation.  Make sure that the file's ctime is now same as or
147 # later than the creation time of the socket, but that the file's creation time
148 # still lies somewhere between those of the directory and the socket.
149 #
150 echo "Test a hard link to a file"
151 ln $TEST_DIR/$seq-file $TEST_DIR/$seq-link
152 check_stat $TEST_DIR/$seq-link \
153            ref=$TEST_DIR/$seq-dir \
154            ts=B,b \
155            ref=$TEST_DIR/$seq-sock \
156            ts=b,B \
157            ts=B,c \
158            ts=C,c \
159            ref=$TEST_DIR/$seq-file \
160            cmp_ref \
161            stx_nlink=2
162
163 # Done.  We leave the success determination to the output comparator.
164 status=0
165 exit