generic/554: hide permision warning on exfat
[xfstests-dev.git] / tests / generic / 402
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Deepa Dinamani.  All Rights Reserved.
4 #
5 # FS QA Test 402
6 #
7 # Test to verify filesystem timestamps for supported ranges.
8 #
9 # Exit status 1: test failed.
10 # Exit status 0: test passed.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # Get standard environment, filters and checks.
28 . ./common/rc
29 . ./common/filter
30 . ./common/attr
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # Prerequisites for the test run.
36 _supported_fs generic
37 _require_scratch
38 _require_check_dmesg
39 _require_xfs_io_command utimes
40
41 # Compare file timestamps obtained from stat
42 # with a given timestamp.
43 check_stat()
44 {
45         file=$1
46         timestamp=$2
47
48         stat_timestamp=`stat -c"%X;%Y" $file`
49
50         prev_timestamp="$timestamp;$timestamp"
51         if [ $prev_timestamp != $stat_timestamp ]; then
52                 echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
53         fi
54 }
55
56 run_test_individual()
57 {
58         file=$1
59         timestamp=$2
60         update_time=$3
61
62         # check if the time needs update
63         if [ $update_time -eq 1 ]; then
64                 echo "Updating file: $file to timestamp $timestamp"  >> $seqres.full
65                 rm -f $tmp.utimes
66                 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file > $tmp.utimes 2>&1
67                 local res=$?
68
69                 cat $tmp.utimes >> $seqres.full
70                 if [ "$timestamp" -ne 0 ] && grep -q "Bad value" "$tmp.utimes"; then
71                         echo "xfs_io could not interpret time value \"$timestamp\", skipping \"$file\" test." >> $seqres.full
72                         rm -f $file $tmp.utimes
73                         return
74                 fi
75                 cat $tmp.utimes
76                 rm -f $tmp.utimes
77                 if [ $res -ne 0 ]; then
78                         echo "Failed to update times on $file" | tee -a $seqres.full
79                 fi
80         else
81                 if [ ! -f "$file" ]; then
82                         echo "xfs_io did not create file for time value \"$timestamp\", skipping test." >> $seqres.full
83                         return
84                 fi
85         fi
86
87         tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))
88         echo "Checking file: $file Updated timestamp is $tsclamp"  >> $seqres.full
89         check_stat $file $tsclamp
90 }
91
92 run_test()
93 {
94         update_time=$1
95
96         n=1
97
98         for TIME in "${TIMESTAMPS[@]}"; do
99                 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
100                 ((n++))
101         done
102 }
103
104 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
105 _scratch_mount
106
107 _require_timestamp_range $SCRATCH_DEV
108
109 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
110 echo min supported timestamp $tsmin >> $seqres.full
111 echo max supported timestamp $tsmax >> $seqres.full
112
113 # Test timestamps array
114
115 declare -a TIMESTAMPS=(
116         $tsmin
117         0
118         $tsmax
119         $((tsmax/2))
120         $((tsmax+1))
121 )
122
123 status=0
124
125 # Begin test case 1
126 echo "In memory timestamps update test start" >> $seqres.full
127
128 # update time on the file
129 update_time=1
130
131 run_test $update_time
132
133 echo "In memory timestamps update complete" >> $seqres.full
134
135 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
136
137 # unmount and remount $SCRATCH_DEV
138 _scratch_cycle_mount
139
140 # Begin test case 2
141
142 n=1
143
144 # Do not update time on the file this time, just read from disk
145 update_time=0
146
147 echo "On disk timestamps update test start" >> $seqres.full
148
149 # Re-run test
150 run_test $update_time
151
152 echo "On disk timestamps update test complete" >> $seqres.full
153
154 echo Silence is golden
155 exit