tests/qtest: replace qmp_discard_response with qtest_qmp_assert_success

The qmp_discard_response method simply ignores the result of the QMP
command, merely unref'ing the object. This is a bad idea for tests
as it leaves no trace if the QMP command unexpectedly failed. The
qtest_qmp_assert_success method will validate that the QMP command
returned without error, and if errors occur, it will print a message
on the console aiding debugging.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20230421171411.566300-2-berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2023-04-21 18:14:06 +01:00 committed by Thomas Huth
parent eb96660507
commit 855436dbf7
8 changed files with 40 additions and 57 deletions

View file

@ -36,9 +36,6 @@
#include "hw/pci/pci_ids.h" #include "hw/pci/pci_ids.h"
#include "hw/pci/pci_regs.h" #include "hw/pci/pci_regs.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(s, ...) qobject_unref(qtest_qmp(s, __VA_ARGS__))
/* Test images sizes in MB */ /* Test images sizes in MB */
#define TEST_IMAGE_SIZE_MB_LARGE (200 * 1024) #define TEST_IMAGE_SIZE_MB_LARGE (200 * 1024)
#define TEST_IMAGE_SIZE_MB_SMALL 64 #define TEST_IMAGE_SIZE_MB_SMALL 64
@ -1595,7 +1592,7 @@ static void test_atapi_tray(void)
rsp = qtest_qmp_receive(ahci->parent->qts); rsp = qtest_qmp_receive(ahci->parent->qts);
qobject_unref(rsp); qobject_unref(rsp);
qmp_discard_response(ahci->parent->qts, qtest_qmp_assert_success(ahci->parent->qts,
"{'execute': 'blockdev-remove-medium', " "{'execute': 'blockdev-remove-medium', "
"'arguments': {'id': 'cd0'}}"); "'arguments': {'id': 'cd0'}}");
@ -1607,13 +1604,15 @@ static void test_atapi_tray(void)
atapi_wait_tray(ahci, true); atapi_wait_tray(ahci, true);
/* Re-insert media */ /* Re-insert media */
qmp_discard_response(ahci->parent->qts, qtest_qmp_assert_success(
ahci->parent->qts,
"{'execute': 'blockdev-add', " "{'execute': 'blockdev-add', "
"'arguments': {'node-name': 'node0', " "'arguments': {'node-name': 'node0', "
"'driver': 'raw', " "'driver': 'raw', "
"'file': { 'driver': 'file', " "'file': { 'driver': 'file', "
"'filename': %s }}}", iso); "'filename': %s }}}", iso);
qmp_discard_response(ahci->parent->qts, qtest_qmp_assert_success(
ahci->parent->qts,
"{'execute': 'blockdev-insert-medium'," "{'execute': 'blockdev-insert-medium',"
"'arguments': { 'id': 'cd0', " "'arguments': { 'id': 'cd0', "
"'node-name': 'node0' }}"); "'node-name': 'node0' }}");

View file

@ -16,9 +16,6 @@
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
#include "standard-headers/linux/qemu_fw_cfg.h" #include "standard-headers/linux/qemu_fw_cfg.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
typedef struct { typedef struct {
const char *args; const char *args;
uint64_t expected_boot; uint64_t expected_boot;
@ -43,7 +40,7 @@ static void test_a_boot_order(const char *machine,
machine ?: "", test_args); machine ?: "", test_args);
actual = read_boot_order(qts); actual = read_boot_order(qts);
g_assert_cmphex(actual, ==, expected_boot); g_assert_cmphex(actual, ==, expected_boot);
qmp_discard_response(qts, "{ 'execute': 'system_reset' }"); qtest_qmp_assert_success(qts, "{ 'execute': 'system_reset' }");
/* /*
* system_reset only requests reset. We get a RESET event after * system_reset only requests reset. We get a RESET event after
* the actual reset completes. Need to wait for that. * the actual reset completes. Need to wait for that.

View file

@ -28,9 +28,6 @@
#include "libqtest-single.h" #include "libqtest-single.h"
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
#define DRIVE_FLOPPY_BLANK \ #define DRIVE_FLOPPY_BLANK \
"-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k" "-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k"
@ -304,7 +301,8 @@ static void test_media_insert(void)
/* Insert media in drive. DSKCHK should not be reset until a step pulse /* Insert media in drive. DSKCHK should not be reset until a step pulse
* is sent. */ * is sent. */
qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments':{" qtest_qmp_assert_success(global_qtest,
"{'execute':'blockdev-change-medium', 'arguments':{"
" 'id':'floppy0', 'filename': %s, 'format': 'raw' }}", " 'id':'floppy0', 'filename': %s, 'format': 'raw' }}",
test_image); test_image);
@ -335,7 +333,8 @@ static void test_media_change(void)
/* Eject the floppy and check that DSKCHG is set. Reading it out doesn't /* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
* reset the bit. */ * reset the bit. */
qmp_discard_response("{'execute':'eject', 'arguments':{" qtest_qmp_assert_success(global_qtest,
"{'execute':'eject', 'arguments':{"
" 'id':'floppy0' }}"); " 'id':'floppy0' }}");
dir = inb(FLOPPY_BASE + reg_dir); dir = inb(FLOPPY_BASE + reg_dir);

View file

