Skip to content

Commit

Permalink
tests/x86: add helper qtest_qmp_device_del_send()
Browse files Browse the repository at this point in the history
Move sending 'device_del' command to separate function.
Function can be used in case of addition action is needed to start
actual removing device after sending command.

Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
Message-Id: <20220929223547.1429580-2-michael.labiuk@virtuozzo.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
[thuth: Fixed typo]
Signed-off-by: Thomas Huth <thuth@redhat.com>
  • Loading branch information
shanechko authored and huth committed Oct 11, 2022
1 parent 770bead commit ea42a6c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
15 changes: 2 additions & 13 deletions tests/qtest/device-plug-test.c
Expand Up @@ -15,17 +15,6 @@
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"

static void device_del(QTestState *qtest, const char *id)
{
QDict *resp;

resp = qtest_qmp(qtest,
"{'execute': 'device_del', 'arguments': { 'id': %s } }", id);

g_assert(qdict_haskey(resp, "return"));
qobject_unref(resp);
}

static void system_reset(QTestState *qtest)
{
QDict *resp;
Expand Down Expand Up @@ -68,7 +57,7 @@ static void process_device_remove(QTestState *qtest, const char *id)
* be processed. However during system reset, the removal will be
* handled, removing the device.
*/
device_del(qtest, id);
qtest_qmp_device_del_send(qtest, id);
system_reset(qtest);
wait_device_deleted_event(qtest, id);
}
Expand Down Expand Up @@ -112,7 +101,7 @@ static void test_ccw_unplug(void)
{
QTestState *qtest = qtest_initf("-device virtio-balloon-ccw,id=dev0");

device_del(qtest, "dev0");
qtest_qmp_device_del_send(qtest, "dev0");
wait_device_deleted_event(qtest, "dev0");

qtest_quit(qtest);
Expand Down
6 changes: 1 addition & 5 deletions tests/qtest/drive_del-test.c
Expand Up @@ -143,11 +143,7 @@ static void device_del(QTestState *qts, bool and_reset)
{
QDict *response;

response = qtest_qmp(qts, "{'execute': 'device_del',"
" 'arguments': { 'id': 'dev0' } }");
g_assert(response);
g_assert(qdict_haskey(response, "return"));
qobject_unref(response);
qtest_qmp_device_del_send(qts, "dev0");

if (and_reset) {
response = qtest_qmp(qts, "{'execute': 'system_reset' }");
Expand Down
8 changes: 1 addition & 7 deletions tests/qtest/libqos/pci-pc.c
Expand Up @@ -179,13 +179,7 @@ void qpci_free_pc(QPCIBus *bus)

void qpci_unplug_acpi_device_test(QTestState *qts, const char *id, uint8_t slot)
{
QDict *response;

response = qtest_qmp(qts, "{'execute': 'device_del',"
" 'arguments': {'id': %s}}", id);
g_assert(response);
g_assert(!qdict_haskey(response, "error"));
qobject_unref(response);
qtest_qmp_device_del_send(qts, id);

qtest_outl(qts, ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot);

Expand Down
16 changes: 10 additions & 6 deletions tests/qtest/libqtest.c
Expand Up @@ -1371,15 +1371,19 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
*
* {"return": {}}
*/
void qtest_qmp_device_del(QTestState *qts, const char *id)
void qtest_qmp_device_del_send(QTestState *qts, const char *id)
{
QDict *rsp;

rsp = qtest_qmp(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}",
id);

QDict *rsp = qtest_qmp(qts, "{'execute': 'device_del', "
"'arguments': {'id': %s}}", id);
g_assert(rsp);
g_assert(qdict_haskey(rsp, "return"));
g_assert(!qdict_haskey(rsp, "error"));
qobject_unref(rsp);
}

void qtest_qmp_device_del(QTestState *qts, const char *id)
{
qtest_qmp_device_del_send(qts, id);
qtest_qmp_eventwait(qts, "DEVICE_DELETED");
}

Expand Down
10 changes: 10 additions & 0 deletions tests/qtest/libqtest.h
Expand Up @@ -761,12 +761,22 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
#endif /* _WIN32 */

/**
* qtest_qmp_device_del_send:
* @qts: QTestState instance to operate on
* @id: Identification string
*
* Generic hot-unplugging test via the device_del QMP command.
*/
void qtest_qmp_device_del_send(QTestState *qts, const char *id);

/**
* qtest_qmp_device_del:
* @qts: QTestState instance to operate on
* @id: Identification string
*
* Generic hot-unplugging test via the device_del QMP command.
* Waiting for command completion event.
*/
void qtest_qmp_device_del(QTestState *qts, const char *id);

Expand Down

0 comments on commit ea42a6c

Please sign in to comment.