tests/libqtest: Make qmp_assert_success() independent from global_qtest

The normal libqtest library functions should never depend on global_qtest.
Pass in the test state via parameter instead. And while we're at it,
also rename this function to qtest_qmp_assert_success() to make it clear
that it is part of libqtest.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190813093047.27948-7-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Thomas Huth 2019-07-23 21:22:39 +02:00
parent e5758de4e8
commit 6fc9f3d347
3 changed files with 12 additions and 8 deletions

View File

@ -1111,13 +1111,13 @@ QDict *qmp(const char *fmt, ...)
return response; return response;
} }
void qmp_assert_success(const char *fmt, ...) void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
{ {
va_list ap; va_list ap;
QDict *response; QDict *response;
va_start(ap, fmt); va_start(ap, fmt);
response = qtest_vqmp(global_qtest, fmt, ap); response = qtest_vqmp(qts, fmt, ap);
va_end(ap); va_end(ap);
g_assert(response); g_assert(response);

View File

@ -666,7 +666,8 @@ static inline void qtest_end(void)
QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
/** /**
* qmp_assert_success: * qtest_qmp_assert_success:
* @qts: QTestState instance to operate on
* @fmt...: QMP message to send to qemu, formatted like * @fmt...: QMP message to send to qemu, formatted like
* qobject_from_jsonf_nofail(). See parse_escape() for what's * qobject_from_jsonf_nofail(). See parse_escape() for what's
* supported after '%'. * supported after '%'.
@ -674,7 +675,8 @@ QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
* Sends a QMP message to QEMU and asserts that a 'return' key is present in * Sends a QMP message to QEMU and asserts that a 'return' key is present in
* the response. * the response.
*/ */
void qmp_assert_success(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
/* /*
* qmp_eventwait: * qmp_eventwait:

View File

@ -225,10 +225,12 @@ static void test_iothread_attach_node(void *obj, void *data,
mkqcow2(tmp_path, 64); mkqcow2(tmp_path, 64);
/* Attach the overlay to the null0 node */ /* Attach the overlay to the null0 node */
qmp_assert_success("{'execute': 'blockdev-add', 'arguments': {" qtest_qmp_assert_success(scsi_pci->pci_vdev.pdev->bus->qts,
"{'execute': 'blockdev-add', 'arguments': {"
" 'driver': 'qcow2', 'node-name': 'overlay'," " 'driver': 'qcow2', 'node-name': 'overlay',"
" 'backing': 'null0', 'file': {" " 'backing': 'null0', 'file': {"
" 'driver': 'file', 'filename': %s}}}", tmp_path); " 'driver': 'file', 'filename': %s}}}",
tmp_path);
/* Send a request to see if the AioContext is still right */ /* Send a request to see if the AioContext is still right */
ret = virtio_scsi_do_command(vs, write_cdb, NULL, 0, buf, 512, NULL); ret = virtio_scsi_do_command(vs, write_cdb, NULL, 0, buf, 512, NULL);