@ -34,9 +34,6 @@
#include "hw/pci/pci_ids.h" #include "hw/pci/pci_ids.h"
#include "hw/pci/pci_regs.h" #include "hw/pci/pci_regs.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(q, ...) qobject_unref(qtest_qmp(q, __VA_ARGS__))
#define TEST_IMAGE_SIZE 64 * 1024 * 1024 #define TEST_IMAGE_SIZE 64 * 1024 * 1024
#define IDE_PCI_DEV 1 #define IDE_PCI_DEV 1
@ -766,7 +763,7 @@ static void test_pci_retry_flush(void)
qtest_qmp_eventwait(qts, "STOP"); qtest_qmp_eventwait(qts, "STOP");
/* Complete the command */ /* Complete the command */
qmp_discard_response(qts, "{'execute':'cont' }"); qtest_qmp_assert_success(qts, "{'execute':'cont' }");
/* Check registers */ /* Check registers */
data = qpci_io_readb(dev, ide_bar, reg_device); data = qpci_io_readb(dev, ide_bar, reg_device);

View file

@ -40,9 +40,6 @@
#include "linux/kvm.h" #include "linux/kvm.h"
#endif #endif
/* TODO actually test the results and get rid of this */
#define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
unsigned start_address; unsigned start_address;
unsigned end_address; unsigned end_address;
static bool uffd_feature_thread_id; static bool uffd_feature_thread_id;
@ -766,7 +763,7 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
usleep(1000 * 10); usleep(1000 * 10);
} while (dest_byte_a == dest_byte_b); } while (dest_byte_a == dest_byte_b);
qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}"); qtest_qmp_assert_success(to, "{ 'execute' : 'stop'}");
/* With it stopped, check nothing changes */ /* With it stopped, check nothing changes */
qtest_memread(to, start_address, &dest_byte_c, 1); qtest_memread(to, start_address, &dest_byte_c, 1);

View file

@ -16,9 +16,6 @@
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
static void test_mirror(void) static void test_mirror(void)
{ {
int send_sock[2], recv_sock[2]; int send_sock[2], recv_sock[2];
@ -52,7 +49,7 @@ static void test_mirror(void)
}; };
/* send a qmp command to guarantee that 'connected' is setting to true. */ /* send a qmp command to guarantee that 'connected' is setting to true. */
qmp_discard_response(qts, "{ 'execute' : 'query-status'}"); qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}");
ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf)); ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf));
g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size)); g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
close(send_sock[0]); close(send_sock[0]);

View file

@ -58,9 +58,6 @@
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
static void test_redirector_tx(void) static void test_redirector_tx(void)
{ {
int backend_sock[2], recv_sock; int backend_sock[2], recv_sock;
@ -98,7 +95,7 @@ static void test_redirector_tx(void)
g_assert_cmpint(recv_sock, !=, -1); g_assert_cmpint(recv_sock, !=, -1);
/* send a qmp command to guarantee that 'connected' is setting to true. */ /* send a qmp command to guarantee that 'connected' is setting to true. */
qmp_discard_response(qts, "{ 'execute' : 'query-status'}"); qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}");
struct iovec iov[] = { struct iovec iov[] = {
{ {
@ -176,7 +173,7 @@ static void test_redirector_rx(void)
send_sock = unix_connect(sock_path1, NULL); send_sock = unix_connect(sock_path1, NULL);
g_assert_cmpint(send_sock, !=, -1); g_assert_cmpint(send_sock, !=, -1);
/* send a qmp command to guarantee that 'connected' is setting to true. */ /* send a qmp command to guarantee that 'connected' is setting to true. */
qmp_discard_response(qts, "{ 'execute' : 'query-status'}"); qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}");
ret = iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)); ret = iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf));
g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size)); g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));

View file

@ -17,9 +17,6 @@
#include "libqos/qgraph.h" #include "libqos/qgraph.h"
#include "libqos/virtio-blk.h" #include "libqos/virtio-blk.h"
/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
#define TEST_IMAGE_SIZE (64 * 1024 * 1024) #define TEST_IMAGE_SIZE (64 * 1024 * 1024)
#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000)
#define PCI_SLOT_HP 0x06 #define PCI_SLOT_HP 0x06
@ -453,7 +450,8 @@ static void config(void *obj, void *data, QGuestAllocator *t_alloc)
qvirtio_set_driver_ok(dev); qvirtio_set_driver_ok(dev);
qmp_discard_response("{ 'execute': 'block_resize', " qtest_qmp_assert_success(global_qtest,
"{ 'execute': 'block_resize', "
" 'arguments': { 'device': 'drive0', " " 'arguments': { 'device': 'drive0', "
" 'size': %d } }", n_size); " 'size': %d } }", n_size);
qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US); qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US);
@ -502,7 +500,8 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
qvirtio_set_driver_ok(dev); qvirtio_set_driver_ok(dev);
qmp_discard_response("{ 'execute': 'block_resize', " qtest_qmp_assert_success(global_qtest,
"{ 'execute': 'block_resize', "
" 'arguments': { 'device': 'drive0', " " 'arguments': { 'device': 'drive0', "
" 'size': %d } }", n_size); " 'size': %d } }", n_size);
@ -758,7 +757,8 @@ static void resize(void *obj, void *data, QGuestAllocator *t_alloc)
vq = test_basic(dev, t_alloc); vq = test_basic(dev, t_alloc);
qmp_discard_response("{ 'execute': 'block_resize', " qtest_qmp_assert_success(global_qtest,
"{ 'execute': 'block_resize', "
" 'arguments': { 'device': 'drive0', " " 'arguments': { 'device': 'drive0', "
" 'size': %d } }", n_size); " 'size': %d } }", n_size);