2 * blockdev.c test cases
4 * Copyright (C) 2013-2014 Red Hat Inc.
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.
17 static void drive_add(void)
21 response
= qmp("{'execute': 'human-monitor-command',"
23 " 'command-line': 'drive_add 0 if=none,id=drive0'"
26 g_assert_cmpstr(qdict_get_try_str(response
, "return"), ==, "OK\r\n");
30 static void drive_del(void)
34 response
= qmp("{'execute': 'human-monitor-command',"
36 " 'command-line': 'drive_del drive0'"
39 g_assert_cmpstr(qdict_get_try_str(response
, "return"), ==, "");
43 static void test_drive_without_dev(void)
45 /* Start with an empty drive */
46 qtest_start("-drive if=none,id=drive0");
48 /* Delete the drive */
51 /* Ensure re-adding the drive works - there should be no duplicate ID error
52 * because the old drive must be gone.
59 static void test_after_failed_device_add(void)
64 qtest_start("-drive if=none,id=drive0");
66 /* Make device_add fail. If this leaks the virtio-blk-pci device then a
67 * reference to drive0 will also be held (via qdev properties).
69 response
= qmp("{'execute': 'device_add',"
71 " 'driver': 'virtio-blk-pci',"
75 error
= qdict_get_qdict(response
, "error");
76 g_assert_cmpstr(qdict_get_try_str(error
, "class"), ==, "GenericError");
79 /* Delete the drive */
82 /* Try to re-add the drive. This fails with duplicate IDs if a leaked
83 * virtio-blk-pci exists that holds a reference to the old drive0.
90 int main(int argc
, char **argv
)
92 const char *arch
= qtest_get_arch();
94 g_test_init(&argc
, &argv
, NULL
);
96 qtest_add_func("/drive_del/without-dev", test_drive_without_dev
);
98 /* TODO I guess any arch with PCI would do */
99 if (!strcmp(arch
, "i386") || !strcmp(arch
, "x86_64")) {
100 qtest_add_func("/drive_del/after_failed_device_add",
101 test_after_failed_device_add
);