Skip to contentSkip to conversation

QOM devices patch queue 2014-03-31

GIT PULL Applied Andreas Färber 2 participants 18 messages Mar 31, 2014 – Apr 1, 2014

lore
Share & tools
lore
#0 lore raw

Hello Peter,

This is my QOM (devices) patch queue. Please pull.

Regards,
Andreas

Cc Peter Maydell <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Stefan Weil <[email protected]>
Cc Keith Busch <[email protected]>
Cc Paolo Bonzini <[email protected]>

The following changes since commit 58b590148ca1b19f64f533d40e32b5acce5c21e7:

pci: Fix clearing IRQs on reset (2014-03-31 19:53:34 +0100)

are available in the git repository at:

git://github.com/afaerber/qemu-cpu.git tags/qom-devices-for-2.0

for you to fetch changes up to 7373fc76930fc0994bab1bc2defd1d3a2b2adaa3:

tmp105-test: Test QOM property and precision (2014-03-31 23:03:14 +0200)

----------------------------------------------------------------
QOM/QTest infrastructure fixes

* Revised QTest SIGABRT fix
* Test cleanups for non-POSIX hosts
* QTest test cases for NVMe, virtio-9p, pvpanic, i82801b11
* QTest API addition for reading events
* TMP105 fix and regression test

----------------------------------------------------------------
Andreas Färber (7):
nvme: Permit zero-length block devices
tests: Add nvme qtest
tests: Add virtio-9p qtest
tests: Add pvpanic qtest
qtest: Factor out qtest_qmp_receive()
pvpanic-test: Assert pause event
tests: Add i82801b11 qtest

Paolo Bonzini (4):
tmp105: Read temperature in milli-celsius
tmp105-test: Wrap simple building blocks for testing
tmp105-test: Add a second sensor and test that one
tmp105-test: Test QOM property and precision

Stefan Hajnoczi (4):
Revert "qtest: Fix crash if SIGABRT during qtest_init()"
qtest: Keep list of qtest instances for SIGABRT handler
tests: Skip POSIX-only tests on Windows
tests: Correctly skip qtest on non-POSIX hosts

Stefan Weil (1):
tests: Remove unsupported tests for MinGW

 MAINTAINERS            |   2 +
 hw/block/nvme.c        |   4 +-
 hw/misc/tmp105.c       |   8 +--
 tests/Makefile         |  23 +++++++--
 tests/i82801b11-test.c |  33 ++++++++++++
 tests/libqtest.c       |  65 ++++++++++++++++-------
 tests/libqtest.h       |  22 +++++++-
 tests/nvme-test.c      |  34 +++++++++++++
 tests/pvpanic-test.c   |  47 +++++++++++++++++
 tests/test-aio.c       |  16 ++++++
 tests/tmp105-test.c    | 136 +++++++++++++++++++++++++++++++++++++++++--------
 tests/virtio-9p-test.c |  46 +++++++++++++++++
 12 files changed, 388 insertions(+), 48 deletions(-)
 create mode 100644 tests/i82801b11-test.c
 create mode 100644 tests/nvme-test.c
 create mode 100644 tests/pvpanic-test.c
 create mode 100644 tests/virtio-9p-test.c
#1 lore raw

[Qemu-devel] [PULL for-2.0 03/16] tests: Remove unsupported tests for MinGW

From: Stefan Weil <[email protected]>

test_timer_schedule and test_source_timer_schedule don't compile for MinGW because some functions are not implemented for MinGW (qemu_pipe, aio_set_fd_handler).

---
 tests/test-aio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tests/test-aio.c +16 -0
index 56f4288..e5f8b55 100644
@@ -65,6 +65,8 @@ static void bh_test_cb(void *opaque)
     }
 }
 
