generic/402: skip test if xfs_io can't parse the date value
[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 _supported_os Linux
38 _require_scratch
39 _require_check_dmesg
40 _require_xfs_io_command utimes
41
42 # Compare file timestamps obtained from stat
43 # with a given timestamp.
44 check_stat()
45 {
46         file=$1
47         timestamp=$2
48
49         stat_timestamp=`stat -c"%X;%Y" $file`
50
51         prev_timestamp="$timestamp;$timestamp"
52         if [ $prev_timestamp != $stat_timestamp ]; then
53                 echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
54         fi
55 }
56
57 run_test_individual()
58 {
59         file=$1
60         timestamp=$2
61         update_time=$3
62
63         # check if the time needs update
64         if [ $update_time -eq 1 ]; then
65                 echo "Updating file: $file to timestamp $timestamp"  >> $seqres.full
66                 rm -f $tmp.utimes
67                 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file > $tmp.utimes 2>&1
68                 local res=$?
69
70                 cat $tmp.utimes >> $seqres.full
71                 if [ "$timestamp" -ne 0 ] && grep -q "Bad value" "$tmp.utimes"; then
72                         echo "xfs_io could not interpret time value \"$timestamp\", skipping \"$file\" test." >> $seqres.full
73                         rm -f $file $tmp.utimes
74                         return
75                 fi
76                 cat $tmp.utimes
77                 rm -f $tmp.utimes
78                 if [ $res -ne 0 ]; then
79                         echo "Failed to update times on $file" | tee -a $seqres.full
80                 fi
81         else
82                 if [ ! -f "$file" ]; then
83                         echo "xfs_io did not create file for time value \"$timestamp\", skipping test." >> $seqres.full
84                         return
85                 fi
86         fi
87
88         tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))
89         echo "Checking file: $file Updated timestamp is $tsclamp"  >> $seqres.full
90         check_stat $file $tsclamp
91 }
92
93 run_test()
94 {
95         update_time=$1
96
97         n=1
98
99         for TIME in "${TIMESTAMPS[@]}"; do
100                 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
101                 ((n++))
102         done
103 }
104
105 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
106 _scratch_mount || _fail "scratch mount failed"
107
108 _require_timestamp_range $SCRATCH_DEV
109
110 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
111 echo min supported timestamp $tsmin >> $seqres.full
112 echo max supported timestamp $tsmax >> $seqres.full
113
114 # Test timestamps array
115
116 declare -a TIMESTAMPS=(
117         $tsmin
118         0
119         $tsmax
120         $((tsmax/2))
121         $((tsmax+1))
122 )
123
124 status=0
125
126 # Begin test case 1
127 echo "In memory timestamps update test start" >> $seqres.full
128
129 # update time on the file
130 update_time=1
131
132 run_test $update_time
133
134 echo "In memory timestamps update complete" >> $seqres.full
135
136 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
137
138 # unmount and remount $SCRATCH_DEV
139 _scratch_cycle_mount
140
141 # Begin test case 2
142
143 n=1
144
145 # Do not update time on the file this time, just read from disk
146 update_time=0
147
148 echo "On disk timestamps update test start" >> $seqres.full
149
150 # Re-run test
151 run_test $update_time
152
153 echo "On disk timestamps update test complete" >> $seqres.full
154
155 echo Silence is golden
156 exit