2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test file timestamps are precise to nanoseconds with 256-byte inodes
10 _begin_fstest auto quick
12 # Import common functions.
15 # real QA test starts here
18 _require_test_program "t_get_file_time"
20 echo "Silence is golden"
22 echo "Test timestamps with 256 inode size one device $SCRATCH_DEV" >$seqres.full
23 _scratch_mkfs -t ext3 -I 256 >> $seqres.full 2>&1
27 touch "${SCRATCH_MNT}/tmp_file"
30 # Change atime, ctime and mtime of the file
31 touch "${SCRATCH_MNT}/tmp_file"
33 cur_time=`date '+%s %N'`
34 sec=`echo $cur_time | $AWK_PROG {'print $1'}`
35 nsec=`echo $cur_time | $AWK_PROG {'print $2'}`
37 sec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime sec`
38 sec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime sec`
39 sec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime sec`
40 nsec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
41 nsec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
42 nsec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`
45 if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]; then
46 echo "The timestamp is not nanosecond(nsec_atime: $nsec_atime, \
47 nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime, cur_time[ns]: $nsec)"
50 # Check difference between file time and current time
51 _within_tolerance "sec_atime" $sec_atime $sec 1
52 _within_tolerance "sec_mtime" $sec_mtime $sec 1
53 _within_tolerance "sec_ctime" $sec_ctime $sec 1
55 _scratch_unmount >> $seqres.full 2>&1
57 # Test mount to ext3 then mount back to ext4 and check timestamp again
58 _mount -t ext3 `_scratch_mount_options $*` || _fail "ext3 mount failed"
59 _scratch_unmount >> $seqres.full 2>&1
62 nsec_atime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
63 nsec_mtime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
64 nsec_ctime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`
66 [ $nsec_atime -ne $nsec_atime2 ] && echo "File nanosecond timestamp atime has changed unexpected from $nsec_atime to $nsec_atime2"
67 [ $nsec_mtime -ne $nsec_mtime2 ] && echo "File nanosecond timestamp mtime has changed unexpected from $nsec_mtime to $nsec_mtime2"
68 [ $nsec_ctime -ne $nsec_ctime2 ] && echo "File nanosecond timestamp ctime has changed unexpected from $nsec_ctime to $nsec_ctime2"