fstests: move test group info to test files
[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 . ./common/preamble
10 _begin_fstest auto quick
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16 _supported_fs ext4
17 _require_scratch
18 _require_test_program "t_get_file_time"
19
20 echo "Silence is golden"
21
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
24 _scratch_mount
25
26 # Create file
27 touch "${SCRATCH_MNT}/tmp_file"
28 sleep 1
29
30 # Change atime, ctime and mtime of the file
31 touch "${SCRATCH_MNT}/tmp_file"
32
33 cur_time=`date '+%s %N'`
34 sec=`echo $cur_time | $AWK_PROG {'print $1'}`
35 nsec=`echo $cur_time | $AWK_PROG {'print $2'}`
36
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`
43
44 # Test nanosecond
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)"
48 fi
49
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
54
55 _scratch_unmount >> $seqres.full 2>&1
56
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
60 _scratch_mount
61
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`
65
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"
69
70 status=0
71 exit