summaryrefslogtreecommitdiff
path: root/tests/vmgenid-test.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-10-18 16:20:27 +0200
committerCornelia Huck <cohuck@redhat.com>2017-10-20 13:32:10 +0200
commit78b27bade1faf91435eae4bdcb7444dcf35f44bf (patch)
treee833f418341a11b9739ec254339cf1ed5b2db802 /tests/vmgenid-test.c
parent6bb6f19473e2f28334bed14740d64afb6cb6a4e5 (diff)
downloadqemu-78b27bade1faf91435eae4bdcb7444dcf35f44bf.tar.gz
libqtest: Add qtest_[v]startf()
We have several callers that were formatting the argument strings themselves; consolidate this effort by adding new convenience functions directly in libqtest, and update some call-sites that can benefit from it. Note that the new functions qtest_startf() and qtest_vstartf() behave more like qtest_init() (the caller must assign global_qtest after the fact, rather than getting it implicitly set). This helps us prepare for future patches that get rid of the global variable, by explicitly highlighting which tests still depend on it now. Signed-off-by: Eric Blake <eblake@redhat.com> [thuth: Dropped the hunks that do not apply cleanly to qemu master yet and added the missing g_free(args) in qtest_vstartf()] Signed-off-by: Thomas Huth <thuth@redhat.com> Message-Id: <1508336428-20511-2-git-send-email-thuth@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Diffstat (limited to 'tests/vmgenid-test.c')
-rw-r--r--tests/vmgenid-test.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
index 918c82c82a..b6e7b3b086 100644
--- a/tests/vmgenid-test.c
+++ b/tests/vmgenid-test.c
@@ -130,41 +130,32 @@ static void read_guid_from_monitor(QemuUUID *guid)
static char disk[] = "tests/vmgenid-test-disk-XXXXXX";
-static char *guid_cmd_strdup(const char *guid)
-{
- return g_strdup_printf("-machine accel=kvm:tcg "
- "-device vmgenid,id=testvgid,guid=%s "
- "-drive id=hd0,if=none,file=%s,format=raw "
- "-device ide-hd,drive=hd0 ",
- guid, disk);
-}
-
+#define GUID_CMD(guid) \
+ "-machine accel=kvm:tcg " \
+ "-device vmgenid,id=testvgid,guid=%s " \
+ "-drive id=hd0,if=none,file=%s,format=raw " \
+ "-device ide-hd,drive=hd0 ", guid, disk
static void vmgenid_set_guid_test(void)
{
QemuUUID expected, measured;
- gchar *cmd;
g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
- cmd = guid_cmd_strdup(VGID_GUID);
- qtest_start(cmd);
+ global_qtest = qtest_startf(GUID_CMD(VGID_GUID));
/* Read the GUID from accessing guest memory */
read_guid_from_memory(&measured);
g_assert(memcmp(measured.data, expected.data, sizeof(measured.data)) == 0);
qtest_quit(global_qtest);
- g_free(cmd);
}
static void vmgenid_set_guid_auto_test(void)
{
- char *cmd;
QemuUUID measured;
- cmd = guid_cmd_strdup("auto");
- qtest_start(cmd);
+ global_qtest = qtest_startf(GUID_CMD("auto"));
read_guid_from_memory(&measured);
@@ -172,25 +163,21 @@ static void vmgenid_set_guid_auto_test(void)
g_assert(!qemu_uuid_is_null(&measured));
qtest_quit(global_qtest);
- g_free(cmd);
}
static void vmgenid_query_monitor_test(void)
{
QemuUUID expected, measured;
- gchar *cmd;
g_assert(qemu_uuid_parse(VGID_GUID, &expected) == 0);
- cmd = guid_cmd_strdup(VGID_GUID);
- qtest_start(cmd);
+ global_qtest = qtest_startf(GUID_CMD(VGID_GUID));
/* Read the GUID via the monitor */
read_guid_from_monitor(&measured);
g_assert(memcmp(measured.data, expected.data, sizeof(measured.data)) == 0);
qtest_quit(global_qtest);
- g_free(cmd);
}
int main(int argc, char **argv)