public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4/048: add check for od endian flag
@ 2021-06-07 21:36 Leah Rumancik
  2021-06-08  1:56 ` xuyang2018.jy
  0 siblings, 1 reply; 2+ messages in thread
From: Leah Rumancik @ 2021-06-07 21:36 UTC (permalink / raw)
  To: fstests; +Cc: guaneryu, xuyang2018.jy, Leah Rumancik, Leah Rumancik

From: Leah Rumancik <lrumancik@google.com>

od --endian=little is used to read bytes in little endian when on a
big endian machine. Update test ext4/048 to require od endian flag
support on big endian machines, otherwise, skip test.

Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
---
 common/rc      |  6 ++++++
 tests/ext4/048 | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index a0aa7300..70aa7176 100644
--- a/common/rc
+++ b/common/rc
@@ -4582,6 +4582,12 @@ _getcap()
 	return ${PIPESTATUS[0]}
 }
 
+_require_od_endian_flag()
+{
+	od --endian=little < /dev/null > /dev/null 2>&1 || \
+		_notrun "od does not support endian flag"
+}
+
 init_rc
 
 ################################################################################
diff --git a/tests/ext4/048 b/tests/ext4/048
index 35d3ece8..51189618 100755
--- a/tests/ext4/048
+++ b/tests/ext4/048
@@ -26,6 +26,11 @@ _supported_fs ext4
 _require_scratch
 _require_command "$DEBUGFS_PROG" debugfs
 
+big_endian=$(echo -ne '\x11' | od -tx2 | head -1 | cut -f2 -d' ' | cut -c1)
+if (( big_endian )); then
+	_require_od_endian_flag
+fi
+
 testdir="${SCRATCH_MNT}/testdir"
 
 # get block number filename's dir ent
@@ -44,7 +49,13 @@ get_offset() {
 # argument 1: block
 # argument 2: offset
 get_reclen() {
-	echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An  --endian=little | tr -d ' \t\n\r')
+	if (( big_endian )); then
+		echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An  --endian=little | \
+			tr -d ' \t\n\r')
+	else
+		echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An | \
+			tr -d ' \t\n\r')
+	fi
 }
 
 # reads portion of dirent that should be zero'd out (starting at offset of name_len = 6)
-- 
2.32.0.rc1.229.g3e70b5a671-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4/048: add check for od endian flag
  2021-06-07 21:36 [PATCH] ext4/048: add check for od endian flag Leah Rumancik
@ 2021-06-08  1:56 ` xuyang2018.jy
  0 siblings, 0 replies; 2+ messages in thread
From: xuyang2018.jy @ 2021-06-08  1:56 UTC (permalink / raw)
  To: Leah Rumancik; +Cc: fstests@vger.kernel.org, guaneryu@gmail.com, Leah Rumancik

on 2021/6/8 5:36, Leah Rumancik wrote:
> From: Leah Rumancik<lrumancik@google.com>
> 
> od --endian=little is used to read bytes in little endian when on a
> big endian machine. Update test ext4/048 to require od endian flag
> support on big endian machines, otherwise, skip test.
> 
Looks good to me,
Reviewed-by: Yang Xu <xuyang2018.jy@fujitsu.com>

> Signed-off-by: Leah Rumancik<leah.rumancik@gmail.com>
> ---
>   common/rc      |  6 ++++++
>   tests/ext4/048 | 13 ++++++++++++-
>   2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index a0aa7300..70aa7176 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4582,6 +4582,12 @@ _getcap()
>   	return ${PIPESTATUS[0]}
>   }
> 
> +_require_od_endian_flag()
> +{
> +	od --endian=little<  /dev/null>  /dev/null 2>&1 || \
> +		_notrun "od does not support endian flag"
> +}
> +
>   init_rc
> 
>   ################################################################################
> diff --git a/tests/ext4/048 b/tests/ext4/048
> index 35d3ece8..51189618 100755
> --- a/tests/ext4/048
> +++ b/tests/ext4/048
> @@ -26,6 +26,11 @@ _supported_fs ext4
>   _require_scratch
>   _require_command "$DEBUGFS_PROG" debugfs
> 
> +big_endian=$(echo -ne '\x11' | od -tx2 | head -1 | cut -f2 -d' ' | cut -c1)
> +if (( big_endian )); then
> +	_require_od_endian_flag
> +fi
> +
>   testdir="${SCRATCH_MNT}/testdir"
> 
>   # get block number filename's dir ent
> @@ -44,7 +49,13 @@ get_offset() {
>   # argument 1: block
>   # argument 2: offset
>   get_reclen() {
> -	echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An  --endian=little | tr -d ' \t\n\r')
> +	if (( big_endian )); then
> +		echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An  --endian=little | \
> +			tr -d ' \t\n\r')
> +	else
> +		echo $(od $SCRATCH_DEV --skip-bytes=$(($1 * $blocksize + $2 + 4)) --read-bytes=2  -d -An | \
> +			tr -d ' \t\n\r')
> +	fi
>   }
> 
>   # reads portion of dirent that should be zero'd out (starting at offset of name_len = 6)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-08  1:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-07 21:36 [PATCH] ext4/048: add check for od endian flag Leah Rumancik
2021-06-08  1:56 ` xuyang2018.jy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox