diff mbox series

[1/3] generic/402: skip test if xfs_io can't parse the date value

Message ID 158328999421.2374922.12052887381904972734.stgit@magnolia (mailing list archive)
State New, archived
Headers show
Series fstests: random stuff | expand

Commit Message

Darrick J. Wong March 4, 2020, 2:46 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

If xfs_io's utimes command cannot interpret the arguments that are given
to it, it will print out "Bad value for [am]time".  Detect when this
happens and drop the file out of the test entirely.

This is particularly noticeable on 32-bit platforms and the largest
timestamp seconds supported by the filesystem is INT_MAX.  In this case,
the maximum value we can cram into tv_sec is INT_MAX, and there is no
way to actually test setting a timestamp of INT_MAX + 1 to test the
clamping.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
 tests/generic/402 |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Zorro Lang March 6, 2020, 9:33 a.m. UTC | #1
On Tue, Mar 03, 2020 at 06:46:34PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> If xfs_io's utimes command cannot interpret the arguments that are given
> to it, it will print out "Bad value for [am]time".  Detect when this
> happens and drop the file out of the test entirely.
> 
> This is particularly noticeable on 32-bit platforms and the largest
> timestamp seconds supported by the filesystem is INT_MAX.  In this case,
> the maximum value we can cram into tv_sec is INT_MAX, and there is no
> way to actually test setting a timestamp of INT_MAX + 1 to test the
> clamping.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> ---

Looks good to me.

>  tests/generic/402 |   20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/tests/generic/402 b/tests/generic/402
> index 2a34d127..2481a5d2 100755
> --- a/tests/generic/402
> +++ b/tests/generic/402
> @@ -63,10 +63,26 @@ run_test_individual()
>  	# check if the time needs update
>  	if [ $update_time -eq 1 ]; then
>  		echo "Updating file: $file to timestamp $timestamp"  >> $seqres.full
> -		$XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
> -		if [ $? -ne 0 ]; then
> +		rm -f $tmp.utimes
> +		$XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file > $tmp.utimes 2>&1
> +		local res=$?
> +
> +		cat $tmp.utimes >> $seqres.full
> +		if [ "$timestamp" -ne 0 ] && grep -q "Bad value" "$tmp.utimes"; then
> +			echo "xfs_io could not interpret time value \"$timestamp\", skipping \"$file\" test." >> $seqres.full
> +			rm -f $file $tmp.utimes
> +			return
> +		fi
> +		cat $tmp.utimes
> +		rm -f $tmp.utimes
> +		if [ $res -ne 0 ]; then
>  			echo "Failed to update times on $file" | tee -a $seqres.full
>  		fi
> +	else
> +		if [ ! -f "$file" ]; then
> +			echo "xfs_io did not create file for time value \"$timestamp\", skipping test." >> $seqres.full
> +			return
> +		fi
>  	fi
>  
>  	tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))
>
diff mbox series

Patch

diff --git a/tests/generic/402 b/tests/generic/402
index 2a34d127..2481a5d2 100755
--- a/tests/generic/402
+++ b/tests/generic/402
@@ -63,10 +63,26 @@  run_test_individual()
 	# check if the time needs update
 	if [ $update_time -eq 1 ]; then
 		echo "Updating file: $file to timestamp $timestamp"  >> $seqres.full
-		$XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
-		if [ $? -ne 0 ]; then
+		rm -f $tmp.utimes
+		$XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file > $tmp.utimes 2>&1
+		local res=$?
+
+		cat $tmp.utimes >> $seqres.full
+		if [ "$timestamp" -ne 0 ] && grep -q "Bad value" "$tmp.utimes"; then
+			echo "xfs_io could not interpret time value \"$timestamp\", skipping \"$file\" test." >> $seqres.full
+			rm -f $file $tmp.utimes
+			return
+		fi
+		cat $tmp.utimes
+		rm -f $tmp.utimes
+		if [ $res -ne 0 ]; then
 			echo "Failed to update times on $file" | tee -a $seqres.full
 		fi
+	else
+		if [ ! -f "$file" ]; then
+			echo "xfs_io did not create file for time value \"$timestamp\", skipping test." >> $seqres.full
+			return
+		fi
 	fi
 
 	tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))