Skip to content

Commit b19fc63

Browse files
committed
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-2.0' into staging
QOM/QTest infrastructure fixes * QOM cast fix for virtserialport and regression test * QTest error handling fix * QTest output cleanup # gpg: Signature made Thu 13 Mar 2014 20:43:34 GMT using RSA key ID 3E7E013F # gpg: Good signature from "Andreas Färber <afaerber@suse.de>" # gpg: aka "Andreas Färber <afaerber@suse.com>" * remotes/afaerber/tags/qom-devices-for-2.0: main-loop: Suppress "I/O thread spun" warnings for qtest qtest: Fix crash if SIGABRT during qtest_init() virtio-console-test: Test virtserialport as well virtio-console: Fix VIRTIO_CONSOLE() cast macro Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2 parents 90c5d39 + 01c22f2 commit b19fc63

File tree

7 files changed

+39
-29
lines changed

7 files changed

+39
-29
lines changed

hw/char/virtio-console.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "trace.h"
1616
#include "hw/virtio/virtio-serial.h"
1717

18-
#define TYPE_VIRTIO_CONSOLE "virtconsole"
18+
#define TYPE_VIRTIO_CONSOLE_SERIAL_PORT "virtserialport"
1919
#define VIRTIO_CONSOLE(obj) \
20-
OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE)
20+
OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE_SERIAL_PORT)
2121

2222
typedef struct VirtConsole {
2323
VirtIOSerialPort parent_obj;
@@ -154,28 +154,16 @@ static void virtconsole_unrealize(DeviceState *dev, Error **errp)
154154
}
155155
}
156156

157-
static Property virtconsole_properties[] = {
158-
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
159-
DEFINE_PROP_END_OF_LIST(),
160-
};
161-
162157
static void virtconsole_class_init(ObjectClass *klass, void *data)
163158
{
164-
DeviceClass *dc = DEVICE_CLASS(klass);
165159
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
166160

167161
k->is_console = true;
168-
k->realize = virtconsole_realize;
169-
k->unrealize = virtconsole_unrealize;
170-
k->have_data = flush_buf;
171-
k->set_guest_connected = set_guest_connected;
172-
dc->props = virtconsole_properties;
173162
}
174163

175164
static const TypeInfo virtconsole_info = {
176-
.name = TYPE_VIRTIO_CONSOLE,
177-
.parent = TYPE_VIRTIO_SERIAL_PORT,
178-
.instance_size = sizeof(VirtConsole),
165+
.name = "virtconsole",
166+
.parent = TYPE_VIRTIO_CONSOLE_SERIAL_PORT,
179167
.class_init = virtconsole_class_init,
180168
};
181169

@@ -197,16 +185,16 @@ static void virtserialport_class_init(ObjectClass *klass, void *data)
197185
}
198186

199187
static const TypeInfo virtserialport_info = {
200-
.name = "virtserialport",
188+
.name = TYPE_VIRTIO_CONSOLE_SERIAL_PORT,
201189
.parent = TYPE_VIRTIO_SERIAL_PORT,
202190
.instance_size = sizeof(VirtConsole),
203191
.class_init = virtserialport_class_init,
204192
};
205193

206194
static void virtconsole_register_types(void)
207195
{
208-
type_register_static(&virtconsole_info);
209196
type_register_static(&virtserialport_info);
197+
type_register_static(&virtconsole_info);
210198
}
211199

212200
type_init(virtconsole_register_types)

main-loop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qemu-common.h"
2626
#include "qemu/timer.h"
2727
#include "qemu/sockets.h"// struct in_addr needed for libslirp.h
28+
#include "sysemu/qtest.h"
2829
#include "slirp/libslirp.h"
2930
#include "qemu/main-loop.h"
3031
#include "block/aio.h"
@@ -208,7 +209,7 @@ static int os_host_main_loop_wait(int64_t timeout)
208209
if (!timeout && (spin_counter > MAX_MAIN_LOOP_SPIN)) {
209210
static bool notified;
210211

211-
if (!notified) {
212+
if (!notified && !qtest_enabled()) {
212213
fprintf(stderr,
213214
"main-loop: WARNING: I/O thread spun for %d iterations\n",
214215
MAX_MAIN_LOOP_SPIN);

stubs/Makefile.objs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ stub-obj-y += mon-print-filename.o
1818
stub-obj-y += mon-protocol-event.o
1919
stub-obj-y += mon-set-error.o
2020
stub-obj-y += pci-drive-hot-add.o
21+
stub-obj-y += qtest.o
2122
stub-obj-y += reset.o
2223
stub-obj-y += set-fd-handler.o
2324
stub-obj-y += slirp.o

stubs/qtest.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* qtest stubs
3+
*
4+
* Copyright (c) 2014 Linaro Limited
5+
* Written by Peter Maydell
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+
#include "qemu-common.h"
12+
13+
/* Needed for qtest_allowed() */
14+
bool qtest_allowed;

tests/libqtest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ QTestState *qtest_init(const char *extra_args)
120120
qemu_binary = getenv("QTEST_QEMU_BINARY");
121121
g_assert(qemu_binary != NULL);
122122

123-
s = g_malloc(sizeof(*s));
123+
global_qtest = s = g_malloc(sizeof(*s));
124124

125125
socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
126126
qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
@@ -181,6 +181,7 @@ QTestState *qtest_init(const char *extra_args)
181181
void qtest_quit(QTestState *s)
182182
{
183183
sigaction(SIGABRT, &s->sigact_old, NULL);
184+
global_qtest = NULL;
184185

185186
kill_qemu(s);
186187
close(s->fd);

tests/libqtest.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ void qtest_add_func(const char *str, void (*fn));
335335
*/
336336
static inline QTestState *qtest_start(const char *args)
337337
{
338-
global_qtest = qtest_init(args);
339-
return global_qtest;
338+
return qtest_init(args);
340339
}
341340

342341
/**
@@ -347,7 +346,6 @@ static inline QTestState *qtest_start(const char *args)
347346
static inline void qtest_end(void)
348347
{
349348
qtest_quit(global_qtest);
350-
global_qtest = NULL;
351349
}
352350

353351
/**

tests/virtio-console-test.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@
1313
#include "qemu/osdep.h"
1414

1515
/* Tests only initialization so far. TODO: Replace with functional tests */
16-
static void pci_nop(void)
16+
static void console_pci_nop(void)
1717
{
18+
qtest_start("-device virtio-serial-pci,id=vser0 "
19+
"-device virtconsole,bus=vser0.0");
20+
qtest_end();
21+
}
22+
23+
static void serialport_pci_nop(void)
24+
{
25+
qtest_start("-device virtio-serial-pci,id=vser0 "
26+
"-device virtserialport,bus=vser0.0");
27+
qtest_end();
1828
}
1929

2030
int main(int argc, char **argv)
2131
{
2232
int ret;
2333

2434
g_test_init(&argc, &argv, NULL);
25-
qtest_add_func("/virtio/console/pci/nop", pci_nop);
35+
qtest_add_func("/virtio/console/pci/nop", console_pci_nop);
36+
qtest_add_func("/virtio/serialport/pci/nop", serialport_pci_nop);
2637

27-
qtest_start("-device virtio-serial-pci,id=vser0 "
28-
"-device virtconsole,bus=vser0.0");
2938
ret = g_test_run();
3039

31-
qtest_end();
32-
3340
return ret;
3441
}

0 commit comments

Comments
 (0)