generic: test for file fsync after moving it to a new parent directory
[xfstests-dev.git] / tests / generic / 120
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 120
6 #
7 # Test noatime mount option.
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 "rm -f $tmp.*; exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21
22 # real QA test starts here
23 _supported_fs generic
24 _supported_os Linux
25
26 _require_scratch
27 _require_atime
28
29 _scratch_mkfs >/dev/null 2>&1 || _fail "mkfs failed"
30
31 _compare_access_times()
32 {
33         original_access_time="`cat $tmp.out | sed -n '5p'|awk '{ print substr($0,0,32)}'`"
34         accessed_time="`src/lstat64 $1 | sed -n '5p'| awk '{ print substr($0,0,32)}'`"
35         echo "*** compare access times ***"
36         if [ "$original_access_time" != "$accessed_time" ]
37                 then
38                 echo "*** file access time updated on $2 (unexpected) ***"
39                 cat $tmp.out
40                 echo "---------------------------------------------------"
41                 src/lstat64 $1
42                 mount | grep $SCRATCH_MNT
43         fi
44
45 }
46
47 if ! _try_scratch_mount "-o noatime" >$tmp.out 2>&1
48 then
49     cat $tmp.out
50     echo "!!! mount failed"
51     exit
52 fi
53
54 #executable file
55 echo "*** copying file ***"
56 cp src/lstat64 $SCRATCH_MNT
57 src/lstat64 $SCRATCH_MNT/lstat64 >$tmp.out
58 sleep 5
59 echo "*** executing file ***"
60 $SCRATCH_MNT/lstat64 $SCRATCH_MNT/lstat64 >/dev/null
61 _compare_access_times $SCRATCH_MNT/lstat64 "executing file"
62
63 #reading file
64 echo "*** creating file ***"
65 touch $SCRATCH_MNT/testfile
66 src/lstat64 $SCRATCH_MNT/testfile >$tmp.out
67 sleep 5
68 echo "*** reading file ***"
69 cat $SCRATCH_MNT/testfile >/dev/null
70 _compare_access_times $SCRATCH_MNT/testfile "reading file"
71
72 #writing file
73 echo "*** creating file ***"
74 touch $SCRATCH_MNT/testfile2
75 src/lstat64 $SCRATCH_MNT/testfile2 >$tmp.out
76 sleep 5
77 echo "*** writing to file ***"
78 echo "asdf" >> $SCRATCH_MNT/testfile2
79 _compare_access_times $SCRATCH_MNT/testfile2 "writing file"
80
81 _scratch_unmount
82
83 # success, all done
84 status=0
85 exit