generic/003: ensure time changes between stat calls

On a fast device like a ramdisk, kernel time may not have changed
between a stat of a file and some operation on it immediately
afterwards. Hence there is no guarantee that an operation actually
changes the timestamps of a file immediately after it is stat'd.

Hence, ensure that the times will change by sleeping for a second
between the initial stat that reads the timestamps and the
operations that is supposed to modify them. This way we ensure that
the timestamp will change if the filesystem is correctly
implemented.

While there, fix the indenting to be 8 space tabs and correct the
header which is missing the bash shell declaration and the test
number identifier.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Dave Chinner
2014-03-13 14:58:24 +11:00
committed by Dave Chinner
parent 97a665b5fc
commit 84edd7a868
+17 -5
View File
@@ -1,3 +1,6 @@
#! /bin/bash
# FS QA Test No. generic/003
#
# Tests the noatime, relatime, strictatime and nodiratime mount options. # Tests the noatime, relatime, strictatime and nodiratime mount options.
# There is an extra check for Btrfs to ensure that the access time is # There is an extra check for Btrfs to ensure that the access time is
# never updated on read-only subvolumes. (Regression test for bug fixed # never updated on read-only subvolumes. (Regression test for bug fixed
@@ -63,16 +66,15 @@ _compare_stat_times() {
for i in 0 1 2; do for i in 0 1 2; do
if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
if [ "${updated:$i:1}" == "Y" ]; then if [ "${updated:$i:1}" == "N" ]; then
continue;
fi
echo -n "ERROR: ${types[$i]} time has not been updated " echo -n "ERROR: ${types[$i]} time has not been updated "
echo $test_step echo $test_step
fi elif [ "${updated:$i:1}" == "N" ]; then
else
if [ "${updated:$i:1}" == "N" ]; then
echo -n "ERROR: ${types[$i]} time has changed " echo -n "ERROR: ${types[$i]} time has changed "
echo $test_step echo $test_step
fi fi
fi
done done
} }
@@ -91,12 +93,14 @@ echo "aaa" > $TPATH/dir1/file1
file1_stat_before_first_access=`_stat $TPATH/dir1/file1` file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
# Accessing file1 the first time # Accessing file1 the first time
sleep 1
cat $TPATH/dir1/file1 > /dev/null cat $TPATH/dir1/file1 > /dev/null
file1_stat_after_first_access=`_stat $TPATH/dir1/file1` file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
_compare_stat_times YNN "$file1_stat_before_first_access" \ _compare_stat_times YNN "$file1_stat_before_first_access" \
"$file1_stat_after_first_access" "after accessing file1 first time" "$file1_stat_after_first_access" "after accessing file1 first time"
# Accessing file1 a second time # Accessing file1 a second time
sleep 1
cat $TPATH/dir1/file1 > /dev/null cat $TPATH/dir1/file1 > /dev/null
file1_stat_after_second_access=`_stat $TPATH/dir1/file1` file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
_compare_stat_times NNN "$file1_stat_after_first_access" \ _compare_stat_times NNN "$file1_stat_after_first_access" \
@@ -112,6 +116,7 @@ _compare_stat_times NNN "$file1_stat_after_second_access" \
# Creating dir2 and file2, checking directory stats # Creating dir2 and file2, checking directory stats
mkdir $TPATH/dir2 mkdir $TPATH/dir2
dir2_stat_before_file_creation=`_stat $TPATH/dir2` dir2_stat_before_file_creation=`_stat $TPATH/dir2`
sleep 1
echo "bbb" > $TPATH/dir2/file2 echo "bbb" > $TPATH/dir2/file2
dir2_stat_after_file_creation=`_stat $TPATH/dir2` dir2_stat_after_file_creation=`_stat $TPATH/dir2`
_compare_stat_times NYY "$dir2_stat_before_file_creation" \ _compare_stat_times NYY "$dir2_stat_before_file_creation" \
@@ -119,6 +124,7 @@ _compare_stat_times NYY "$dir2_stat_before_file_creation" \
# Accessing file2 # Accessing file2
file2_stat_before_first_access=`_stat $TPATH/dir2/file2` file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
sleep 1
cat $TPATH/dir2/file2 > /dev/null cat $TPATH/dir2/file2 > /dev/null
file2_stat_after_first_access=`_stat $TPATH/dir2/file2` file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
_compare_stat_times YNN "$file2_stat_before_first_access" \ _compare_stat_times YNN "$file2_stat_before_first_access" \
@@ -132,6 +138,7 @@ _scratch_unmount
_scratch_mount "-o noatime" _scratch_mount "-o noatime"
echo "ccc" > $TPATH/dir2/file3 echo "ccc" > $TPATH/dir2/file3
file3_stat_before_first_access=`_stat $TPATH/dir2/file3` file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
sleep 1
cat $TPATH/dir2/file3 > /dev/null cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_first_access=`_stat $TPATH/dir2/file3` file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
_compare_stat_times NNN "$file3_stat_before_first_access" \ _compare_stat_times NNN "$file3_stat_before_first_access" \
@@ -139,10 +146,12 @@ _compare_stat_times NNN "$file3_stat_before_first_access" \
# Checking that the modify and change times are still updated # Checking that the modify and change times are still updated
file1_stat_before_modify=`_stat $TPATH/dir1/file1` file1_stat_before_modify=`_stat $TPATH/dir1/file1`
sleep 1
echo "xyz" > $TPATH/dir1/file1 echo "xyz" > $TPATH/dir1/file1
file1_stat_after_modify=`_stat $TPATH/dir1/file1` file1_stat_after_modify=`_stat $TPATH/dir1/file1`
_compare_stat_times NYY "$file1_stat_before_modify" \ _compare_stat_times NYY "$file1_stat_before_modify" \
"$file1_stat_after_modify" "after modifying file1" "$file1_stat_after_modify" "after modifying file1"
sleep 1
mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed` file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
_compare_stat_times NNY "$file1_stat_after_modify" \ _compare_stat_times NNY "$file1_stat_after_modify" \
@@ -156,6 +165,7 @@ cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_second_access=`_stat $TPATH/dir2/file3` file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
_compare_stat_times YNN "$file3_stat_after_first_access" \ _compare_stat_times YNN "$file3_stat_after_first_access" \
"$file3_stat_after_second_access" "after accessing file3 second time" "$file3_stat_after_second_access" "after accessing file3 second time"
sleep 1
cat $TPATH/dir2/file3 > /dev/null cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_third_access=`_stat $TPATH/dir2/file3` file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
_compare_stat_times YNN "$file3_stat_after_second_access" \ _compare_stat_times YNN "$file3_stat_after_second_access" \
@@ -167,6 +177,7 @@ if [ "$FSTYP" = "btrfs" ]; then
SPATH=$SCRATCH_MNT/snap1 SPATH=$SCRATCH_MNT/snap1
btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
dir2_stat_readonly_before_access=`_stat $SPATH/dir2` dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
sleep 1
ls $SPATH/dir2 >> $seqres.full ls $SPATH/dir2 >> $seqres.full
cat $SPATH/dir2/file3 >> $seqres.full cat $SPATH/dir2/file3 >> $seqres.full
dir2_stat_readonly_after_access=`_stat $SPATH/dir2` dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
@@ -179,6 +190,7 @@ fi
# Remounting read-only. Access time should never be updated, despite the # Remounting read-only. Access time should never be updated, despite the
# strictatime mount option. # strictatime mount option.
sleep 1
dir2_stat_before_ro_mount=`_stat $TPATH/dir2` dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3` file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
_scratch_unmount _scratch_unmount