From: Karel Zak Date: Thu, 28 May 2026 09:05:55 +0000 (+0200) Subject: tests: use tar --no-same-owner for sysfs dump extraction X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6381d7c695a13eab1407475b93f58385ea28691;p=thirdparty%2Futil-linux.git tests: use tar --no-same-owner for sysfs dump extraction Use --no-same-owner when extracting sysfs dump tarballs so that extracted files are owned by the current user rather than preserving the original (often root) ownership from the archive. This allows chmem tests to run without root since they only operate on a local sysfs dump via --sysroot. The valid_zones file (0444 in real sysfs) needs an explicit chmod u+w before the test can write to it. Apply --no-same-owner to lsblk, lscpu, lsmem, and hardlink tests for consistency. Signed-off-by: Karel Zak --- diff --git a/tests/ts/chmem/aarch64_16k_16g b/tests/ts/chmem/aarch64_16k_16g index ad201e314..da075adf8 100755 --- a/tests/ts/chmem/aarch64_16k_16g +++ b/tests/ts/chmem/aarch64_16k_16g @@ -20,8 +20,6 @@ TS_DESC="aarch64_16k_16g" . "$TS_TOPDIR/functions.sh" ts_init "$*" -ts_skip_nonroot - ts_check_test_command "$TS_CMD_CHMEM" ts_check_test_command "$TS_CMD_LSMEM" ts_check_prog "bzip2" @@ -34,7 +32,7 @@ DUMP_FILENAME="$TS_SELF/sysfs-dumps/$DUMP_NAME.tar.bz2" DUMP_DIR="$TS_OUTDIR/sysfs-dumps" mkdir -p "$DUMP_DIR" -tar -C "$DUMP_DIR" -jxf "$DUMP_FILENAME" +tar --no-same-owner -C "$DUMP_DIR" -jxf "$DUMP_FILENAME" do_chmem() { "$TS_CMD_CHMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" "${@}" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" @@ -76,6 +74,7 @@ mem_block="memory${index}" # We need to enable the "Movable" zone on this block first # otherwise chmem will complain about a zone mismatch +chmod u+w "${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones" echo "Movable" >"${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones" diff --git a/tests/ts/chmem/x86_64_16g b/tests/ts/chmem/x86_64_16g index 5d5842c26..b27329349 100755 --- a/tests/ts/chmem/x86_64_16g +++ b/tests/ts/chmem/x86_64_16g @@ -20,8 +20,6 @@ TS_DESC="x86_64_16g" . "$TS_TOPDIR/functions.sh" ts_init "$*" -ts_skip_nonroot - ts_check_test_command "$TS_CMD_CHMEM" ts_check_test_command "$TS_CMD_LSMEM" ts_check_prog "bzip2" @@ -34,7 +32,7 @@ DUMP_FILENAME="$TS_SELF/sysfs-dumps/$DUMP_NAME.tar.bz2" DUMP_DIR="$TS_OUTDIR/sysfs-dumps" mkdir -p "$DUMP_DIR" -tar -C "$DUMP_DIR" -jxf "$DUMP_FILENAME" +tar --no-same-owner -C "$DUMP_DIR" -jxf "$DUMP_FILENAME" do_chmem() { "$TS_CMD_CHMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" "${@}" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" @@ -76,6 +74,7 @@ mem_block="memory${index}" # We need to enable the "Movable" zone on this block first # otherwise chmem will complain about a zone mismatch +chmod u+w "${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones" echo "Movable" >"${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones" diff --git a/tests/ts/hardlink/options b/tests/ts/hardlink/options index 64d2e0550..aba9dd2fb 100755 --- a/tests/ts/hardlink/options +++ b/tests/ts/hardlink/options @@ -32,7 +32,7 @@ SRCDIR="$TS_OUTDIR/testdir1" create_srcdir() { rm -rf "$SRCDIR" - tar -C "$TS_OUTDIR" -xJf "$TS_SELF/testdir1.tar.xz" + tar --no-same-owner -C "$TS_OUTDIR" -xJf "$TS_SELF/testdir1.tar.xz" } show_srcdir() diff --git a/tests/ts/lsblk/lsblk b/tests/ts/lsblk/lsblk index 2c83ffc7b..b429e64bb 100755 --- a/tests/ts/lsblk/lsblk +++ b/tests/ts/lsblk/lsblk @@ -31,7 +31,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.xz" | sort); do dumpdir="$TS_OUTDIR/dumps" mkdir -p $dumpdir - tar -C $dumpdir --xz -xf $dump + tar --no-same-owner -C $dumpdir --xz -xf $dump # # Read *.cols from the tarball, but the expected output is not used diff --git a/tests/ts/lscpu/lscpu b/tests/ts/lscpu/lscpu index 7c073835b..1c25405a6 100755 --- a/tests/ts/lscpu/lscpu +++ b/tests/ts/lscpu/lscpu @@ -33,7 +33,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.gz" | sort); do ts_init_subtest $name mkdir -p $dumpdir - tar -C $dumpdir -zxf $dump + tar --no-same-owner -C $dumpdir -zxf $dump # Architecture information is not applicable with -s. "${TS_CMD_LSCPU}" --sysroot "${dumpdir}/${name}" | \ diff --git a/tests/ts/lsmem/lsmem b/tests/ts/lsmem/lsmem index c3011dcb3..abcd42e28 100755 --- a/tests/ts/lsmem/lsmem +++ b/tests/ts/lsmem/lsmem @@ -43,7 +43,7 @@ for dump in $(find "$TS_SELF"/dumps/ -maxdepth 1 -name "*.tar.bz2" | sort); do ts_init_subtest $name mkdir -p $dumpdir - tar -C $dumpdir -jxf $dump + tar --no-same-owner -C $dumpdir -jxf $dump do_lsmem --split=STATE,REMOVABLE do_lsmem --output RANGE,SIZE --split none