qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v7 27/38] libqtest: Swap order of qtest_init() and q


From: Eric Blake
Subject: [Qemu-devel] [PATCH v7 27/38] libqtest: Swap order of qtest_init() and qtest_start()
Date: Mon, 11 Sep 2017 12:20:11 -0500

We already have another qtest_init() in the tree (namely, as part
of the device initialization of the qtest device at the top level
qtest.c), with a different signature; having two different
qtest_init() is confusing, so an upcoming patch will consolidate
all testsuite callers onto a unified spelling.  But the
consolidation is easier if qtest_start() is further down the call
chain, rather than an intermediate wrapper, so swap the call chain
around.  This includes renaming qtest_init_without_qmp_handshake()
into qtest_start_without_qmp_handshake(), as it remains the lowest
point in the call stack.

Note that qtest_init() now asserts that global_qtest was not set
on entry, and clears it on exit, to preserve the behavior of
existing tests that assert the same (and also proving that we
fixed all tests that had parallel connections); but later patches
will eventually simplify things by getting rid of qtest_init()
and global_qtest altogether.

Signed-off-by: Eric Blake <address@hidden>
---
 tests/libqtest.h | 52 ++++++++++++++++++++++++++++------------------------
 tests/libqtest.c |  9 +++++----
 tests/qmp-test.c |  2 +-
 3 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/tests/libqtest.h b/tests/libqtest.h
index d976a542b8..9ef0fbefea 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -24,20 +24,39 @@ typedef struct QTestState QTestState;
 extern QTestState *global_qtest;

 /**
+ * qtest_start_without_qmp_handshake:
+ * @extra_args: other arguments to pass to QEMU.
+ *
+ * Returns: #QTestState instance.  Does not affect #global_qtest.
+ */
+QTestState *qtest_start_without_qmp_handshake(const char *extra_args);
+
+/**
+ * qtest_start:
+ * @args: other arguments to pass to QEMU
+ *
+ * Start QEMU and assign the resulting #QTestState to #global_qtest.
+ * The global variable is used by "shortcut" functions documented below.
+ *
+ * Returns: #QTestState instance.
+ */
+QTestState *qtest_start(const char *args);
+
+/**
  * qtest_init:
  * @extra_args: other arguments to pass to QEMU.
  *
- * Returns: #QTestState instance.
+ * Returns: #QTestState instance.  Does not affect #global_qtest.
  */
-QTestState *qtest_init(const char *extra_args);
+static inline QTestState *qtest_init(const char *extra_args)
+{
+    QTestState *s;

-/**
- * qtest_init_without_qmp_handshake:
- * @extra_args: other arguments to pass to QEMU.
- *
- * Returns: #QTestState instance.
- */
-QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
+    assert(!global_qtest);
+    s = qtest_start(extra_args);
+    global_qtest = NULL;
+    return s;
+}

 /**
  * qtest_quit:
@@ -508,21 +527,6 @@ void qtest_add_data_func_full(const char *str, void *data,
 void qtest_add_abrt_handler(GHookFunc fn, const void *data);

 /**
- * qtest_start:
- * @args: other arguments to pass to QEMU
- *
- * Start QEMU and assign the resulting #QTestState to a global variable.
- * The global variable is used by "shortcut" functions documented below.
- *
- * Returns: #QTestState instance.
- */
-static inline QTestState *qtest_start(const char *args)
-{
-    global_qtest = qtest_init(args);
-    return global_qtest;
-}
-
-/**
  * qmp:
  * @fmt...: QMP message to send to qemu
  *
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 94c157ce02..e8c2e11817 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -152,7 +152,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data)
     g_hook_prepend(&abrt_hooks, hook);
 }

-QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
+QTestState *qtest_start_without_qmp_handshake(const char *extra_args)
 {
     QTestState *s;
     int sock, qmpsock, i;
@@ -233,15 +233,16 @@ QTestState *qtest_init_without_qmp_handshake(const char 
*extra_args)
     return s;
 }

-QTestState *qtest_init(const char *extra_args)
+QTestState *qtest_start(const char *extra_args)
 {
-    QTestState *s = qtest_init_without_qmp_handshake(extra_args);
+    QTestState *s = qtest_start_without_qmp_handshake(extra_args);

     /* Read the QMP greeting and then do the handshake */
     qtest_qmp_discard_response(s, "");
     qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");

-    return s;
+    assert(!global_qtest);
+    return global_qtest = s;
 }

 void qtest_quit(QTestState *s)
diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index a31c0f7de1..8985e7f9ec 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -77,7 +77,7 @@ static void test_qmp_protocol(void)
     QList *capabilities;
     QTestState *qts;

-    qts = qtest_init_without_qmp_handshake(common_args);
+    qts = qtest_start_without_qmp_handshake(common_args);

     /* Test greeting */
     resp = qtest_qmp_receive(qts);
-- 
2.13.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]