+#if !defined(_WIN32)
+
 static void timer_test_cb(void *opaque)
 {
     TimerTestData *data = opaque;
@@ -78,6 +80,8 @@ static void dummy_io_handler_read(void *opaque)
 {
 }
 
+#endif /* !_WIN32 */
+
 static void bh_delete_cb(void *opaque)
 {
     BHTestData *data = opaque;
@@ -423,6 +427,8 @@ static void test_wait_event_notifier_noflush(void)
     event_notifier_cleanup(&data.e);
 }
 
+#if !defined(_WIN32)
+
 static void test_timer_schedule(void)
 {
     TimerTestData data = { .n = 0, .ctx = ctx, .ns = SCALE_MS * 750LL,
@@ -484,6 +490,8 @@ static void test_timer_schedule(void)
     timer_del(&data.timer);
 }
 
+#endif /* !_WIN32 */
+
 /* Now the same tests, using the context as a GSource.  They are
  * very similar to the ones above, with g_main_context_iteration
  * replacing aio_poll.  However:
@@ -766,6 +774,8 @@ static void test_source_wait_event_notifier_noflush(void)
     event_notifier_cleanup(&data.e);
 }
 
+#if !defined(_WIN32)
+
 static void test_source_timer_schedule(void)
 {
     TimerTestData data = { .n = 0, .ctx = ctx, .ns = SCALE_MS * 750LL,
@@ -815,6 +825,8 @@ static void test_source_timer_schedule(void)
     timer_del(&data.timer);
 }
 
+#endif /* !_WIN32 */
+
 
 /* End of tests.  */
 
@@ -845,7 +857,9 @@ int main(int argc, char **argv)
     g_test_add_func("/aio/event/wait",              test_wait_event_notifier);
     g_test_add_func("/aio/event/wait/no-flush-cb",  test_wait_event_notifier_noflush);
     g_test_add_func("/aio/event/flush",             test_flush_event_notifier);
+#if !defined(_WIN32)
     g_test_add_func("/aio/timer/schedule",          test_timer_schedule);
+#endif
 
     g_test_add_func("/aio-gsource/notify",                  test_source_notify);
     g_test_add_func("/aio-gsource/flush",                   test_source_flush);
@@ -860,6 +874,8 @@ int main(int argc, char **argv)
     g_test_add_func("/aio-gsource/event/wait",              test_source_wait_event_notifier);
     g_test_add_func("/aio-gsource/event/wait/no-flush-cb",  test_source_wait_event_notifier_noflush);
     g_test_add_func("/aio-gsource/event/flush",             test_source_flush_event_notifier);
+#if !defined(_WIN32)
     g_test_add_func("/aio-gsource/timer/schedule",          test_source_timer_schedule);
+#endif
     return g_test_run();
 }
Signature · 1 line
1.8.4.5
#2 lore raw

[Qemu-devel] [PULL for-2.0 02/16] qtest: Keep list of qtest instances for SIGABRT handler

In reply to Andreas Färber

From: Stefan Hajnoczi <[email protected]>

Keep track of active qtest instances so we can kill them when the test aborts. This ensures no QEMU processes are left running after test failure.

---
 tests/libqtest.c | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)
tests/libqtest.c +37 -10
index 2b90e4a..d9e3a33 100644
@@ -48,6 +48,9 @@ struct QTestState
     struct sigaction sigact_old; /* restored on exit */
 };
 
+static GList *qtest_instances;
+static struct sigaction sigact_old;
+
 #define g_assert_no_errno(ret) do { \
     g_assert_cmpint(ret, !=, -1); \
 } while (0)
@@ -104,7 +107,28 @@ static void kill_qemu(QTestState *s)
 
 static void sigabrt_handler(int signo)
 {
-    kill_qemu(global_qtest);
+    GList *elem;
+    for (elem = qtest_instances; elem; elem = elem->next) {
+        kill_qemu(elem->data);
+    }
+}
+
+static void setup_sigabrt_handler(void)
+{
+    struct sigaction sigact;
+
+    /* Catch SIGABRT to clean up on g_assert() failure */
+    sigact = (struct sigaction){
+        .sa_handler = sigabrt_handler,
+        .sa_flags = SA_RESETHAND,
+    };
+    sigemptyset(&sigact.sa_mask);
+    sigaction(SIGABRT, &sigact, &sigact_old);
+}
+
+static void cleanup_sigabrt_handler(void)
+{
+    sigaction(SIGABRT, &sigact_old, NULL);
 }
 
 QTestState *qtest_init(const char *extra_args)
@@ -115,7 +139,6 @@ QTestState *qtest_init(const char *extra_args)
     gchar *qmp_socket_path;
     gchar *command;
     const char *qemu_binary;
-    struct sigaction sigact;
 
     qemu_binary = getenv("QTEST_QEMU_BINARY");
     g_assert(qemu_binary != NULL);
