mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Albert Esteve <aesteve@redhat.com>
To: "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Shuah Khan" <shuah@kernel.org>
Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	 linux-kselftest@vger.kernel.org,
	Albert Esteve <aesteve@redhat.com>,
	 mripard@kernel.org, echanude@redhat.com
Subject: [PATCH v4 4/4] selftests: cgroup: handle vmtest-dmem -b to test locally built kernel
Date: Tue, 19 May 2026 13:03:14 +0200	[thread overview]
Message-ID: <20260519-kunit_cgroups-v4-4-f6c2f498fae4@redhat.com> (raw)
In-Reply-To: <20260519-kunit_cgroups-v4-0-f6c2f498fae4@redhat.com>

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 run_vm() passes the
local tree to vng --run so the VM boots the freshly built kernel.

Signed-off-by: Eric Chanudet <echanude@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
 tools/testing/selftests/cgroup/vmtest-dmem.sh | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/vmtest-dmem.sh b/tools/testing/selftests/cgroup/vmtest-dmem.sh
index b395b7153f635..415c1722b08e7 100755
--- a/tools/testing/selftests/cgroup/vmtest-dmem.sh
+++ b/tools/testing/selftests/cgroup/vmtest-dmem.sh
@@ -15,6 +15,7 @@ readonly KERNEL_CHECKOUT="$(realpath "${SCRIPT_DIR}"/../../../../)"
 
 source "${SCRIPT_DIR}"/../kselftest/ktap_helpers.sh
 
+BUILD=0
 QEMU="qemu-system-$(uname -m)"
 VERBOSE=0
 SHELL_MODE=0
@@ -26,6 +27,7 @@ function usage() {
 	cat <<EOF
 $0 [OPTIONS]
 Options:
+	-b	Build kernel from source tree before booting
 	-q	QEMU binary/path (default: ${QEMU})
 	-s	Start interactive shell in VM instead of running tests
 	-v	Verbose output (vng boot logs on stdout)
@@ -60,16 +62,33 @@ function check_deps() {
 	done
 }
 
+function handle_build() {
+	[[ "${BUILD}" -eq 1 ]] || return 0
+
+	[[ -d "${KERNEL_CHECKOUT}" ]] || \
+		fail "-b requires vmtest-dmem.sh called from the kernel source tree"
+
+	pushd "${KERNEL_CHECKOUT}" &>/dev/null
+	vng --kconfig --config "${SCRIPT_DIR}"/config || \
+		fail "failed to generate .config for kernel source tree (${KERNEL_CHECKOUT})"
+	make O= KBUILD_OUTPUT= -j"$(nproc)" || \
+		fail "failed to build kernel from source tree (${KERNEL_CHECKOUT})"
+	popd &>/dev/null
+}
+
 # Run vng with common flags. Extra arguments are appended by the caller:
 #   --exec <script>  for automated test runs
 #   (nothing)        for interactive shell mode
 function run_vm() {
 	local verbose_opt=""
+	local kernel_opt=""
 
 	[[ "${VERBOSE}" -eq 1 ]] && verbose_opt="--verbose"
+	[[ "${BUILD}" -eq 1 ]] && kernel_opt="${KERNEL_CHECKOUT}"
 
 	vng \
 		--run \
+		${kernel_opt:+"${kernel_opt}"} \
 		${verbose_opt:+"${verbose_opt}"} \
 		--qemu="$(command -v "${QEMU}")" \
 		--user root \
@@ -78,10 +97,11 @@ function run_vm() {
 }
 
 function main() {
-	while getopts ':hvq:s' opt; do
+	while getopts ':hvq:sb' opt; do
 		case "${opt}" in
 		v) VERBOSE=1 ;;
 		q) QEMU="${OPTARG}" ;;
+		b) BUILD=1 ;;
 		s) SHELL_MODE=1 ;;
 		h) usage; exit 0 ;;
 		*) usage; exit 1 ;;
@@ -89,6 +109,7 @@ function main() {
 	done
 
 	check_deps
+	handle_build
 
 	if [[ "${SHELL_MODE}" -eq 1 ]]; then
 		echo "Starting interactive shell in VM. Exit to stop VM."

-- 
2.53.0


      parent reply	other threads:[~2026-05-19 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 11:03 [PATCH v4 0/4] cgroup: dmem: add selftest helper, coverage, and VM runner Albert Esteve
2026-05-19 11:03 ` [PATCH v4 1/4] cgroup: Add dmem_selftest module Albert Esteve
2026-05-19 11:03 ` [PATCH v4 2/4] selftests: cgroup: Add dmem selftest coverage Albert Esteve
2026-05-19 11:03 ` [PATCH v4 3/4] selftests: cgroup: Add vmtest-dmem runner script Albert Esteve
2026-05-19 11:03 ` Albert Esteve [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260519-kunit_cgroups-v4-4-f6c2f498fae4@redhat.com \
    --to=aesteve@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=echanude@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=mripard@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®