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