@@ -128,13 +151,12 @@ QTestState *qtest_init(const char *extra_args)
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
-    /* Catch SIGABRT to clean up on g_assert() failure */
-    sigact = (struct sigaction){
-        .sa_handler = sigabrt_handler,
-        .sa_flags = SA_RESETHAND,
-    };
-    sigemptyset(&sigact.sa_mask);
-    sigaction(SIGABRT, &sigact, &s->sigact_old);
+    /* Only install SIGABRT handler once */
+    if (!qtest_instances) {
+        setup_sigabrt_handler();
+    }
+
+    qtest_instances = g_list_prepend(qtest_instances, s);
 
     s->qemu_pid = fork();
     if (s->qemu_pid == 0) {
@@ -180,7 +202,12 @@ QTestState *qtest_init(const char *extra_args)
 
 void qtest_quit(QTestState *s)
 {
-    sigaction(SIGABRT, &s->sigact_old, NULL);
+    /* Uninstall SIGABRT handler on last instance */
+    if (qtest_instances && !qtest_instances->next) {
+        cleanup_sigabrt_handler();
+    }
+
+    qtest_instances = g_list_remove(qtest_instances, s);
 
     kill_qemu(s);
     close(s->fd);
Signature · 1 line
1.8.4.5
#3 lore raw

[Qemu-devel] [PULL for-2.0 04/16] tests: Skip POSIX-only tests on Windows

In reply to Andreas Färber

From: Stefan Hajnoczi <[email protected]>

test-rfifolock and test-vmstate only build on POSIX hosts. Exclude them if building for Windows.

---
 tests/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/Makefile +2 -2
index 2d021fb..ef286e7 100644
@@ -35,7 +35,7 @@ check-unit-y += tests/test-visitor-serialization$(EXESUF)
 check-unit-y += tests/test-iov$(EXESUF)
 gcov-files-test-iov-y = util/iov.c
 check-unit-y += tests/test-aio$(EXESUF)
-check-unit-y += tests/test-rfifolock$(EXESUF)
+check-unit-$(CONFIG_POSIX) += tests/test-rfifolock$(EXESUF)
 check-unit-y += tests/test-throttle$(EXESUF)
 gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c
 gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c
@@ -59,7 +59,7 @@ check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-y += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
-check-unit-y += tests/test-vmstate$(EXESUF)
+check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
Signature · 1 line
1.8.4.5
#4 lore raw

[Qemu-devel] [PULL for-2.0 07/16] tests: Add nvme qtest

In reply to Andreas Färber
---
 MAINTAINERS       |  1 +
 tests/Makefile    |  3 +++
 tests/nvme-test.c | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)
 create mode 100644 tests/nvme-test.c
MAINTAINERS +1 -0
index 7d17f83..4d8eefc 100644
@@ -648,6 +648,7 @@ nvme
 M: Keith Busch <[email protected]>
 S: Supported
 F: hw/block/nvme*
+F: tests/nvme-test.c
 
 Xilinx EDK
 M: Peter Crosthwaite <[email protected]>
tests/Makefile +3 -0
index 0e3eb44..01a3463 100644
@@ -100,6 +100,8 @@ check-qtest-pci-y += tests/eepro100-test$(EXESUF)
 gcov-files-pci-y += hw/net/eepro100.c
 check-qtest-pci-y += tests/ne2000-test$(EXESUF)
 gcov-files-pci-y += hw/net/ne2000.c
+check-qtest-pci-y += tests/nvme-test$(EXESUF)
+gcov-files-pci-y += hw/block/nvme.c
 check-qtest-pci-y += $(check-qtest-virtio-y)
 gcov-files-pci-y += $(gcov-files-virtio-y) hw/virtio/virtio-pci.c
 check-qtest-pci-y += tests/tpci200-test$(EXESUF)
@@ -272,6 +274,7 @@ tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
 tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
+tests/nvme-test$(EXESUF): tests/nvme-test.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 
 # QTest rules
tests/nvme-test.c new file +34 -0
new file mode 100644
index 0000000..85768e8
@@ -0,0 +1,34 @@
+/*
+ * QTest testcase for NVMe
+ *
+ * Copyright (c) 2014 SUSE LINUX Products GmbH
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include "libqtest.h"
+#include "qemu/osdep.h"
+
+/* Tests only initialization so far. TODO: Replace with functional tests */
+static void nop(void)
+{
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/nvme/nop", nop);
+
+    qtest_start("-drive id=drv0,if=none,file=/dev/null "
+                "-device nvme,drive=drv0,serial=foo");
+    ret = g_test_run();
+
+    qtest_end();
+
+    return ret;
+}
Signature · 1 line
1.8.4.5
#5 lore raw

[Qemu-devel] [PULL for-2.0 05/16] tests: Correctly skip qtest on non-POSIX hosts

In reply to Andreas Färber

From: Stefan Hajnoczi <[email protected]>

qtest test cases only work on POSIX hosts. The following line only defines dependencies for qtest binaries on POSIX hosts:

  check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS),$(check-qtest-$(TARGET)-y))

