pc-bios/s390-ccw: make checkpatch happy
[qemu.git] / tests / qdev-monitor-test.c
blobe20ffd67a70e2d8351cb71ae27d119c4d8f47b4a
1 /*
2 * qdev-monitor.c test cases
4 * Copyright (C) 2013 Red Hat Inc.
6 * Authors:
7 * Stefan Hajnoczi <stefanha@redhat.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
13 #include <string.h>
14 #include <glib.h>
15 #include "libqtest.h"
16 #include "qapi/qmp/qjson.h"
18 static void test_device_add(void)
20 QDict *response;
21 QDict *error;
23 qtest_start("-drive if=none,id=drive0");
25 /* Make device_add fail. If this leaks the virtio-blk-pci device then a
26 * reference to drive0 will also be held (via qdev properties).
28 response = qmp("{\"execute\": \"device_add\","
29 " \"arguments\": {"
30 " \"driver\": \"virtio-blk-pci\","
31 " \"drive\": \"drive0\""
32 "}}");
33 g_assert(response);
34 error = qdict_get_qdict(response, "error");
35 g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, "GenericError");
36 QDECREF(response);
38 /* Delete the drive */
39 response = qmp("{\"execute\": \"human-monitor-command\","
40 " \"arguments\": {"
41 " \"command-line\": \"drive_del drive0\""
42 "}}");
43 g_assert(response);
44 g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
45 QDECREF(response);
47 /* Try to re-add the drive. This fails with duplicate IDs if a leaked
48 * virtio-blk-pci exists that holds a reference to the old drive0.
50 response = qmp("{\"execute\": \"human-monitor-command\","
51 " \"arguments\": {"
52 " \"command-line\": \"drive_add pci-addr=auto if=none,id=drive0\""
53 "}}");
54 g_assert(response);
55 g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
56 QDECREF(response);
58 qtest_end();
61 int main(int argc, char **argv)
63 const char *arch = qtest_get_arch();
65 /* Check architecture */
66 if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
67 g_test_message("Skipping test for non-x86\n");
68 return 0;
71 /* Run the tests */
72 g_test_init(&argc, &argv, NULL);
74 qtest_add_func("/qmp/device_add", test_device_add);
76 return g_test_run();