From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P . Berrangé" <berrange@redhat.com>
Subject: [PULL 08/22] tests/qtest/migration: Move bootfile code to its own file
Date: Thu, 12 Dec 2024 12:09:35 -0300 [thread overview]
Message-ID: <20241212150949.16806-9-farosas@suse.de> (raw)
In-Reply-To: <20241212150949.16806-1-farosas@suse.de>
Move the code that creates the guest binary out of migration-test and
into the qtest/migration/ directory, along with the rest of the
a-b-kernel code.
That code is part of the basic infrastructure of migration tests, it
shouldn't be among the tests themselves.
Also take the chance and rename migration-test.h, which is too generic
a name for this header which contains only values related to guest
memory offsets.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
tests/qtest/meson.build | 8 ++-
tests/qtest/migration-helpers.c | 1 +
tests/qtest/migration-test.c | 58 +--------------
tests/qtest/migration/bootfile.c | 70 +++++++++++++++++++
.../{migration-test.h => bootfile.h} | 9 ++-
5 files changed, 86 insertions(+), 60 deletions(-)
create mode 100644 tests/qtest/migration/bootfile.c
rename tests/qtest/migration/{migration-test.h => bootfile.h} (85%)
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 89db3ecf2f..c3712a9e36 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -332,7 +332,11 @@ endif
tpmemu_files = ['tpm-emu.c', 'tpm-util.c', 'tpm-tests.c']
-migration_files = [files('migration-helpers.c')]
+migration_files = [files(
+ 'migration-helpers.c',
+ 'migration/bootfile.c',
+)]
+
if gnutls.found()
migration_files += [files('../unit/crypto-tls-psk-helpers.c'), gnutls]
@@ -358,7 +362,7 @@ qtests = {
'tpm-tis-i2c-test': [io, tpmemu_files, 'qtest_aspeed.c'],
'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
- 'virtio-net-failover': files('migration-helpers.c'),
+ 'virtio-net-failover': migration_files,
'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'),
'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'),
'aspeed_smc-test': files('aspeed-smc-utils.c', 'aspeed_smc-test.c'),
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 3f8ba7fa8e..2786f9c860 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -21,6 +21,7 @@
#include "qemu/memalign.h"
#include "migration-helpers.h"
+#include "migration/bootfile.h"
/*
* Number of seconds we wait when looking for migration
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 82b9170e3c..e104e44802 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -24,7 +24,7 @@
#include "ppc-util.h"
#include "migration-helpers.h"
-#include "migration/migration-test.h"
+#include "migration/bootfile.h"
#ifdef CONFIG_GNUTLS
# include "tests/unit/crypto-tls-psk-helpers.h"
# ifdef CONFIG_TASN1
@@ -135,58 +135,6 @@ static bool ufd_version_check(void)
static char *tmpfs;
static char *bootpath;
-/* The boot file modifies memory area in [start_address, end_address)
- * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
- */
-#include "migration/i386/a-b-bootblock.h"
-#include "migration/aarch64/a-b-kernel.h"
-#include "migration/ppc64/a-b-kernel.h"
-#include "migration/s390x/a-b-bios.h"
-
-static void bootfile_delete(void)
-{
- if (!bootpath) {
- return;
- }
- unlink(bootpath);
- g_free(bootpath);
- bootpath = NULL;
-}
-
-static void bootfile_create(char *dir, bool suspend_me)
-{
- const char *arch = qtest_get_arch();
- unsigned char *content;
- size_t len;
-
- bootfile_delete();
- bootpath = g_strdup_printf("%s/bootsect", dir);
- if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
- /* the assembled x86 boot sector should be exactly one sector large */
- g_assert(sizeof(x86_bootsect) == 512);
- x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me;
- content = x86_bootsect;
- len = sizeof(x86_bootsect);
- } else if (g_str_equal(arch, "s390x")) {
- content = s390x_elf;
- len = sizeof(s390x_elf);
- } else if (strcmp(arch, "ppc64") == 0) {
- content = ppc64_kernel;
- len = sizeof(ppc64_kernel);
- } else if (strcmp(arch, "aarch64") == 0) {
- content = aarch64_kernel;
- len = sizeof(aarch64_kernel);
- g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
- } else {
- g_assert_not_reached();
- }
-
- FILE *bootfile = fopen(bootpath, "wb");
-
- g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
- fclose(bootfile);
-}
-
/*
* Wait for some output in the serial output file,
* we get an 'A' followed by an endless string of 'B's
@@ -737,7 +685,7 @@ static int migrate_start(QTestState **from, QTestState **to,
dst_state = (QTestMigrationState) { };
src_state = (QTestMigrationState) { };
- bootfile_create(tmpfs, args->suspend_me);
+ bootpath = bootfile_create(arch, tmpfs, args->suspend_me);
src_state.suspend_me = args->suspend_me;
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -3488,7 +3436,7 @@ static QTestState *dirtylimit_start_vm(void)
QTestState *vm = NULL;
g_autofree gchar *cmd = NULL;
- bootfile_create(tmpfs, false);
+ bootpath = bootfile_create(qtest_get_arch(), tmpfs, false);
cmd = g_strdup_printf("-accel kvm,dirty-ring-size=4096 "
"-name dirtylimit-test,debug-threads=on "
"-m 150M -smp 1 "
diff --git a/tests/qtest/migration/bootfile.c b/tests/qtest/migration/bootfile.c
new file mode 100644
index 0000000000..8f75f64093
--- /dev/null
+++ b/tests/qtest/migration/bootfile.c
@@ -0,0 +1,70 @@
+/*
+ * Guest code setup for migration tests
+ *
+ * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+ * based on the vhost-user-test.c that is:
+ * Copyright (c) 2014 Virtual Open Systems Sarl.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+/*
+ * The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
+ */
+#include "bootfile.h"
+#include "i386/a-b-bootblock.h"
+#include "aarch64/a-b-kernel.h"
+#include "ppc64/a-b-kernel.h"
+#include "s390x/a-b-bios.h"
+
+static char *bootpath;
+
+void bootfile_delete(void)
+{
+ if (!bootpath) {
+ return;
+ }
+ unlink(bootpath);
+ g_free(bootpath);
+ bootpath = NULL;
+}
+
+char *bootfile_create(const char *arch, char *dir, bool suspend_me)
+{
+ unsigned char *content;
+ size_t len;
+
+ bootfile_delete();
+ bootpath = g_strdup_printf("%s/bootsect", dir);
+ if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+ /* the assembled x86 boot sector should be exactly one sector large */
+ g_assert(sizeof(x86_bootsect) == 512);
+ x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me;
+ content = x86_bootsect;
+ len = sizeof(x86_bootsect);
+ } else if (g_str_equal(arch, "s390x")) {
+ content = s390x_elf;
+ len = sizeof(s390x_elf);
+ } else if (strcmp(arch, "ppc64") == 0) {
+ content = ppc64_kernel;
+ len = sizeof(ppc64_kernel);
+ } else if (strcmp(arch, "aarch64") == 0) {
+ content = aarch64_kernel;
+ len = sizeof(aarch64_kernel);
+ g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
+ } else {
+ g_assert_not_reached();
+ }
+
+ FILE *bootfile = fopen(bootpath, "wb");
+
+ g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
+ fclose(bootfile);
+
+ return bootpath;
+}
diff --git a/tests/qtest/migration/migration-test.h b/tests/qtest/migration/bootfile.h
similarity index 85%
rename from tests/qtest/migration/migration-test.h
rename to tests/qtest/migration/bootfile.h
index 194df7df6f..4f5099d765 100644
--- a/tests/qtest/migration/migration-test.h
+++ b/tests/qtest/migration/bootfile.h
@@ -5,8 +5,8 @@
* See the COPYING file in the top-level directory.
*/
-#ifndef MIGRATION_TEST_H
-#define MIGRATION_TEST_H
+#ifndef BOOTFILE_H
+#define BOOTFILE_H
/* Common */
#define TEST_MEM_PAGE_SIZE 4096
@@ -33,4 +33,7 @@
*/
#define ARM_TEST_MAX_KERNEL_SIZE (512 * 1024)
-#endif /* MIGRATION_TEST_H */
+void bootfile_delete(void);
+char *bootfile_create(const char *arch, char *dir, bool suspend_me);
+
+#endif /* BOOTFILE_H */
--
2.35.3
next prev parent reply other threads:[~2024-12-12 15:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 15:09 [PULL 00/22] QTest patches for 2024-12-12 Fabiano Rosas
2024-12-12 15:09 ` [PULL 01/22] tests/qtest: add TIMEOUT_MULTIPLIER Fabiano Rosas
2024-12-12 15:09 ` [PULL 02/22] tests/qtest: Add qtest_system_reset() utility function Fabiano Rosas
2024-12-12 15:09 ` [PULL 03/22] tests/qtest: Use qtest_system_reset() instead of open-coded versions Fabiano Rosas
2024-12-12 15:09 ` [PULL 04/22] tests/qtest: Use qtest_system_reset_nowait() where appropriate Fabiano Rosas
2024-12-12 15:09 ` [PULL 05/22] tests/qtest/migration: Standardize hook names Fabiano Rosas
2024-12-12 15:09 ` [PULL 06/22] tests/qtest/migration: Stop calling everything "test" Fabiano Rosas
2024-12-12 15:09 ` [PULL 07/22] tests/migration: Disambiguate guestperf vs. a-b Fabiano Rosas
2024-12-12 15:09 ` Fabiano Rosas [this message]
2024-12-12 15:09 ` [PULL 09/22] tests/qtest/migration: Move qmp helpers to a separate file Fabiano Rosas
2024-12-12 15:09 ` [PULL 10/22] tests/qtest/migration: Rename migration-helpers.c Fabiano Rosas
2024-12-12 15:09 ` [PULL 11/22] tests/qtest/migration: Move ufd_version_check to utils Fabiano Rosas
2024-12-12 15:09 ` [PULL 12/22] tests/qtest/migration: Move kvm_dirty_ring_supported " Fabiano Rosas
2024-12-12 15:09 ` [PULL 13/22] tests/qtest/migration: Isolate test initialization Fabiano Rosas
2024-12-12 15:09 ` [PULL 14/22] tests/qtest/migration: Move common test code Fabiano Rosas
2024-12-12 15:09 ` [PULL 15/22] tests/qtest/migration: Split TLS tests from migration-test.c Fabiano Rosas
2024-12-12 15:09 ` [PULL 16/22] tests/qtest/migration: Split compression " Fabiano Rosas
2024-12-12 15:09 ` [PULL 17/22] tests/qtest/migration: Split postcopy tests Fabiano Rosas
2024-12-12 15:09 ` [PULL 18/22] tests/qtest/migration: Split file tests Fabiano Rosas
2024-12-12 15:09 ` [PULL 19/22] tests/qtest/migration: Split precopy tests Fabiano Rosas
2024-12-12 15:09 ` [PULL 20/22] tests/qtest/migration: Split CPR tests Fabiano Rosas
2024-12-12 15:09 ` [PULL 21/22] tests/qtest/migration-test: Fix and enable test_ignore_shared Fabiano Rosas
2024-12-12 15:09 ` [PULL 22/22] tests/qtest/migration: Split validation tests + misc Fabiano Rosas
2024-12-13 1:21 ` [PULL 00/22] QTest patches for 2024-12-12 Stefan Hajnoczi
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=20241212150949.16806-9-farosas@suse.de \
--to=farosas@suse.de \
--cc=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.