But the QTEST_TARGETS definition earlier in the Makefile fails to check CONFIG_POSIX. This causes make targets to be generated for qtest test cases even though we don't know how to build the binaries.

The following error message is printed when trying to run gtester on a binary that was never built:

GLib-WARNING **: Failed to execute test binary: tests/endianness-test.exe: Failed to execute child process "tests/endianness-test.exe" (No such file or directory)

This patch makes QTEST_TARGETS empty on non-POSIX hosts. This prevents the targets from being generated.

---
 tests/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/Makefile +3 -1
index ef286e7..0e3eb44 100644
@@ -277,8 +277,10 @@ tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_hel
 # QTest rules
 
 TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS)))
+ifeq ($(CONFIG_POSIX),y)
 QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TARGET),))
-check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y))
+check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y))
+endif
 
 qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a
 $(check-qtest-y): $(qtest-obj-y)
Signature · 1 line
1.8.4.5
#6 lore raw

[Qemu-devel] [PULL for-2.0 06/16] nvme: Permit zero-length block devices

In reply to Andreas Färber

It may not be sensible for normal use cases, but it allows to use /dev/null in QTest.

---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nvme.c +2 -2
index 2882ffe..5fd8f89 100644
@@ -752,8 +752,8 @@ static int nvme_init(PCIDevice *pci_dev)
         return -1;
     }
 
-    bs_size =  bdrv_getlength(n->conf.bs);
-    if (bs_size <= 0) {
+    bs_size = bdrv_getlength(n->conf.bs);
+    if (bs_size < 0) {
         return -1;
     }
 
Signature · 1 line
1.8.4.5
#7 lore raw

[Qemu-devel] [PULL for-2.0 08/16] tests: Add virtio-9p qtest

In reply to Andreas Färber

Make it conditional to 9p availability.
Create a temporary directory to share.

---
 MAINTAINERS            |  1 +
 tests/Makefile         |  6 ++++++
 tests/virtio-9p-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 tests/virtio-9p-test.c
MAINTAINERS +1 -0
index 4d8eefc..4923b0f 100644
@@ -623,6 +623,7 @@ M: Aneesh Kumar K.V <[email protected]>
 S: Supported
 F: hw/9pfs/
 F: fsdev/
+F: tests/virtio-9p-test.c
 T: git git://github.com/kvaneesh/QEMU.git
 
 virtio-blk
tests/Makefile +6 -0
index 01a3463..843429b 100644
@@ -84,6 +84,11 @@ check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF)
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
+ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
+check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF)
+gcov-files-virtio-y += hw/9pfs/virtio-9p.c
+gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c
+endif
 check-qtest-virtio-y += tests/virtio-serial-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/char/virtio-serial-bus.c
 check-qtest-virtio-y += $(check-qtest-virtioserial-y)
@@ -267,6 +272,7 @@ tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o
+tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o
 tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o
 tests/virtio-console-test$(EXESUF): tests/virtio-console-test.o
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
tests/virtio-9p-test.c new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.8.4.5
#8 lore raw

[Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()"

In reply to Andreas Färber

From: Stefan Hajnoczi <[email protected]>

It turns out there are test cases that use multiple libqtest instances. We cannot use a global qtest instance in the SIGABRT handler.

This reverts commit cb201b4872f16dfbce63f8648b2584631e2e965f.

---
 tests/libqtest.c | 3 +--
 tests/libqtest.h | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
tests/libqtest.c +1 -2
index b03b57a..2b90e4a 100644
@@ -120,7 +120,7 @@ QTestState *qtest_init(const char *extra_args)
     qemu_binary = getenv("QTEST_QEMU_BINARY");
     g_assert(qemu_binary != NULL);
 
-    global_qtest = s = g_malloc(sizeof(*s));
+    s = g_malloc(sizeof(*s));
 
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
@@ -181,7 +181,6 @@ QTestState *qtest_init(const char *extra_args)
 void qtest_quit(QTestState *s)
 {
     sigaction(SIGABRT, &s->sigact_old, NULL);
-    global_qtest = NULL;
 
     kill_qemu(s);
     close(s->fd);
tests/libqtest.h +3 -1
index 27a58fd..8268c09 100644
@@ -335,7 +335,8 @@ void qtest_add_func(const char *str, void (*fn));
  */
 static inline QTestState *qtest_start(const char *args)
 {
-    return qtest_init(args);
+    global_qtest = qtest_init(args);
+    return global_qtest;
 }
 
 /**
@@ -346,6 +347,7 @@ static inline QTestState *qtest_start(const char *args)
 static inline void qtest_end(void)
 {
     qtest_quit(global_qtest);
+    global_qtest = NULL;
 }
 
 /**
Signature · 1 line
1.8.4.5
#9 lore raw

[Qemu-devel] [PULL for-2.0 10/16] qtest: Factor out qtest_qmp_receive()

In reply to Andreas Färber
---
 tests/libqtest.c | 15 ++++++++++-----
 tests/libqtest.h | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
tests/libqtest.c +10 -5
index d9e3a33..8155695 100644
@@ -345,14 +345,10 @@ static void qmp_response(JSONMessageParser *parser, QList *tokens)
     qmp->response = (QDict *)obj;
 }
 
-QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
+QDict *qtest_qmp_receive(QTestState *s)
 {
     QMPResponseParser qmp;
 
-    /* Send QMP request */
-    socket_sendf(s->qmp_fd, fmt, ap);
-
-    /* Receive reply */
     qmp.response = NULL;
     json_message_parser_init(&qmp.parser, qmp_response);
     while (!qmp.response) {
@@ -376,6 +372,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
     return qmp.response;
 }
 
+QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
+{
+    /* Send QMP request */
+    socket_sendf(s->qmp_fd, fmt, ap);
+
+    /* Receive reply */
+    return qtest_qmp_receive(s);
+}
+
 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
 {
     va_list ap;
tests/libqtest.h +18 -0
index 8268c09..8f323c7 100644
@@ -83,6 +83,14 @@ void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap);
 QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
 
 /**
+ * qtest_receive:
+ * @s: #QTestState instance to operate on.
+ *
+ * Reads a QMP message from QEMU and returns the response.
+ */
+QDict *qtest_qmp_receive(QTestState *s);
+
+/**
  * qtest_get_irq:
  * @s: #QTestState instance to operate on.
  * @num: Interrupt to observe.
@@ -367,6 +375,16 @@ QDict *qmp(const char *fmt, ...);
 void qmp_discard_response(const char *fmt, ...);
 
 /**
+ * qmp_receive:
+ *
+ * Reads a QMP message from QEMU and returns the response.
+ */
+static inline QDict *qmp_receive(void)
+{
+    return qtest_qmp_receive(global_qtest);
+}
+
+/**
  * get_irq:
  * @num: Interrupt to observe.
  *
Signature · 1 line
1.8.4.5
#10 lore raw

[Qemu-devel] [PULL for-2.0 11/16] pvpanic-test: Assert pause event

In reply to Andreas Färber
---
 tests/pvpanic-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tests/pvpanic-test.c +9 -0
index 7bb4d06..a7ad6b3 100644
@@ -15,11 +15,20 @@
 static void test_panic(void)
 {
     uint8_t val;
+    QDict *response, *data;
 
     val = inb(0x505);
     g_assert_cmpuint(val, ==, 1);
 
     outb(0x505, 0x1);
+
+    response = qmp_receive();
+    g_assert(qdict_haskey(response, "event"));
+    g_assert_cmpstr(qdict_get_str(response, "event"), ==, "GUEST_PANICKED");
+    g_assert(qdict_haskey(response, "data"));
+    data = qdict_get_qdict(response, "data");
+    g_assert(qdict_haskey(data, "action"));
+    g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause");
 }
 
 int main(int argc, char **argv)
Signature · 1 line
1.8.4.5
#11 lore raw

[Qemu-devel] [PULL for-2.0 09/16] tests: Add pvpanic qtest

In reply to Andreas Färber
---
 tests/Makefile       |  3 +++
 tests/pvpanic-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 tests/pvpanic-test.c
tests/Makefile +3 -0
index 843429b..e4f7c07 100644
@@ -133,6 +133,8 @@ check-qtest-i386-y += tests/vmxnet3-test$(EXESUF)
 gcov-files-i386-y += hw/net/vmxnet3.c
 gcov-files-i386-y += hw/net/vmxnet_rx_pkt.c
 gcov-files-i386-y += hw/net/vmxnet_tx_pkt.c
+check-qtest-i386-y += tests/pvpanic-test$(EXESUF)
+gcov-files-i386-y += i386-softmmu/hw/misc/pvpanic.c
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -281,6 +283,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/nvme-test$(EXESUF): tests/nvme-test.o
+tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 
 # QTest rules
tests/pvpanic-test.c new file +38 -0
new file mode 100644
index 0000000..7bb4d06
@@ -0,0 +1,38 @@
+/*
+ * QTest testcase for PV Panic
+ *
+ * Copyright (c) 2014 SUSE LINUX Products GmbH
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include "libqtest.h"
+#include "qemu/osdep.h"
+
+static void test_panic(void)
+{
+    uint8_t val;
+
+    val = inb(0x505);
+    g_assert_cmpuint(val, ==, 1);
+
+    outb(0x505, 0x1);
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/pvpanic/panic", test_panic);
+
+    qtest_start("-device pvpanic");
+    ret = g_test_run();
+
+    qtest_end();
+
+    return ret;
+}
Signature · 1 line
1.8.4.5
#12 lore raw

[Qemu-devel] [PULL for-2.0 12/16] tests: Add i82801b11 qtest

In reply to Andreas Färber
---
 tests/Makefile         |  3 +++
 tests/i82801b11-test.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 tests/i82801b11-test.c
tests/Makefile +3 -0
index e4f7c07..6086f68 100644
@@ -135,6 +135,8 @@ gcov-files-i386-y += hw/net/vmxnet_rx_pkt.c
 gcov-files-i386-y += hw/net/vmxnet_tx_pkt.c
 check-qtest-i386-y += tests/pvpanic-test$(EXESUF)
 gcov-files-i386-y += i386-softmmu/hw/misc/pvpanic.c
+check-qtest-i386-y += tests/i82801b11-test$(EXESUF)
+gcov-files-i386-y += hw/pci-bridge/i82801b11.c
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -284,6 +286,7 @@ tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/nvme-test$(EXESUF): tests/nvme-test.o
 tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o
+tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 
 # QTest rules
tests/i82801b11-test.c new file +33 -0
new file mode 100644
index 0000000..78d9ce0
@@ -0,0 +1,33 @@
+/*
+ * QTest testcase for i82801b11
+ *
+ * Copyright (c) 2014 SUSE LINUX Products GmbH
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include "libqtest.h"
+#include "qemu/osdep.h"
+
+/* Tests only initialization so far. TODO: Replace with functional tests */
+static void nop(void)
+{
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/i82801b11/nop", nop);
+
+    qtest_start("-machine q35 -device i82801b11-bridge,bus=pcie.0,addr=1e.0");
+    ret = g_test_run();
+
+    qtest_end();
+
+    return ret;
+}
Signature · 1 line
1.8.4.5
#13 lore raw

[Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius

In reply to Andreas Färber

From: Paolo Bonzini <[email protected]>

Right now, the temperature property must be written in milli-celsius, but it reads back the value in 8.8 fixed point. Fix this by letting the property read back the original value (possibly rounded). Also simplify the code that does the conversion.

Before:

(QEMU) qom-set path=/machine/peripheral/sensor property=temperature value=20000 {u'return': {}}
(QEMU) qom-get path=sensor property=temperature
{u'return': 5120}

After:

(QEMU) qom-set path=/machine/peripheral/sensor property=temperature value=20000 {u'return': {}}
(QEMU) qom-get path=sensor property=temperature
{u'return': 20000}

---
 hw/misc/tmp105.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/misc/tmp105.c +5 -3
index 155e03d..63aa3d6 100644
@@ -56,12 +56,14 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque,
                                    const char *name, Error **errp)
 {
     TMP105State *s = TMP105(obj);
-    int64_t value = s->temperature;
+    int64_t value = s->temperature * 1000 / 256;
 
     visit_type_int(v, &value, name, errp);
 }
 
-/* Units are 0.001 centigrades relative to 0 C.  */
+/* Units are 0.001 centigrades relative to 0 C.  s->temperature is 8.8
+ * fixed point, so units are 1/256 centigrades.  A simple ratio will do.
+ */
 static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque,
                                    const char *name, Error **errp)
 {
@@ -78,7 +80,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
-    s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4;
+    s->temperature = (int16_t) (temp * 256 / 1000);
 
     tmp105_alarm_update(s);
 }
Signature · 1 line
1.8.4.5
#14 lore raw

[Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing

In reply to Andreas Färber

From: Paolo Bonzini <[email protected]>

The next patches will add more reads and writes. Add a simple testing API for this.

---
 tests/tmp105-test.c | 54 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 18 deletions(-)
tests/tmp105-test.c +36 -18
index 0834219..20a1894 100644
@@ -20,39 +20,57 @@
 static I2CAdapter *i2c;
 static uint8_t addr;
 
-static void send_and_receive(void)
+static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg)
 {
-    uint8_t cmd[3];
     uint8_t resp[2];
-
-    cmd[0] = TMP105_REG_TEMPERATURE;
-    i2c_send(i2c, addr, cmd, 1);
+    i2c_send(i2c, addr, &reg, 1);
     i2c_recv(i2c, addr, resp, 2);
-    g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], ==, 0);
+    return (resp[0] << 8) | resp[1];
+}
+
+static void tmp105_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
+                        uint8_t value)
+{
+    uint8_t cmd[2];
+    uint8_t resp[1];
 
-    cmd[0] = TMP105_REG_CONFIG;
-    cmd[1] = 0x0; /* matches the reset value */
+    cmd[0] = reg;
+    cmd[1] = value;
     i2c_send(i2c, addr, cmd, 2);
     i2c_recv(i2c, addr, resp, 1);
     g_assert_cmphex(resp[0], ==, cmd[1]);
+}
 
