xref: /openbmc/qemu/tests/qtest/virtio-ccw-test.c (revision 7d87775f)
1 /*
2  * QTest testcase for VirtIO CCW
3  *
4  * Copyright (c) 2014 SUSE LINUX Products GmbH
5  * Copyright (c) 2018 Red Hat, Inc.
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or later.
8  * See the COPYING file in the top-level directory.
9  */
10 
11 /* Until we have a full libqos implementation of virtio-ccw (which requires
12  * also to add support for I/O channels to qtest), we can only do simple
13  * tests that initialize the devices.
14  */
15 
16 #include "qemu/osdep.h"
17 #include "libqtest-single.h"
18 #include "libqos/virtio.h"
19 
20 static void virtconsole_nop(void)
21 {
22     global_qtest = qtest_initf("-device virtio-serial-ccw,id=vser0 "
23                                 "-device virtconsole,bus=vser0.0");
24     qtest_end();
25 }
26 
27 static void virtserialport_nop(void)
28 {
29     global_qtest = qtest_initf("-device virtio-serial-ccw,id=vser0 "
30                                 "-device virtserialport,bus=vser0.0");
31     qtest_end();
32 }
33 
34 static void virtio_serial_nop(void)
35 {
36     global_qtest = qtest_initf("-device virtio-serial-ccw");
37     qtest_end();
38 }
39 
40 static void virtio_serial_hotplug(void)
41 {
42     QTestState *qts = qtest_initf("-device virtio-serial-ccw");
43 
44     qtest_qmp_device_add(qts, "virtserialport", "hp-port", "{}");
45     qtest_qmp_device_del(qts, "hp-port");
46 
47     qtest_quit(qts);
48 }
49 
50 static void virtio_rng_nop(void)
51 {
52     global_qtest = qtest_initf("-device virtio-rng-ccw");
53     qtest_end();
54 }
55 
56 static void virtio_scsi_nop(void)
57 {
58     global_qtest = qtest_initf("-device virtio-scsi-ccw");
59     qtest_end();
60 }
61 
62 static void virtio_scsi_hotplug(void)
63 {
64     QTestState *s = qtest_initf("-drive if=none,id=drv0,file=null-co://,"
65                                 "file.read-zeroes=on,format=raw "
66                                 "-drive if=none,id=drv1,file=null-co://,"
67                                 "file.read-zeroes=on,format=raw "
68                                 "-device virtio-scsi-ccw "
69                                 "-device scsi-hd,drive=drv0");
70     qtest_qmp_device_add(s, "scsi-hd", "scsihd", "{'drive': 'drv1'}");
71     qtest_qmp_device_del(s, "scsihd");
72 
73     qtest_quit(s);
74 }
75 
76 int main(int argc, char **argv)
77 {
78     g_test_init(&argc, &argv, NULL);
79     if (qtest_has_device("virtio-serial-ccw")) {
80         qtest_add_func("/virtio/console/nop", virtconsole_nop);
81         qtest_add_func("/virtio/serialport/nop", virtserialport_nop);
82         qtest_add_func("/virtio/serial/nop", virtio_serial_nop);
83         qtest_add_func("/virtio/serial/hotplug", virtio_serial_hotplug);
84     }
85     if (qtest_has_device("virtio-rng-ccw")) {
86         qtest_add_func("/virtio/rng/nop", virtio_rng_nop);
87     }
88     if (qtest_has_device("virtio-scsi-ccw")) {
89         qtest_add_func("/virtio/scsi/nop", virtio_scsi_nop);
90         qtest_add_func("/virtio/scsi/hotplug", virtio_scsi_hotplug);
91     }
92 
93     return g_test_run();
94 }
95