summaryrefslogtreecommitdiff
path: root/tests/ext4/044
blob: 96fa70cc0d1e1f7f58ba14602fa8a0f1464cd284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE Linux Products GmbH.  All Rights Reserved.
#
# FS QA Test No. 044
#
# Test file timestamps are precise to nanoseconds with 256-byte inodes
#
. ./common/preamble
_begin_fstest auto quick

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs ext4
_require_scratch
_require_test_program "t_get_file_time"
_require_metadata_journaling

echo "Test timestamps with 256 inode size one device $SCRATCH_DEV" >$seqres.full
_scratch_mkfs -t ext3 -I 256 >> $seqres.full 2>&1
_scratch_mount

# Create file
touch "${SCRATCH_MNT}/tmp_file"
sleep 1

# Change atime, ctime and mtime of the file
touch "${SCRATCH_MNT}/tmp_file"

cur_time=`date '+%s %N'`
sec=`echo $cur_time | $AWK_PROG {'print $1'}`
nsec=`echo $cur_time | $AWK_PROG {'print $2'}`

sec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime sec`
sec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime sec`
sec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime sec`
nsec_atime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
nsec_mtime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
nsec_ctime=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`

# Test nanosecond
if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]; then
       echo "The timestamp is not nanosecond(nsec_atime: $nsec_atime, \
nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime, cur_time[ns]: $nsec)"
fi

# Check difference between file time and current time
_within_tolerance "sec_atime" $sec_atime $sec 1 -v
_within_tolerance "sec_mtime" $sec_mtime $sec 1 -v
_within_tolerance "sec_ctime" $sec_ctime $sec 1 -v

_scratch_unmount >> $seqres.full 2>&1

# Test mount to ext3 then mount back to ext4 and check timestamp again.  We
# ignore if ext3 failed to mount. It can happen because some mount options are
# incompatible with ext3. Still the test makes sense.
_mount -t ext3 `_scratch_mount_options $*` >> $seqres.full 2>&1 && _scratch_unmount >> $seqres.full 2>&1
_scratch_mount

nsec_atime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file atime nsec`
nsec_mtime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file mtime nsec`
nsec_ctime2=`$here/src/t_get_file_time $SCRATCH_MNT/tmp_file ctime nsec`

[ $nsec_atime -ne $nsec_atime2 ] && echo "File nanosecond timestamp atime has changed unexpected from $nsec_atime to $nsec_atime2"
[ $nsec_mtime -ne $nsec_mtime2 ] && echo "File nanosecond timestamp mtime has changed unexpected from $nsec_mtime to $nsec_mtime2"
[ $nsec_ctime -ne $nsec_ctime2 ] && echo "File nanosecond timestamp ctime has changed unexpected from $nsec_ctime to $nsec_ctime2"

status=0
exit