diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2015-05-26 11:31:03 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2015-05-26 11:31:03 +0100 |
| commit | 0915aed5842bd4dbe396b92d4f3b846ae29ad663 (patch) | |
| tree | 1468824a966176762562275a550ffb12ba0427e5 /tests/libqos/libqos.c | |
| parent | 0d2ed6039cf86fe3a78671e32b5e3eb17d725762 (diff) | |
| parent | cd6cb73beb63e5fa62ca8ed540b9d54063b15c44 (diff) | |
| download | focaccia-qemu-0915aed5842bd4dbe396b92d4f3b846ae29ad663.tar.gz focaccia-qemu-0915aed5842bd4dbe396b92d4f3b846ae29ad663.zip | |
Merge remote-tracking branch 'remotes/jnsnow/tags/ide-pull-request' into staging
# gpg: Signature made Fri May 22 20:58:44 2015 BST using RSA key ID AAFC390E # gpg: Good signature from "John Snow (John Huston) <jsnow@redhat.com>" # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: FAEB 9711 A12C F475 812F 18F2 88A9 064D 1835 61EB # Subkey fingerprint: F9B7 ABDB BCAC DF95 BE76 CBD0 7DEF 8106 AAFC 390E * remotes/jnsnow/tags/ide-pull-request: ahci: do not remap clb/fis unconditionally macio: move unaligned DMA write code into separate pmac_dma_write() function macio: move unaligned DMA read code into separate pmac_dma_read() function qtest: pre-buffer hex nibs libqos/ahci: Swap memread/write with bufread/write qtest: add memset to qtest protocol qtest: Add base64 encoded read/write qtest: allow arbitrarily long sends qtest/ahci: add migrate halted dma test qtest/ahci: add halted dma test qtest/ahci: add flush migrate test qtest/ahci: add migrate dma test qtest/ahci: Add migration test ich9/ahci: Enable Migration libqos: Add migration helpers libqos/ahci: Fix sector set method libqos/ahci: Add halted command helpers glib: remove stale compat functions configure: require glib 2.22 Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/libqos/libqos.c')
| -rw-r--r-- | tests/libqos/libqos.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 7e7207856e..fce625b18a 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <glib.h> #include <unistd.h> #include <fcntl.h> @@ -62,6 +63,90 @@ void qtest_shutdown(QOSState *qs) g_free(qs); } +void set_context(QOSState *s) +{ + global_qtest = s->qts; +} + +static QDict *qmp_execute(const char *command) +{ + char *fmt; + QDict *rsp; + + fmt = g_strdup_printf("{ 'execute': '%s' }", command); + rsp = qmp(fmt); + g_free(fmt); + + return rsp; +} + +void migrate(QOSState *from, QOSState *to, const char *uri) +{ + const char *st; + char *s; + QDict *rsp, *sub; + bool running; + + set_context(from); + + /* Is the machine currently running? */ + rsp = qmp_execute("query-status"); + g_assert(qdict_haskey(rsp, "return")); + sub = qdict_get_qdict(rsp, "return"); + g_assert(qdict_haskey(sub, "running")); + running = qdict_get_bool(sub, "running"); + QDECREF(rsp); + + /* Issue the migrate command. */ + s = g_strdup_printf("{ 'execute': 'migrate'," + "'arguments': { 'uri': '%s' } }", + uri); + rsp = qmp(s); + g_free(s); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); + + /* Wait for STOP event, but only if we were running: */ + if (running) { + qmp_eventwait("STOP"); + } + + /* If we were running, we can wait for an event. */ + if (running) { + migrate_allocator(from->alloc, to->alloc); + set_context(to); + qmp_eventwait("RESUME"); + return; + } + + /* Otherwise, we need to wait: poll until migration is completed. */ + while (1) { + rsp = qmp_execute("query-migrate"); + g_assert(qdict_haskey(rsp, "return")); + sub = qdict_get_qdict(rsp, "return"); + g_assert(qdict_haskey(sub, "status")); + st = qdict_get_str(sub, "status"); + + /* "setup", "active", "completed", "failed", "cancelled" */ + if (strcmp(st, "completed") == 0) { + QDECREF(rsp); + break; + } + + if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0)) { + QDECREF(rsp); + g_usleep(5000); + continue; + } + + fprintf(stderr, "Migration did not complete, status: %s\n", st); + g_assert_not_reached(); + } + + migrate_allocator(from->alloc, to->alloc); + set_context(to); +} + void mkimg(const char *file, const char *fmt, unsigned size_mb) { gchar *cli; |