From: Eric Chanudet <[email protected]> Currently vmtest-dmem.sh relies on the host's running kernel or a pre-built one when booting the virtme-ng VM, with no option to configure and build a local kernel tree directly.
This adds friction to the development cycle: the user must manually run vng --kconfig with the correct config fragment, build the kernel, and pass the result to the script. Add a -b flag that automates this workflow. When set, handle_build() configures the kernel using vng --kconfig with the selftest config fragment, builds it with make -j$(nproc), and vm_start() passes the local tree to vng --run so the VM boots the freshly built kernel. Signed-off-by: Eric Chanudet <[email protected]> Signed-off-by: Albert Esteve <[email protected]> --- tools/testing/selftests/cgroup/vmtest-dmem.sh | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/vmtest-dmem.sh b/tools/testing/selftests/cgroup/vmtest-dmem.sh index 9524dbddb06b7..b6e4777285c1b 100755 --- a/tools/testing/selftests/cgroup/vmtest-dmem.sh +++ b/tools/testing/selftests/cgroup/vmtest-dmem.sh @@ -23,6 +23,7 @@ readonly WAIT_TOTAL=$((WAIT_PERIOD * WAIT_PERIOD_MAX)) readonly QEMU_PIDFILE="$(mktemp /tmp/qemu_dmem_vmtest_XXXX.pid)" readonly QEMU_OPTS=" --pidfile ${QEMU_PIDFILE} " +BUILD=0 QEMU="qemu-system-$(uname -m)" VERBOSE=0 SHELL_MODE=0 @@ -31,6 +32,7 @@ GUEST_TREE="${GUEST_TREE:-$KERNEL_CHECKOUT}" usage() { echo echo "$0 [OPTIONS]" + echo " -b Build kernel from source tree before booting" echo " -q <qemu> QEMU binary/path (default: ${QEMU})" echo " -s Start interactive shell in VM" echo " -v Verbose output (vng boot logs on stdout)" @@ -72,17 +74,46 @@ check_deps() { done } +handle_build() { + if [[ ! "${BUILD}" -eq 1 ]]; then + return + fi + + if [[ ! -d "${KERNEL_CHECKOUT}" ]]; then + echo "-b requires vmtest-dmem.sh called from the kernel source tree" >&2 + exit 1 + fi + + pushd "${KERNEL_CHECKOUT}" &>/dev/null + + if ! vng --kconfig --config "${SCRIPT_DIR}"/config; then + die "failed to generate .config for kernel source tree (${KERNEL_CHECKOUT})" + fi + + if ! make -j"$(nproc)"; then + die "failed to build kernel from source tree (${KERNEL_CHECKOUT})" + fi + + popd &>/dev/null +} + vm_start() { local logfile=/dev/null local verbose_opt="" + local kernel_opt="" if [[ "${VERBOSE}" -eq 1 ]]; then verbose_opt="--verbose" logfile=/dev/stdout fi + if [[ "${BUILD}" -eq 1 ]]; then + kernel_opt="${KERNEL_CHECKOUT}" + fi + vng \ --run \ + ${kernel_opt} \ ${verbose_opt} \ --qemu-opts="${QEMU_OPTS}" \ --qemu="$(command -v "${QEMU}")" \ @@ -165,10 +196,11 @@ run_test() { vm_ssh -- "cd '${GUEST_TREE}' && ./tools/testing/selftests/cgroup/test_dmem" } -while getopts ":hvq:s" o; do +while getopts ":hvq:sb" o; do case "${o}" in v) VERBOSE=1 ;; q) QEMU="${OPTARG}" ;; + b) BUILD=1 ;; s) SHELL_MODE=1 ;; h|*) usage ;; esac @@ -177,6 +209,7 @@ done trap cleanup EXIT check_deps +handle_build echo "Booting virtme-ng VM..." vm_start vm_wait_for_ssh -- 2.53.0