-    cmd[0] = TMP105_REG_T_LOW;
-    cmd[1] = 0x12;
-    cmd[2] = 0x34;
-    i2c_send(i2c, addr, cmd, 3);
-    i2c_recv(i2c, addr, resp, 2);
-    g_assert_cmphex(resp[0], ==, cmd[1]);
-    g_assert_cmphex(resp[1], ==, cmd[2]);
+static void tmp105_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
+                         uint16_t value)
+{
+    uint8_t cmd[3];
+    uint8_t resp[2];
 
-    cmd[0] = TMP105_REG_T_HIGH;
-    cmd[1] = 0x42;
-    cmd[2] = 0x31;
+    cmd[0] = reg;
+    cmd[1] = value >> 8;
+    cmd[2] = value & 255;
     i2c_send(i2c, addr, cmd, 3);
     i2c_recv(i2c, addr, resp, 2);
     g_assert_cmphex(resp[0], ==, cmd[1]);
     g_assert_cmphex(resp[1], ==, cmd[2]);
 }
 
+
+static void send_and_receive(void)
+{
+    uint16_t value;
+
+    value = tmp105_get16(i2c, addr, TMP105_REG_TEMPERATURE);
+    g_assert_cmpuint(value, ==, 0);
+
+    /* reset */
+    tmp105_set8(i2c, addr, TMP105_REG_CONFIG, 0);
+
+    tmp105_set16(i2c, addr, TMP105_REG_T_LOW, 0x1234);
+    tmp105_set16(i2c, addr, TMP105_REG_T_HIGH, 0x4231);
+}
+
 int main(int argc, char **argv)
 {
     QTestState *s = NULL;
Signature · 1 line
1.8.4.5
#15 lore raw

[Qemu-devel] [PULL for-2.0 15/16] tmp105-test: Add a second sensor and test that one

In reply to Andreas Färber

From: Paolo Bonzini <[email protected]>

This will make it easier to reach the device under test via QOM.

---
 tests/tmp105-test.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
tests/tmp105-test.c +9 -8
index 20a1894..4e640b4 100644
@@ -15,10 +15,10 @@
 
 #define OMAP2_I2C_1_BASE 0x48070000
 
-#define N8X0_ADDR 0x48
+#define TMP105_TEST_ID   "tmp105-test"
+#define TMP105_TEST_ADDR 0x49
 
 static I2CAdapter *i2c;
-static uint8_t addr;
 
 static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg)
 {
@@ -61,14 +61,14 @@ static void send_and_receive(void)
 {
     uint16_t value;
 
-    value = tmp105_get16(i2c, addr, TMP105_REG_TEMPERATURE);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
     g_assert_cmpuint(value, ==, 0);
 
     /* reset */
-    tmp105_set8(i2c, addr, TMP105_REG_CONFIG, 0);
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0);
 
-    tmp105_set16(i2c, addr, TMP105_REG_T_LOW, 0x1234);
-    tmp105_set16(i2c, addr, TMP105_REG_T_HIGH, 0x4231);
+    tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234);
+    tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231);
 }
 
 int main(int argc, char **argv)
