generic: test adding filesystem-level fscrypt key via key_id
[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                 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
67                 if [ $? -ne 0 ]; then
68                         echo "Failed to update times on $file" | tee -a $seqres.full
69                 fi
70         fi
71
72         tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))
73         echo "Checking file: $file Updated timestamp is $tsclamp"  >> $seqres.full
74         check_stat $file $tsclamp
75 }
76
77 run_test()
78 {
79         update_time=$1
80
81         n=1
82
83         for TIME in "${TIMESTAMPS[@]}"; do
84                 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
85                 ((n++))
86         done
87 }
88
89 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
90 _scratch_mount || _fail "scratch mount failed"
91
92 _require_timestamp_range $SCRATCH_DEV
93
94 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
95 echo min supported timestamp $tsmin >> $seqres.full
96 echo max supported timestamp $tsmax >> $seqres.full
97
98 # Test timestamps array
99
100 declare -a TIMESTAMPS=(
101         $tsmin
102         0
103         $tsmax
104         $((tsmax/2))
105         $((tsmax+1))
106 )
107
108 status=0
109
110 # Begin test case 1
111 echo "In memory timestamps update test start" >> $seqres.full
112
113 # update time on the file
114 update_time=1
115
116 run_test $update_time
117
118 echo "In memory timestamps update complete" >> $seqres.full
119
120 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
121
122 # unmount and remount $SCRATCH_DEV
123 _scratch_cycle_mount
124
125 # Begin test case 2
126
127 n=1
128
129 # Do not update time on the file this time, just read from disk
130 update_time=0
131
132 echo "On disk timestamps update test start" >> $seqres.full
133
134 # Re-run test
135 run_test $update_time
136
137 echo "On disk timestamps update test complete" >> $seqres.full
138
139 echo Silence is golden
140 exit