]> git.proxmox.com Git - mirror_qemu.git/commitdiff
libqtest: add qmp_eventwait
authorJohn Snow <jsnow@redhat.com>
Tue, 28 Apr 2015 19:27:51 +0000 (15:27 -0400)
committerJohn Snow <jsnow@redhat.com>
Tue, 28 Apr 2015 19:27:51 +0000 (15:27 -0400)
Allow the user to poll until a desired interrupt occurs.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1426018503-821-4-git-send-email-jsnow@redhat.com

tests/ide-test.c
tests/libqtest.c
tests/libqtest.h

index b28a3023c2e6c80a21477a44ac706e7f6b5af1a1..1dae84fc94c78d092e917f1abbd620ad99d3d571 100644 (file)
@@ -520,7 +520,6 @@ static void test_retry_flush(const char *machine)
 {
     uint8_t data;
     const char *s;
-    QDict *response;
 
     prepare_blkdebug_script(debug_path, "flush_to_disk");
 
@@ -539,15 +538,7 @@ static void test_retry_flush(const char *machine)
     assert_bit_set(data, BSY | DRDY);
     assert_bit_clear(data, DF | ERR | DRQ);
 
-    for (;; response = NULL) {
-        response = qmp_receive();
-        if ((qdict_haskey(response, "event")) &&
-            (strcmp(qdict_get_str(response, "event"), "STOP") == 0)) {
-            QDECREF(response);
-            break;
-        }
-        QDECREF(response);
-    }
+    qmp_eventwait("STOP");
 
     /* Complete the command */
     s = "{'execute':'cont' }";
index 12d65bd1e6ca1fc85cb6d23468b42a3054895496..e2d01b47a2a18c6c2d8ff0ba3d6c66183f375693 100644 (file)
@@ -450,6 +450,22 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)
     QDECREF(response);
 }
 
+void qtest_qmp_eventwait(QTestState *s, const char *event)
+{
+    QDict *response;
+
+    for (;;) {
+        response = qtest_qmp_receive(s);
+        if ((qdict_haskey(response, "event")) &&
+            (strcmp(qdict_get_str(response, "event"), event) == 0)) {
+            QDECREF(response);
+            break;
+        }
+        QDECREF(response);
+    }
+}
+
+
 const char *qtest_get_arch(void)
 {
     const char *qemu = getenv("QTEST_QEMU_BINARY");
index 03469b87817e76e1df87cce3ea5f4ddb5ab4607e..30009ca5c95abcf7e024c720915df55f81bfaeb9 100644 (file)
@@ -91,6 +91,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
  */
 QDict *qtest_qmp_receive(QTestState *s);
 
+/**
+ * qtest_qmp_eventwait:
+ * @s: #QTestState instance to operate on.
+ * @s: #event event to wait for.
+ *
+ * Continuosly polls for QMP responses until it receives the desired event.
+ */
+void qtest_qmp_eventwait(QTestState *s, const char *event);
+
 /**
  * qtest_get_irq:
  * @s: #QTestState instance to operate on.
@@ -428,6 +437,17 @@ static inline QDict *qmp_receive(void)
     return qtest_qmp_receive(global_qtest);
 }
 
+/**
+ * qmp_eventwait:
+ * @s: #event event to wait for.
+ *
+ * Continuosly polls for QMP responses until it receives the desired event.
+ */
+static inline void qmp_eventwait(const char *event)
+{
+    return qtest_qmp_eventwait(global_qtest, event);
+}
+
 /**
  * get_irq:
  * @num: Interrupt to observe.