@@ -78,9 +78,10 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    s = qtest_start("-machine n800");
+    s = qtest_start("-machine n800 "
+                    "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
+                    ",address=0x49");
     i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
-    addr = N8X0_ADDR;
 
     qtest_add_func("/tmp105/tx-rx", send_and_receive);
 
Signature · 1 line
1.8.4.5
#16 lore raw

[Qemu-devel] [PULL for-2.0 16/16] tmp105-test: Test QOM property and precision

In reply to Andreas Färber

From: Paolo Bonzini <[email protected]>

This adds a regression test for commit efdf6a56a7c73753dd135ed085a223a119b5d805 (tmp105: Read temperature in milli-celsius).

---
 tests/tmp105-test.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 3 deletions(-)
tests/tmp105-test.c +76 -3
index 4e640b4..15ddaf3 100644
@@ -20,6 +20,14 @@
 
 static I2CAdapter *i2c;
 
+static uint16_t tmp105_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg)
+{
+    uint8_t resp[1];
+    i2c_send(i2c, addr, &reg, 1);
+    i2c_recv(i2c, addr, resp, 1);
+    return resp[0];
+}
+
 static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg)
 {
     uint8_t resp[2];
@@ -56,16 +64,81 @@ static void tmp105_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
     g_assert_cmphex(resp[1], ==, cmd[2]);
 }
 
