generic/528: take fs timestamps granularity into account in tolerance interval
[xfstests-dev.git] / tests / generic / 528
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 528
6 #
7 # Check that statx btime (aka creation time) is plausibly close to when
8 # we created a file.  A bug caught during code review of xfs patches revealed
9 # that there weren't any sanity checks of the btime values.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick
13 testfile=$TEST_DIR/$seq.txt
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         rm -f $tmp.* $testfile
20 }
21
22 # Import common functions.
23 . ./common/attr
24 . ./common/filter
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_test
29 _require_xfs_io_command "statx" "-r"
30 _require_btime
31
32 rm -f $testfile
33
34 # Create a file and the time we created it
35 now=$(date +%s)
36 touch $testfile
37
38 # Make sure the reported btime is within 5 seconds of the time we recorded
39 # just prior to creating the file.
40 btime=$(date +%s -d "$($XFS_IO_PROG -c "statx -v -m $STATX_BTIME" $testfile | \
41         grep 'stat.btime =' | cut -d '=' -f 2)")
42 test -n "$btime" || echo "error: did not see btime in output??"
43
44 _within_tolerance "btime" "$btime" "$now" 1 5 -v
45
46 status=0
47 exit