]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (chmem) add missing tests
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Sun, 17 May 2026 13:02:31 +0000 (09:02 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Tue, 26 May 2026 10:59:20 +0000 (06:59 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
tests/commands.sh
tests/expected/chmem/x86_64_16g-enable-disable-blocks [new file with mode: 0644]
tests/expected/chmem/x86_64_16g-enable-disable-zone [new file with mode: 0644]
tests/expected/chmem/x86_64_16g-enable-disable-zone.err [new file with mode: 0644]
tests/ts/chmem/sysfs-dumps/x86_64_16g.tar.bz2 [new file with mode: 0644]
tests/ts/chmem/x86_64_16g [new file with mode: 0755]

index e3cc1ddfc142f1f32bb11564a8ab970d30eaafec..9a1cf3161b642e7068ef0b3f23f678f7fc5c3c63 100644 (file)
@@ -79,6 +79,7 @@ TS_CMD_BITS=${TS_CMD_BITS-"${ts_commandsdir}bits"}
 TS_CMD_BLKDISCARD=${TS_CMD_BLKID-"${ts_commandsdir}blkdiscard"}
 TS_CMD_BLKID=${TS_CMD_BLKID-"${ts_commandsdir}blkid"}
 TS_CMD_CAL=${TS_CMD_CAL-"${ts_commandsdir}cal"}
+TS_CMD_CHMEM=${TS_CMD_CHMEM:-"${ts_commandsdir}chmem"}
 TS_CMD_CHOOM=${TS_CMD_CHOOM:-"${ts_commandsdir}choom"}
 TS_CMD_CHSH=${TS_CMD_CHSH:-"${ts_commandsdir}chsh"}
 TS_CMD_COLCRT=${TS_CMD_COLCRT:-"${ts_commandsdir}colcrt"}
diff --git a/tests/expected/chmem/x86_64_16g-enable-disable-blocks b/tests/expected/chmem/x86_64_16g-enable-disable-blocks
new file mode 100644 (file)
index 0000000..d6558bd
--- /dev/null
@@ -0,0 +1,2 @@
+offline
+online
diff --git a/tests/expected/chmem/x86_64_16g-enable-disable-zone b/tests/expected/chmem/x86_64_16g-enable-disable-zone
new file mode 100644 (file)
index 0000000..3991e46
--- /dev/null
@@ -0,0 +1,7 @@
+Memory Block 4 (0x0000000020000000-0x0000000027ffffff) disabled
+offline
+Memory Block 4 (0x0000000020000000-0x0000000027ffffff) enabled
+online_movable
+Memory Block 4 (0x0000000020000000-0x0000000027ffffff) already enabled
+
+
diff --git a/tests/expected/chmem/x86_64_16g-enable-disable-zone.err b/tests/expected/chmem/x86_64_16g-enable-disable-zone.err
new file mode 100644 (file)
index 0000000..c71b390
--- /dev/null
@@ -0,0 +1 @@
+chmem: Memory Block 4 (0x0000000020000000-0x0000000027ffffff) enable failed: Zone mismatch
diff --git a/tests/ts/chmem/sysfs-dumps/x86_64_16g.tar.bz2 b/tests/ts/chmem/sysfs-dumps/x86_64_16g.tar.bz2
new file mode 100644 (file)
index 0000000..5c9e11c
Binary files /dev/null and b/tests/ts/chmem/sysfs-dumps/x86_64_16g.tar.bz2 differ
diff --git a/tests/ts/chmem/x86_64_16g b/tests/ts/chmem/x86_64_16g
new file mode 100755 (executable)
index 0000000..5d5842c
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/env bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# Copyright (C) 2026 Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
+
+TS_TOPDIR="${0%/*}/../.."
+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"
+ts_check_prog "tar"
+
+_PATH_SYS_MEM="/sys/devices/system/memory"
+
+DUMP_NAME="x86_64_16g"
+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"
+
+do_chmem() {
+        "$TS_CMD_CHMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" "${@}" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
+}
+
+# The tests below are primarily testing the reads and writes
+# performed by chmem(8). Whether the performed actions have an
+# effect on the memory block settings, can only be tested on a
+# running Linux system. chmem(8) simply interacts with the kernel
+# ABI through the sysfs, i.e. reads or writes to the provided interfaces.
+
+ts_init_subtest "enable-disable-blocks"
+
+do_chmem --disable --blocks 0
+path_mem_state="${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/memory0/state"
+cat "$path_mem_state" >>"$TS_OUTPUT"
+true >"$path_mem_state"
+printf "\n" >>"$TS_OUTPUT"
+
+do_chmem --enable --blocks 0
+cat "$path_mem_state" >>"$TS_OUTPUT"
+printf "\n" >>"$TS_OUTPUT"
+
+ts_finalize_subtest
+
+
+ts_init_subtest "enable-disable-zone"
+
+# We will enable memory block 4 (memory4) on the Movable zone,
+# so let us make sure that it is disabled first.
+
+# In this subtest we will use a hexadecimal address range
+index="4"
+range_str="$("$TS_CMD_LSMEM" --sysroot "${DUMP_DIR}/${DUMP_NAME}" \
+                --all --output=BLOCK,RANGE --raw 2>>"$TS_ERRLOG" \
+                | sed -n "s/\(^$index\) \(.*\)/\2/p" 2>>"$TS_ERRLOG" \
+        )"
+mem_block="memory${index}"
+
+# We need to enable the "Movable" zone on this block first
+# otherwise chmem will complain about a zone mismatch
+echo "Movable" >"${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/valid_zones"
+
+
+do_chmem --verbose --disable "$range_str"
+path_mem_state="${DUMP_DIR}/${DUMP_NAME}/${_PATH_SYS_MEM}/${mem_block}/state"
+cat "$path_mem_state" >>"$TS_OUTPUT"
+true >"$path_mem_state"
+printf "\n" >>"$TS_OUTPUT"
+
+do_chmem --verbose --enable --zone "Movable" "$range_str"
+cat "$path_mem_state" >>"$TS_OUTPUT"
+printf "\n" >>"$TS_OUTPUT"
+
+# Should report that it is already enabled
+do_chmem --verbose --enable "$range_str"
+true >"$path_mem_state"
+printf "\n" >>"$TS_OUTPUT"
+
+# Should report a zone mismatch
+do_chmem --verbose --enable --zone "Normal" "$range_str"
+cat "$path_mem_state" >>"$TS_OUTPUT"
+printf "\n" >>"$TS_OUTPUT"
+
+ts_finalize_subtest
+
+
+ts_finalize