+static int qmp_tmp105_get_temperature(const char *id)
+{
+    QDict *response;
+    int ret;
 
+    response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': '%s', "
+                   "'property': 'temperature' } }", id);
+    g_assert(qdict_haskey(response, "return"));
+    ret = qdict_get_int(response, "return");
+    QDECREF(response);
+    return ret;
+}
+
+static void qmp_tmp105_set_temperature(const char *id, int value)
+{
+    QDict *response;
+
+    response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': '%s', "
+                   "'property': 'temperature', 'value': %d } }", id, value);
+    g_assert(qdict_haskey(response, "return"));
+    QDECREF(response);
+}
+
+#define TMP105_PRECISION (1000/16)
 static void send_and_receive(void)
 {
     uint16_t value;
 
-    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
     g_assert_cmpuint(value, ==, 0);
 
-    /* reset */
-    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0);
+
+    qmp_tmp105_set_temperature(TMP105_TEST_ID, 20000);
+    value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
+    g_assert_cmpuint(value, ==, 20000);
+
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x1400);
+
+    qmp_tmp105_set_temperature(TMP105_TEST_ID, 20938); /* 20 + 15/16 */
+    value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
+    g_assert_cmpuint(value, >=, 20938 - TMP105_PRECISION/2);
+    g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2);
+
+    /* Set config */
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60);
+    value = tmp105_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG);
+    g_assert_cmphex(value, ==, 0x60);
+
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x14f0);
+
+    /* Set precision to 9, 10, 11 bits.  */
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x00);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x1480);
+
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x20);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x14c0);
+
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x40);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x14e0);
+
+    /* stored precision remains the same */
+    value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
+    g_assert_cmpuint(value, >=, 20938 - TMP105_PRECISION/2);
+    g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2);
+
+    tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60);
+    value = tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE);
+    g_assert_cmphex(value, ==, 0x14f0);
 
     tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234);
     tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231);
Signature · 1 line
1.8.4.5
#17 lore raw
In reply to Andreas Färber
Quoted 52 lines · Andreas Färber

Hello Peter,

This is my QOM (devices) patch queue. Please pull.

Regards,
Andreas

Cc Peter Maydell <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Stefan Weil <[email protected]>
Cc Keith Busch <[email protected]>
Cc Paolo Bonzini <[email protected]>

The following changes since commit 58b590148ca1b19f64f533d40e32b5acce5c21e7:

pci: Fix clearing IRQs on reset (2014-03-31 19:53:34 +0100)

are available in the git repository at:

git://github.com/afaerber/qemu-cpu.git tags/qom-devices-for-2.0

for you to fetch changes up to 7373fc76930fc0994bab1bc2defd1d3a2b2adaa3:

tmp105-test: Test QOM property and precision (2014-03-31 23:03:14 +0200)

----------------------------------------------------------------
QOM/QTest infrastructure fixes

* Revised QTest SIGABRT fix
* Test cleanups for non-POSIX hosts
* QTest test cases for NVMe, virtio-9p, pvpanic, i82801b11
* QTest API addition for reading events
* TMP105 fix and regression test

----------------------------------------------------------------
Andreas Färber (7):
nvme: Permit zero-length block devices
tests: Add nvme qtest
tests: Add virtio-9p qtest
tests: Add pvpanic qtest
qtest: Factor out qtest_qmp_receive()
pvpanic-test: Assert pause event
tests: Add i82801b11 qtest

Paolo Bonzini (4):
tmp105: Read temperature in milli-celsius
tmp105-test: Wrap simple building blocks for testing
tmp105-test: Add a second sensor and test that one
tmp105-test: Test QOM property and precision

Quoted 8 lines

Stefan Hajnoczi (4):
Revert "qtest: Fix crash if SIGABRT during qtest_init()"
qtest: Keep list of qtest instances for SIGABRT handler
tests: Skip POSIX-only tests on Windows
tests: Correctly skip qtest on non-POSIX hosts

Stefan Weil (1):
tests: Remove unsupported tests for MinGW

Applied, thanks.

-- PMM