From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7268B60A6F62 for ; Wed, 2 Dec 2026 00:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Sk5HWz6a; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=CTTTYnga DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=aKQT30cn2pf/y3b+kQGkBs5TU2t9zD5yc76Bsizq4bU=; b=Sk5HWz6aoRSWE7fMWgjWtqi91b I9czy0FLv2N44H+zaWUY13H0YuoeFobKfOejESHH3n3MhX6zuHMuqzp0XaeyhZ0QlF7nslEk+A/FA z/AkHTwhFgsXamimZbOmskcnMTxZpUfEsDlkeTqMOnirqgOwgDD4YLfEUosb38YJ3abbQjjnxPAQW ePp6luIjRJsBc3RUxyJ00s38gW6BibOPCekFO2ZPkQWNYKjrhWW3w7slGTTfAB3X8YpHr99tWcOZc f13MZRUA0g1tX3CXAB4yCIz7qi3C+BMtK7IuvgMrWnGq/ZU9OKlBn+jgt4vkQqyBBx8oirYHNZ/6O jOAqrELA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOQ-00000009mEx-1xU7; Wed, 02 Dec 2026 00:40:18 +0000 Received: from mail-oi1-x246.google.com ([2607:f8b0:4864:20::246]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOF-00000009lvB-1LgL for kexec@lists.infradead.org; Wed, 02 Dec 2026 00:40:12 +0000 Received: by mail-oi1-x246.google.com with SMTP id 5614622812f47-57ce46ad0c1so13070336b6e.2 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=1796172006; x=1796776806; darn=lists.infradead.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=CTTTYngazdoiIchlCweoJbTIKjaWNr44SnC3MPAo7bYjxW6G4KUv6CZMkOQtwSfyMz 8XNnggX53i6NYF1CHrsqGux6uC8lb2GNRdwPyfJddF347LEi6aqHLlIQNCBaPjQmBi3J bOudsduhECRDEvzsQIZyrreAA/gwZg+6c/FeQ7VlnmIyX+ybbrJOUKkXWN0jpfGgUhxI JAyNUc6jMcCJvZb7p9koNOoQmwDC++wRAz8leXUL+B8sOET7sS0GR09wPiOyGMitVjw/ bZs53/UlgWMb/uaLcX3KEk3iuGVf6eTqr17SHyREtXG0CKeq3wv6vTUisFcs+sdBt67A s7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796172006; x=1796776806; 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=EKk4XhPlgwE2hl8DrnwqpbNWbj9PAo8s5lVPygndllaTN7weFt5MDGsF2/OgKUdm5h JLGoH+aKMWzpHFTpMADieL29h9Ra/aHRgCICfQ3aZNWLTfCLDl0d+IiQeywmmMiZjb4i Yhnx1AsL8H8f9iDLpJtmoR6FtM+gKVYb93+Se48esYZiD+GwJseA+TAwcHjWrMsHPdkg fBHSMKloWu7FL4OEBXrKeDXKJd0iEAMdtL2K3ZerXz8284wBN2RCB76Wy8+O1rS/EDkB bVETIXxlEHTBuTlPhgTPHGRzYVDqRFIOvecCD18MwgsYV8x+R9p8Vv4PJ8mTuQczUxJy MlHQ== X-Gm-Message-State: APuU4Z+haMZjhNFRJcrRxdMVEW99TR7TTgVwOgzKY/U99aXKggZrWmQW RXEcBHTUm4fgB7b6mVTW2VKBvSy+Lb+naoTHVu5I5GSSyqERFT7sL7pgHYKtLqeFWOZCGdvPj17 045UR4qc2Qx/+RwDcadNX1aqowYtlh6gnOfGFonTqqaV37+URrz6Rg1KQ2DyxSVUgb3Woi5K73N FLK/36mbygo6IiapMRlWWRJMW20JUQwJd/p+JDj2AHUbQ1a9ZRxvo= 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-Archived-By: 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_164007_470682_F0C1AE51 X-CRM114-Status: GOOD ( 21.17 ) X-Spam-Score: -9.5 (---------) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F0DF606A335 for ; Wed, 2 Dec 2026 00:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PB+j2357; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=fQT91I/d DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=ZtMfVauA/psFjJ7NOQcnwSrYohBx79bzTGp6RCAD8as=; b=PB+j2357cUja6dMhbo59P4Pg/w xibqj3c0viW1eJpvqxCCGrKhdaJHBrvsGiO6TfdzJFyUnbTsrCjd5kVPtmVpQuuRQdQ7uE4FJLNCS GL7qNc+X1/g6gu+2QQ8t395UlJIgWGj2qi5XTkdCLH3NY0jynzK7Yh9NnIZtBTqzGXKNqFaCmQBlO YCS9QXDwYsRe3YnmTn1XRVHUux+aGuxJwXYK0fML5wxZe96XTG2l+RSvwPQNb3gClnpVRDCNdRyot 7RZSIKNfZKX8wnqtxzBSYr1Qwk0DIa2/Jy6TdE/V9F/AgU430xUt3BKmjIg5nJbz9VJcmmQWLud6w ZoPpG76g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOO-00000009mAb-1x4m; Wed, 02 Dec 2026 00:40:16 +0000 Received: from mail-oi1-x245.google.com ([2607:f8b0:4864:20::245]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYYOF-00000009lux-1CQV for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 00:40:12 +0000 Received: by mail-oi1-x245.google.com with SMTP id 5614622812f47-4e778acdbc6so14888238b6e.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=lists.infradead.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=fQT91I/dcTJYO7bps81iH2Kv2L9lTEoA+1HSRrD1w/3qRHi/zh/yAFEwj+me5pIJdf 2LnkRMfurIRjMnXOGWT6SzJWQ/jfpw/IC82vkIrL7jwYQnXc2ZofSa4Li71ISKWY+aAQ Kmid5RHt9ksH+K/7WepO/XBAtbjSExcgrIqt7cRFl608lUc/hJTHW1ApfZRgrkI2dM1Y riLaZT0ZHE9dGhtzzNjAWkQwgqJEiiNm2Si15nnov9YngdC88ahPSM8RTwEd0aUb1Q7u rVl2jvkhZe0QrXpyfcxZ5brjET+cVMtfh9ImMIoSh3Wj1HWeYAfY4YrhQYoH+8vNzR0V OXyw== 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=iuZnJNuOurIVOfG4ln2DA+NiVLiQLmv76qMLTjGLIJhuHl8+KLRgf66bpsWG8vGEq3 Hh8v3AkQ9DKK40wnvpbKqGx5uJAtAcYm+eeTU2LFQWgWERNJ6PF6Cmqj/cia74YZMdbN hFwzw5mHi6GedauhaidwLkmH42FaBLBq1d1iMhxSfVotI9+ZbCjt/pWUuVcNwh3M15b7 GepLTelKy4SOJt2qJW4LsRg5PLRTxMvzX0M/Q9z9UibRg+FmDzEhqcwhUpquWnyMRVBo hsRzCOs6e2o0cnT69jCdFAFF/Ysgy3t3xizOWmZhLXLBzlF5q0wp3nzY0G+eFLPeS1ux 1fzQ== X-Forwarded-Encrypted: i=1; AL+hErHv6CrgMmfrV3xQDbEBgsHcgHBJ/lB23/ObAtsMzYx48a0IW6xQy0E1hVGh+ZQDJUUl0I19A1ppEbRaWw==@lists.infradead.org X-Gm-Message-State: APuU4Z/0gayeCSLTWw4mBYRSRgVQG6ZDvG+b+7R0XJK/mz3HtkX2j7b1 EMLuDbhX0zbV8hDuOcvsCqAAz47mHBa2L53iers5euUhB3xKrJe1ePvkR9peEAd7xcdhvo/SkWt 9fn5qFABRZm7L8w== 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-Archived-By: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_164007_373923_FE874BF0 X-CRM114-Status: GOOD ( 20.80 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv