common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / ext4 / 044
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test No. 044
6 #
7 # Test file timestamps are precise to nanoseconds with 256-byte inodes
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       # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20        cd /
21        rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32 _supported_fs ext4
33 _require_scratch
34 _require_test_program "t_get_file_time"
35
36 echo "Silence is golden"
37
38 echo "Test timestamps with 256 inode size one device $SCRATCH_DEV" >$seqres.full
39 _scratch_mkfs -t ext3 -I 256 >> $seqres.full 2>&1
40 _scratch_mount
41
42 # Create file
43 touch "${SCRATCH_MNT}/tmp_file"
44 sleep 1
45
46 # Change atime, ctime and mtime of the file
47 touch "${SCRATCH_MNT}/tmp_file"
48
49 cur_time=`date '+%s %N'`
50 sec=`echo $cur_time | $AWK_PROG {'print $1'}`
51 nsec=`echo $cur_time | $AWK_PROG {'print $2'}`
52
53 sec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime sec`
54 sec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime sec`
55 sec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime sec`
56 nsec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
57 nsec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
58 nsec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`
59
60 # Test nanosecond
61 if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]; then
62        echo "The timestamp is not nanosecond(nsec_atime: $nsec_atime, \
63 nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime, cur_time[ns]: $nsec)"
64 fi
65
66 # Check difference between file time and current time
67 _within_tolerance "sec_atime" $sec_atime $sec 1
68 _within_tolerance "sec_mtime" $sec_mtime $sec 1
69 _within_tolerance "sec_ctime" $sec_ctime $sec 1
70
71 _scratch_unmount >> $seqres.full 2>&1
72
73 # Test mount to ext3 then mount back to ext4 and check timestamp again
74 _mount -t ext3 `_scratch_mount_options $*` || _fail "ext3 mount failed"
75 _scratch_unmount >> $seqres.full 2>&1
76 _scratch_mount
77
78 nsec_atime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
79 nsec_mtime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
80 nsec_ctime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`
81
82 [ $nsec_atime -ne $nsec_atime2 ] && echo "File nanosecond timestamp atime has changed unexpected from $nsec_atime to $nsec_atime2"
83 [ $nsec_mtime -ne $nsec_mtime2 ] && echo "File nanosecond timestamp mtime has changed unexpected from $nsec_mtime to $nsec_mtime2"
84 [ $nsec_ctime -ne $nsec_ctime2 ] && echo "File nanosecond timestamp ctime has changed unexpected from $nsec_ctime to $nsec_ctime2"
85
86 status=0
87 exit