public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nico Boehr <nrb@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com,
	pbonzini@redhat.com, andrew.jones@linux.dev, lvivier@redhat.com
Subject: [kvm-unit-tests PATCH v1 1/4] lib: add function to request migration
Date: Wed, 30 Nov 2022 15:22:46 +0100	[thread overview]
Message-ID: <20221130142249.3558647-2-nrb@linux.ibm.com> (raw)
In-Reply-To: <20221130142249.3558647-1-nrb@linux.ibm.com>

Migration tests can ask migrate_cmd to migrate them to a new QEMU
process. Requesting migration and waiting for completion is hence a
common pattern which is repeated all over the code base. Add a function
which does all of that to avoid repeating the same pattern.

Since migrate_cmd currently can only migrate exactly once, this function
is called migrate_once() and is a no-op when it has been called before.
This can simplify the control flow, especially when tests are skipped.

Suggested-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/migrate.c | 34 ++++++++++++++++++++++++++++++++++
 lib/migrate.h |  9 +++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 lib/migrate.c
 create mode 100644 lib/migrate.h

diff --git a/lib/migrate.c b/lib/migrate.c
new file mode 100644
index 000000000000..50e78fb08865
--- /dev/null
+++ b/lib/migrate.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Migration-related functions
+ *
+ * Copyright IBM Corp. 2022
+ * Author: Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <libcflat.h>
+#include "migrate.h"
+
+/* static for now since we only support migrating exactly once per test. */
+static void migrate(void)
+{
+	puts("Please migrate me, then press return\n");
+	(void)getchar();
+	report_info("Migration complete");
+}
+
+/*
+ * Initiate migration and wait for it to complete.
+ * If this function is called more than once, it is a no-op.
+ * Since migrate_cmd can only migrate exactly once this function can
+ * simplify the control flow, especially when skipping tests.
+ */
+void migrate_once(void)
+{
+	static bool migrated;
+
+	if (migrated)
+		return;
+
+	migrated = true;
+	migrate();
+}
diff --git a/lib/migrate.h b/lib/migrate.h
new file mode 100644
index 000000000000..3c94e6af761c
--- /dev/null
+++ b/lib/migrate.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Migration-related functions
+ *
+ * Copyright IBM Corp. 2022
+ * Author: Nico Boehr <nrb@linux.ibm.com>
+ */
+
+void migrate_once(void);
-- 
2.36.1


  reply	other threads:[~2022-11-30 14:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 14:22 [kvm-unit-tests PATCH v1 0/4] lib: add function to request migration Nico Boehr
2022-11-30 14:22 ` Nico Boehr [this message]
2022-11-30 17:30   ` [kvm-unit-tests PATCH v1 1/4] " Claudio Imbrenda
2022-12-01  8:12     ` Nico Boehr
2022-11-30 14:22 ` [kvm-unit-tests PATCH v1 2/4] powerpc: use migrate_once() in migration tests Nico Boehr
2022-12-09 13:18   ` Thomas Huth
2022-11-30 14:22 ` [kvm-unit-tests PATCH v1 3/4] s390x: " Nico Boehr
2022-11-30 17:34   ` Claudio Imbrenda
2022-11-30 14:22 ` [kvm-unit-tests PATCH v1 4/4] arm: " Nico Boehr
2022-12-02 11:56   ` Andrew Jones
2022-12-09 12:56     ` Nico Boehr

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=20221130142249.3558647-2-nrb@linux.ibm.com \
    --to=nrb@linux.ibm.com \
    --cc=andrew.jones@linux.dev \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /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