ext4/048: add check for od endian flag
authorLeah Rumancik <lrumancik@google.com>
Mon, 7 Jun 2021 21:36:38 +0000 (21:36 +0000)
committerEryu Guan <guaneryu@gmail.com>
Sun, 13 Jun 2021 15:39:50 +0000 (23:39 +0800)
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>
Reviewed-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc
tests/ext4/048

index 4efd436414db6e2e21bca21f624fbb6a8432a7fe..d4ad421ed5c7f09ed00a951afe8b75531cc80d1e 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -4593,6 +4593,12 @@ _getcap()
        return ${PIPESTATUS[0]}
 }
 
        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
 
 ################################################################################
 init_rc
 
 ################################################################################
index 35d3ece809e9d8a76c67b38352d8689f786cbff6..511896189c421cae5bace3078afe8561444b3190 100755 (executable)
@@ -26,6 +26,11 @@ _supported_fs ext4
 _require_scratch
 _require_command "$DEBUGFS_PROG" debugfs
 
 _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
 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() {
 # 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)
 }
 
 # reads portion of dirent that should be zero'd out (starting at offset of name_len = 6)