From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796172006; b=SsYs+Ji3D8jdG0JypUjy/Y9tEVOeV7vBHIn5BJnTX6eSrGEmJLRNA4GrgHKh0nVJIzHR E40nxyme7eeiwD4Ytu0gBiQEGIFcRMfDP5KymZGxmxeE+tEgi4VjGi4fjcXTxTKaUZOFp zUSzKQqzs3ePcnDzkgCBeAhe5aQmY6acGRXp/83fpdgKdb3Q18PKEO5HkF5yjRyuYfiN6 /xz7bz7oMm/4A3N9MsbYz7HgBISV9UqIBOWv4ee9LFhJUXfiopMLDAtJBPyoQZop8VV6R xattqPhjCqjUDHpUZ/kS1d2f8YSLGtPaYk0SOJHvi0ZcKGCg2wCreL6g6Ewp4PiPbDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796172006; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=aKQT30cn2pf/y3b+kQGkBs5TU2t9zD5yc76Bsizq4bU=; b=OnLzNWPBWtVDrYUXeMWpM52Z9osnB/MH2/AAcMs+O0NfaJvBFQhF5vEC/7c7MSdVStbT QNbc0y8EV/sIzNlB3Epbsd8UWV75GvYyZ0QikPAZEAAyoncMbkWmeFqorPcB7PtmTEki7 tWRPF27bJMgqg15aN72RBrG6EoXPRY3L3VtnI/USlblDusSQSz35knPmnlsaGrxtHtTBD rD4C150RvA7W4eW/0aVuR8zdVgscXCC1yrSDAl0kwIT7j1j4dvZ/A8rvYVz9q50Lxa564 yUUj7GOAP73K8cTb2R+NBTuU+QH4/WkiIcGPwbo/6gVop9gWx0BObpgMcXWE3JkTeWg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=AKnzudHR; arc=none smtp.remote-ip=209.85.167.197 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C09B606A31A for ; Wed, 2 Dec 2026 00:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C09B606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=AKnzudHR Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-4e778acdbc6so14888236b6e.3 for ; Tue, 01 Dec 2026 16:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796172005; x=1796776805; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=aKQT30cn2pf/y3b+kQGkBs5TU2t9zD5yc76Bsizq4bU=; b=AKnzudHRTadvYv9jGRS6kMAwhKnoGv0T724ty1YxQzgeYM0/13QAsOgpf3cMAmLKMr yqUI9rVjn0XdRv29I1niJjI5rqAzKq1uMHHU1JHMuYHAZXD6T+HHjFAAzK4DLaayVZ8F JAz+GLlAp9Cc0PE7PMeAm6964QvSbGoaB4IusOFm693BiAhUXX3eOE6F8XigXWwzrdsp flQZERlT9NnOYWp0kmPf6jUeFn3SRPR/CKdHnpbtVfSYqSvGOWEQFpAjjcKmUt3/u+MV WO8/pRZYghCMKEESXmI/DjISjqc+hfvkMJA5iHcNiGQs9Dv2wea2sMC+eqIOiAph+ncm AzcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796172005; x=1796776805; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aKQT30cn2pf/y3b+kQGkBs5TU2t9zD5yc76Bsizq4bU=; b=rq3IYhMs1sb6j87cZW1EbvMlV/EfJABinDXiyNOyebH0i33Eppivimn31oYZW6Shfu PiSiuzGzS9WYBliK9DwD9vM1yvX3SoHJ4yHNBWFcWvQnQ0ZktvIy9j5b4PPxLC7APd9K ojIAvAThV0CPgQ5DQ1wuUZdksEna5Brj9kW3HOEelLm+Wv536oQ1JZAHBmuHV5N1enOd C5C09Vpfr4ND3JZytoiJlVNJgvMi8SNN3jBO488K0KhZUslj5Vw+ssMK8U7w+Ej/9EQM UxFxzG74xA6v/kJ8rBUGIGfEmHFnXGdv5WjjhUwJ3vgflcmVyUJHNhYKo3rBz7QsJ/Xp Cs5Q== X-Forwarded-Encrypted: i=1; AL+hErFpAvor8E5wsO3u9IIgA60p4TOD+rO10c2gTv1a21QyU05/dDyQ9l4w39nRyzOCUOp6NqwHOXCjBdTqv79jC+Q=@vger.kernel.org X-Gm-Message-State: APuU4Z8W9WMf8pu/MB/3JDIq7iepTlU3N0EvreXUJhLfa0x1CSf6aS88 v89oQg3pQSiQeV348qGtbqUuKnA0C56MgMt4Ob28PGNlCAGxooBH//3OlBsqvZglMvDIMbPBjLg VGCwb+5grDfg6Lg== X-Received: from iobp17-n2.prod.google.com ([2002:a05:6602:8691:20b0:9c7:6dd9:edb5]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1a0c:b0:4cb:818f:d56f with SMTP id 5614622812f47-57a0a4048femr41749037b6e.23.1796172005225; Tue, 01 Dec 2026 16:40:05 -0800 (PST) Date: Wed, 2 Dec 2026 00:39:43 +0000 In-Reply-To: <20261202003955.3607156-1-dmatlack@google.com> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202003955.3607156-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202003955.3607156-7-dmatlack@google.com> Subject: [PATCH 06/18] selftests/liveupdate: Support test definitions in vmtest.sh From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Albert Ou , Alexandre Ghiti , Alex Williamson , Bjorn Helgaas , David Matlack , Jacob Pan , Jason Gunthorpe , Josh Hilke , Lukas Wunner , Mike Rapoport , Palmer Dabbelt , Parav Pandit , Pasha Tatashin , Paul Walmsley , Pranjal Shrivastava , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , Vipin Sharma Content-Type: text/plain; charset="UTF-8" Allow a test to be described by a .vmtest.sh file, which vmtest.sh sources. A test definition can set the test binary to run and the arguments to pass to it, extra QEMU arguments, the QEMU timeout, and a host-side check to run after the test passes in the VM. vmtest.sh writes the arguments to /test_args in the initrds, and init passes them to the test binary in both stages. This lets tests that need more than the default VM, e.g. a specific PCI topology, keep their setup out of vmtest.sh. Test definitions can also live in subdirectories, e.g. "vmtest.sh -T pci/root_port". Signed-off-by: David Matlack --- tools/testing/selftests/liveupdate/init.c | 49 +++++++++++++++++++- tools/testing/selftests/liveupdate/vmtest.sh | 44 +++++++++++++++--- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/liveupdate/init.c b/tools/testing/selftests/liveupdate/init.c index 824c9da2facf..bcb401295801 100644 --- a/tools/testing/selftests/liveupdate/init.c +++ b/tools/testing/selftests/liveupdate/init.c @@ -19,6 +19,8 @@ #define KERNEL_IMAGE "/kernel" #define INITRD_IMAGE "/initrd.img" #define TEST_BINARY "/test_binary" +#define TEST_ARGS "/test_args" +#define MAX_TEST_ARGS 32 static int mount_filesystems(void) { @@ -95,21 +97,64 @@ static int kexec_load(void) return err; } +/* + * Split the contents of TEST_ARGS, if it exists, into @args at whitespace. + * Returns the number of arguments, or -1 on error. + */ +static int read_test_args(char *buf, size_t size, char **args, int max) +{ + int fd, nr_args = 0; + ssize_t len; + char *p; + + fd = open(TEST_ARGS, O_RDONLY); + if (fd < 0) + return 0; + + len = read(fd, buf, size - 1); + close(fd); + if (len < 0) + return -1; + buf[len] = 0; + + for (p = buf; *p; ) { + if (*p == ' ' || *p == '\n') { + *p++ = 0; + continue; + } + + if (nr_args == max) + return -1; + + args[nr_args++] = p; + while (*p && *p != ' ' && *p != '\n') + p++; + } + + return nr_args; +} + static int run_test(int stage) { + char *argv[3 + MAX_TEST_ARGS + 1] = {TEST_BINARY, "-s"}; char stage_arg[32]; + char args[1024]; int status; pid_t pid; snprintf(stage_arg, sizeof(stage_arg), "%d", stage); + argv[2] = stage_arg; + + if (read_test_args(args, sizeof(args), &argv[3], MAX_TEST_ARGS) < 0) { + fprintf(stderr, "INIT: Failed to read %s\n", TEST_ARGS); + return -1; + } pid = fork(); if (pid < 0) return -1; if (!pid) { - char *const argv[] = {TEST_BINARY, "-s", stage_arg, NULL}; - execve(TEST_BINARY, argv, NULL); fprintf(stderr, "INIT: execve failed\n"); _exit(1); diff --git a/tools/testing/selftests/liveupdate/vmtest.sh b/tools/testing/selftests/liveupdate/vmtest.sh index b24a8bb774ca..797190d4b47c 100755 --- a/tools/testing/selftests/liveupdate/vmtest.sh +++ b/tools/testing/selftests/liveupdate/vmtest.sh @@ -13,6 +13,25 @@ headers_dir="" initrd="" KEEP_WORKSPACE=0 +# A test named "foo" either runs the binary "foo" built by the Makefile, or is +# described by foo.vmtest.sh. A test definition is sourced after $arch, +# $target, $test_dir and $workspace_dir are set, and may override any of the +# following: +# +# TEST_BINARY Test binary to run, as named in the Makefile +# (default: the test name) +# TEST_ARGS Arguments for the test binary in both stages +# TEST_QEMU_ARGS Extra QEMU arguments +# TEST_TIMEOUT Timeout for the QEMU run +# test_check() Host-side check, run after the test passes in the VM +TEST_ARGS=() +TEST_QEMU_ARGS=() +TEST_TIMEOUT="30s" + +function test_check() { + return 0 +} + source "$test_dir/../kselftest/ktap_helpers.sh" function get_arch_conf() { @@ -42,7 +61,7 @@ Options: -d) path to the kernel build directory (default: .luo_test_build.) -j) number of jobs for compilation -t) run test for target_arch (aarch64, x86_64, riscv64) - -T) test name to run (default: luo_kexec_simple) + -T) test name to run, e.g. luo_kexec_simple or pci/root_port (default: luo_kexec_simple) -w) custom workspace directory (default: creates temp dir) -k) keep workspace directory -h) display this help @@ -138,17 +157,19 @@ function build_kernel() { function mkinitrd() { local build_dir=$1 local kernel_path=$2 - local test_name=$3 - local make_cmd=$4 + local make_cmd=$3 local output="$workspace_dir/build" local init="$output/init" - local test_binary="$output/$test_name" + local test_binary="$output/$TEST_BINARY" # Build the test binary and the init process mkdir -p "$output" $make_cmd -C "$test_dir" NOLIBC=1 OUTPUT="$output" \ KHDR_INCLUDES="-I$headers_dir/include" "$init" "$test_binary" + # init passes these to the test binary in both stages + echo "${TEST_ARGS[*]}" > "$workspace_dir/test_args" + cat > "$workspace_dir/cpio_list_inner" < /dev/null || fail "Liveupdate failed" + test_check || fail "Host-side check failed" } function target_to_arch() { @@ -248,6 +273,11 @@ function main() { local arch=$(target_to_arch "$target") + TEST_BINARY="$test_name" + if [ -f "$test_dir/$test_name.vmtest.sh" ]; then + source "$test_dir/$test_name.vmtest.sh" + fi + if [ -z "$build_dir" ]; then build_dir="$kernel_dir/.luo_test_build.$arch" fi @@ -262,7 +292,7 @@ function main() { build_kernel "$build_dir" "$make_cmd_build" "$KERNEL_IMAGE" "$target" local final_kernel="$build_dir/arch/$arch/boot/$KERNEL_IMAGE" - mkinitrd "$build_dir" "$final_kernel" "$test_name" "$make_cmd" + mkinitrd "$build_dir" "$final_kernel" "$make_cmd" run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$final_kernel" ktap_test_pass "$test_name succeeded" -- 2.56.1.911.g883d8bcb20-goog