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