patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Cc: Yureka <yuka@yuka.dev>
Subject: [PATCH 4/8] release/checks/integration: extract config struct
Date: Fri, 13 Jun 2025 16:05:04 +0200	[thread overview]
Message-ID: <20250613140508.76998-5-hi@alyssa.is> (raw)
In-Reply-To: <20250613140508.76998-1-hi@alyssa.is>

This will make it easier to share code between tests, especially as we
add more things that tests might want to optionally customise.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
 release/checks/integration/networking.c | 39 ++++++++++++++++---------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/release/checks/integration/networking.c b/release/checks/integration/networking.c
index 44dccf3..efc7b44 100644
--- a/release/checks/integration/networking.c
+++ b/release/checks/integration/networking.c
@@ -176,14 +176,21 @@ static void wait_for_prompt(FILE *console)
 	exit(EXIT_FAILURE);
 }
 
-static FILE *start_qemu(const char *tmp_dir, const char *run_qemu,
-                        const char *efi, const char *img, const char *user_data)
+struct config {
+	const char *run_qemu;
+
+	struct {
+		const char *efi, *img, *user_data;
+	} drives;
+};
+
+static FILE *start_qemu(const char *tmp_dir, struct config c)
 {
 	FILE *console;
 	struct utsname u;
 	int console_listener, console_conn;
 	char *arch, *args[] = {
-		(char *)run_qemu,
+		(char *)c.run_qemu,
 		"-serial", nullptr,
 		"-drive", nullptr,
 		"-drive", nullptr,
@@ -227,14 +234,14 @@ static FILE *start_qemu(const char *tmp_dir, const char *run_qemu,
 			exit(EXIT_FAILURE);
 		}
 
-		if (asprintf(&args[4], "file=%s,format=raw,if=pflash,readonly=true", efi) == -1 ||
-		    asprintf(&args[6], "file=%s,format=raw,if=virtio,readonly=true", img) == -1 ||
-		    asprintf(&args[8], "file=%s,format=raw,if=virtio,readonly=true", user_data) == -1) {
+		if (asprintf(&args[4], "file=%s,format=raw,if=pflash,readonly=true", c.drives.efi) == -1 ||
+		    asprintf(&args[6], "file=%s,format=raw,if=virtio,readonly=true", c.drives.img) == -1 ||
+		    asprintf(&args[8], "file=%s,format=raw,if=virtio,readonly=true", c.drives.user_data) == -1) {
 			perror("asprintf");
 			exit(EXIT_FAILURE);
 		}
 
-		execv(run_qemu, args);
+		execv(c.run_qemu, args);
 		perror("execv");
 		exit(EXIT_FAILURE);
 	}
@@ -296,12 +303,17 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	char *run_qemu = argv[1];
-	char *efi = argv[2];
-	char *img = argv[3];
-	char *user_data = argv[4];
+	struct config c = {
+		.run_qemu = argv[1],
+		.drives = {
+			.efi = argv[2],
+			.img = argv[3],
+			.user_data = argv[4],
+		},
+	};
 
-	if (strchr(efi, ',') || strchr(img, ',') || strchr(user_data, ',')) {
+	if (strchr(c.drives.efi, ',') || strchr(c.drives.img, ',') ||
+	    strchr(c.drives.user_data, ',')) {
 		fputs("arguments contain commas\n", stderr);
 		exit(EXIT_FAILURE);
 	}
@@ -313,8 +325,7 @@ int main(int argc, char *argv[])
 
 	int server = setup_server();
 
-	FILE *console = start_qemu(make_tmp_dir(), run_qemu, efi, img,
-	                           user_data);
+	FILE *console = start_qemu(make_tmp_dir(), c);
 
 	if (fputs("set -euxo pipefail\n"
 	          "mkdir /run/mnt\n"
-- 
2.49.0


  parent reply	other threads:[~2025-06-13 14:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-13 14:05 [PATCH 0/8] Change serial getty instances dynamically Alyssa Ross
2025-06-13 14:05 ` [PATCH 1/8] host/rootfs: poll active consoles for serial getty Alyssa Ross
2025-06-28 19:54   ` Alyssa Ross
2025-06-13 14:05 ` [PATCH 2/8] release/checks/integration: init from networking Alyssa Ross
2025-06-28 19:54   ` Alyssa Ross
2025-06-13 14:05 ` [PATCH 3/8] release/checks/integration: use default Meson timeout Alyssa Ross
2025-06-13 14:05 ` Alyssa Ross [this message]
2025-06-28 19:54   ` [PATCH 4/8] release/checks/integration: extract config struct Alyssa Ross
2025-06-13 14:05 ` [PATCH 5/8] release/checks/integration: run from tmpdir Alyssa Ross
2025-06-13 14:05 ` [PATCH 6/8] release/checks/integration: name QEMU arg pointers Alyssa Ross
2025-06-28 19:54   ` Alyssa Ross
2025-06-13 14:05 ` [PATCH 7/8] release/checks/integration: extract library Alyssa Ross
2025-06-28 19:54   ` Alyssa Ross
2025-06-13 14:05 ` [PATCH 8/8] release/checks/integration: test late serial Alyssa Ross
2025-06-28 19:54   ` Alyssa Ross

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=20250613140508.76998-5-hi@alyssa.is \
    --to=hi@alyssa.is \
    --cc=devel@spectrum-os.org \
    --cc=yuka@yuka.dev \
    /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.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).