[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/11] readconfig-test: add test for accelerator configuration
From: |
Paolo Bonzini |
Subject: |
[PULL 07/11] readconfig-test: add test for accelerator configuration |
Date: |
Wed, 8 Feb 2023 18:19:18 +0100 |
Test that it does not cause a SIGSEGV, and cover a valid configuration
as well.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tests/qtest/libqtest.c | 28 +++++++++++++++++-----
tests/qtest/libqtest.h | 12 ++++++++++
tests/qtest/readconfig-test.c | 45 ++++++++++++++++++++++++++++-------
3 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index ce5f235e25f1..4fba2bb27f06 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -420,6 +420,26 @@ static QTestState *G_GNUC_PRINTF(1, 2)
qtest_spawn_qemu(const char *fmt, ...)
return s;
}
+QTestState *G_GNUC_PRINTF(1, 0) qtest_init_bare(const char *args)
+{
+ QTestState *s = qtest_spawn_qemu("%s", args);
+
+ /*
+ * Stopping QEMU for debugging is not supported on Windows.
+ *
+ * Using DebugActiveProcess() API can suspend the QEMU process,
+ * but gdb cannot attach to the process. Using the undocumented
+ * NtSuspendProcess() can suspend the QEMU process and gdb can
+ * attach to the process, but gdb cannot resume it.
+ */
+#ifndef _WIN32
+ if (getenv("QTEST_STOP")) {
+ kill(s->qemu_pid, SIGSTOP);
+ }
+#endif
+ return s;
+}
+
QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
{
QTestState *s;
@@ -477,12 +497,8 @@ QTestState *qtest_init_without_qmp_handshake(const char
*extra_args)
}
/*
- * Stopping QEMU for debugging is not supported on Windows.
- *
- * Using DebugActiveProcess() API can suspend the QEMU process,
- * but gdb cannot attach to the process. Using the undocumented
- * NtSuspendProcess() can suspend the QEMU process and gdb can
- * attach to the process, but gdb cannot resume it.
+ * Stopping QEMU for debugging is not supported on Windows;
+ * see qtest_init_bare for more information.
*/
#ifndef _WIN32
if (getenv("QTEST_STOP")) {
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index fcf1c3c3b36f..7ca7df26a2c0 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -23,6 +23,18 @@
typedef struct QTestState QTestState;
+/**
+ * qtest_init_bare:
+ * @extra_args: other arguments to pass to QEMU. CAUTION: these
+ * arguments are subject to word splitting and shell evaluation.
+ *
+ * Return a QTestState instance without automatically creating any
+ * sockets for QMP and qtest communication.
+ *
+ * Returns: #QTestState instance.
+ */
+QTestState *qtest_init_bare(const char *args);
+
/**
* qtest_initf:
* @fmt: Format for creating other arguments to pass to QEMU, formatted
diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c
index 9ef870643dcd..4c11883e36eb 100644
--- a/tests/qtest/readconfig-test.c
+++ b/tests/qtest/readconfig-test.c
@@ -19,13 +19,11 @@
#include "qapi/qmp/qstring.h"
#include "qemu/units.h"
-static QTestState *qtest_init_with_config(const char *cfgdata)
+static char *qtest_write_config(const char *cfgdata)
{
GError *error = NULL;
- g_autofree char *args = NULL;
int cfgfd = -1;
- g_autofree char *cfgpath = NULL;
- QTestState *qts;
+ char *cfgpath;
ssize_t ret;
cfgfd = g_file_open_tmp("readconfig-test-XXXXXX", &cfgpath, &error);
@@ -38,13 +36,14 @@ static QTestState *qtest_init_with_config(const char
*cfgdata)
unlink(cfgpath);
}
g_assert_cmpint(ret, ==, strlen(cfgdata));
+ return cfgpath;
+}
- args = g_strdup_printf("-nodefaults -machine none -readconfig %s",
cfgpath);
-
- qts = qtest_init(args);
-
+static QTestState *qtest_init_with_config(const char *cfgdata)
+{
+ g_autofree char *cfgpath = qtest_write_config(cfgdata);
+ QTestState *qts = qtest_initf("-nodefaults -machine none -readconfig %s",
cfgpath);
unlink(cfgpath);
-
return qts;
}
@@ -176,6 +175,32 @@ static void test_object_rng(void)
qtest_quit(qts);
}
+static void test_valid_accel(void)
+{
+ const char *cfgdata =
+ "[accel]\n"
+ "accel = \"qtest\"\n";
+
+ QTestState *qts = qtest_init_with_config(cfgdata);
+ qtest_quit(qts);
+}
+
+static void test_invalid_accel(void)
+{
+ const char *cfgdata =
+ "[accel]\n"
+ "foo = \"bar\"\n";
+
+ g_autofree char *cfgpath = qtest_write_config(cfgdata);
+ g_autofree char *args = g_strdup_printf("-nodefaults -machine none
-readconfig %s", cfgpath);
+ QTestState *qts = qtest_init_bare(args);
+
+ qtest_set_expected_status(qts, 1);
+ qtest_wait_qemu(qts);
+ g_free(qts);
+ unlink(cfgpath);
+}
+
int main(int argc, char *argv[])
{
const char *arch;
@@ -192,6 +217,8 @@ int main(int argc, char *argv[])
#endif
qtest_add_func("readconfig/object-rng", test_object_rng);
+ qtest_add_func("readconfig/invalid-accel", test_invalid_accel);
+ qtest_add_func("readconfig/valid-accel", test_valid_accel);
return g_test_run();
}
--
2.39.1
- [PULL 00/11] Misc patches for 2022-02-08, Paolo Bonzini, 2023/02/08
- [PULL 01/11] build: make meson-buildoptions.sh stable, Paolo Bonzini, 2023/02/08
- [PULL 03/11] block/iscsi: fix double-free on BUSY or similar statuses, Paolo Bonzini, 2023/02/08
- [PULL 06/11] libqtest: ensure waitpid() is only called once, Paolo Bonzini, 2023/02/08
- [PULL 11/11] target/i386: fix ADOX followed by ADCX, Paolo Bonzini, 2023/02/08
- [PULL 05/11] libqtest: split qtest_spawn_qemu function, Paolo Bonzini, 2023/02/08
- [PULL 08/11] tests/tcg/i386: Introduce and use reg_t consistently, Paolo Bonzini, 2023/02/08
- [PULL 10/11] target/i386: Fix C flag for BLSI, BLSMSK, BLSR, Paolo Bonzini, 2023/02/08
- [PULL 04/11] vl: catch [accel] entry without accelerator, Paolo Bonzini, 2023/02/08
- [PULL 07/11] readconfig-test: add test for accelerator configuration,
Paolo Bonzini <=
- [PULL 09/11] target/i386: Fix BEXTR instruction, Paolo Bonzini, 2023/02/08
- [PULL 02/11] remove unnecessary extern "C" blocks, Paolo Bonzini, 2023/02/08
- Re: [PULL 00/11] Misc patches for 2022-02-08, Thomas Huth, 2023/02/09