All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31
@ 2014-03-31 21:10 Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()" Andreas Färber
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Weil, Keith Busch,
	Stefan Hajnoczi, Paolo Bonzini, Andreas Färber

Hello Peter,

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

Regards,
Andreas

Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Anthony Liguori <anthony@codemonkey.ws>

Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Stefan Weil <sw@weilnetz.de>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()"
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 02/16] qtest: Keep list of qtest instances for SIGABRT handler Andreas Färber
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Stefan Hajnoczi

From: Stefan Hajnoczi <stefanha@redhat.com>

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.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/libqtest.c | 3 +--
 tests/libqtest.h | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index b03b57a..2b90e4a 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -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);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 27a58fd..8268c09 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -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;
 }
 
 /**
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 02/16] qtest: Keep list of qtest instances for SIGABRT handler
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()" Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 03/16] tests: Remove unsupported tests for MinGW Andreas Färber
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Stefan Hajnoczi

From: Stefan Hajnoczi <stefanha@redhat.com>

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.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/libqtest.c | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 2b90e4a..d9e3a33 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -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);
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 03/16] tests: Remove unsupported tests for MinGW
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()" Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 02/16] qtest: Keep list of qtest instances for SIGABRT handler Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 04/16] tests: Skip POSIX-only tests on Windows Andreas Färber
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Weil, Andreas Färber, Stefan Hajnoczi

From: Stefan Weil <sw@weilnetz.de>

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).

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/test-aio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tests/test-aio.c b/tests/test-aio.c
index 56f4288..e5f8b55 100644
--- a/tests/test-aio.c
+++ b/tests/test-aio.c
@@ -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();
 }
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 04/16] tests: Skip POSIX-only tests on Windows
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (2 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 03/16] tests: Remove unsupported tests for MinGW Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 05/16] tests: Correctly skip qtest on non-POSIX hosts Andreas Färber
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Stefan Hajnoczi

From: Stefan Hajnoczi <stefanha@redhat.com>

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

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index 2d021fb..ef286e7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
 
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 05/16] tests: Correctly skip qtest on non-POSIX hosts
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (3 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 04/16] tests: Skip POSIX-only tests on Windows Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 06/16] nvme: Permit zero-length block devices Andreas Färber
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Stefan Hajnoczi

From: Stefan Hajnoczi <stefanha@redhat.com>

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.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index ef286e7..0e3eb44 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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)
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 06/16] nvme: Permit zero-length block devices
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (4 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 05/16] tests: Correctly skip qtest on non-POSIX hosts Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 07/16] tests: Add nvme qtest Andreas Färber
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Keith Busch, Kevin Wolf, Andreas Färber, Stefan Hajnoczi

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

Acked-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 2882ffe..5fd8f89 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -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;
     }
 
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 07/16] tests: Add nvme qtest
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (5 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 06/16] nvme: Permit zero-length block devices Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 08/16] tests: Add virtio-9p qtest Andreas Färber
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Keith Busch, Andreas Färber

Acked-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 MAINTAINERS       |  1 +
 tests/Makefile    |  3 +++
 tests/nvme-test.c | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)
 create mode 100644 tests/nvme-test.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 7d17f83..4d8eefc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -648,6 +648,7 @@ nvme
 M: Keith Busch <keith.busch@intel.com>
 S: Supported
 F: hw/block/nvme*
+F: tests/nvme-test.c
 
 Xilinx EDK
 M: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
diff --git a/tests/Makefile b/tests/Makefile
index 0e3eb44..01a3463 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
new file mode 100644
index 0000000..85768e8
--- /dev/null
+++ b/tests/nvme-test.c
@@ -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;
+}
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 08/16] tests: Add virtio-9p qtest
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (6 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 07/16] tests: Add nvme qtest Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 09/16] tests: Add pvpanic qtest Andreas Färber
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Aneesh Kumar K.V

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

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 MAINTAINERS            |  1 +
 tests/Makefile         |  6 ++++++
 tests/virtio-9p-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 tests/virtio-9p-test.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4d8eefc..4923b0f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -623,6 +623,7 @@ M: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
 S: Supported
 F: hw/9pfs/
 F: fsdev/
+F: tests/virtio-9p-test.c
 T: git git://github.com/kvaneesh/QEMU.git
 
 virtio-blk
diff --git a/tests/Makefile b/tests/Makefile
index 01a3463..843429b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
new file mode 100644
index 0000000..1fae477
--- /dev/null
+++ b/tests/virtio-9p-test.c
@@ -0,0 +1,46 @@
+/*
+ * QTest testcase for VirtIO 9P
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include "libqtest.h"
+#include "qemu-common.h"
+#include "qemu/osdep.h"
+
+/* Tests only initialization so far. TODO: Replace with functional tests */
+static void pci_nop(void)
+{
+}
+
+static char test_share[] = "/tmp/qtest.XXXXXX";
+
+int main(int argc, char **argv)
+{
+    char *args;
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/virtio/9p/pci/nop", pci_nop);
+
+    g_assert(mkdtemp(test_share));
+
+    args = g_strdup_printf("-fsdev local,id=fsdev0,security_model=none,path=%s "
+                           "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=qtest",
+                           test_share);
+    qtest_start(args);
+    g_free(args);
+
+    ret = g_test_run();
+
+    qtest_end();
+    rmdir(test_share);
+
+    return ret;
+}
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 09/16] tests: Add pvpanic qtest
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (7 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 08/16] tests: Add virtio-9p qtest Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 10/16] qtest: Factor out qtest_qmp_receive() Andreas Färber
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile       |  3 +++
 tests/pvpanic-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 tests/pvpanic-test.c

diff --git a/tests/Makefile b/tests/Makefile
index 843429b..e4f7c07 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
diff --git a/tests/pvpanic-test.c b/tests/pvpanic-test.c
new file mode 100644
index 0000000..7bb4d06
--- /dev/null
+++ b/tests/pvpanic-test.c
@@ -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;
+}
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 10/16] qtest: Factor out qtest_qmp_receive()
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (8 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 09/16] tests: Add pvpanic qtest Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 11/16] pvpanic-test: Assert pause event Andreas Färber
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/libqtest.c | 15 ++++++++++-----
 tests/libqtest.h | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index d9e3a33..8155695 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -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;
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 8268c09..8f323c7 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -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.
  *
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 11/16] pvpanic-test: Assert pause event
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (9 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 10/16] qtest: Factor out qtest_qmp_receive() Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 12/16] tests: Add i82801b11 qtest Andreas Färber
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/pvpanic-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tests/pvpanic-test.c b/tests/pvpanic-test.c
index 7bb4d06..a7ad6b3 100644
--- a/tests/pvpanic-test.c
+++ b/tests/pvpanic-test.c
@@ -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)
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 12/16] tests: Add i82801b11 qtest
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (10 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 11/16] pvpanic-test: Assert pause event Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius Andreas Färber
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/Makefile         |  3 +++
 tests/i82801b11-test.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 tests/i82801b11-test.c

diff --git a/tests/Makefile b/tests/Makefile
index e4f7c07..6086f68 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
diff --git a/tests/i82801b11-test.c b/tests/i82801b11-test.c
new file mode 100644
index 0000000..78d9ce0
--- /dev/null
+++ b/tests/i82801b11-test.c
@@ -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;
+}
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (11 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 12/16] tests: Add i82801b11 qtest Andreas Färber
@ 2014-03-31 21:10 ` Andreas Färber
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing Andreas Färber
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber

From: Paolo Bonzini <pbonzini@redhat.com>

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}

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/misc/tmp105.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c
index 155e03d..63aa3d6 100644
--- a/hw/misc/tmp105.c
+++ b/hw/misc/tmp105.c
@@ -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);
 }
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (12 preceding siblings ...)
  2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius Andreas Färber
@ 2014-03-31 21:11 ` Andreas Färber
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 15/16] tmp105-test: Add a second sensor and test that one Andreas Färber
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber

From: Paolo Bonzini <pbonzini@redhat.com>

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/tmp105-test.c | 54 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c
index 0834219..20a1894 100644
--- a/tests/tmp105-test.c
+++ b/tests/tmp105-test.c
@@ -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;
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 15/16] tmp105-test: Add a second sensor and test that one
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (13 preceding siblings ...)
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing Andreas Färber
@ 2014-03-31 21:11 ` Andreas Färber
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 16/16] tmp105-test: Test QOM property and precision Andreas Färber
  2014-04-01 16:09 ` [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Peter Maydell
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber

From: Paolo Bonzini <pbonzini@redhat.com>

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/tmp105-test.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c
index 20a1894..4e640b4 100644
--- a/tests/tmp105-test.c
+++ b/tests/tmp105-test.c
@@ -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);
 
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PULL for-2.0 16/16] tmp105-test: Test QOM property and precision
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (14 preceding siblings ...)
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 15/16] tmp105-test: Add a second sensor and test that one Andreas Färber
@ 2014-03-31 21:11 ` Andreas Färber
  2014-04-01 16:09 ` [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Peter Maydell
  16 siblings, 0 replies; 18+ messages in thread
From: Andreas Färber @ 2014-03-31 21:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber

From: Paolo Bonzini <pbonzini@redhat.com>

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/tmp105-test.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 3 deletions(-)

diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c
index 4e640b4..15ddaf3 100644
--- a/tests/tmp105-test.c
+++ b/tests/tmp105-test.c
@@ -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);
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31
  2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
                   ` (15 preceding siblings ...)
  2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 16/16] tmp105-test: Test QOM property and precision Andreas Färber
@ 2014-04-01 16:09 ` Peter Maydell
  16 siblings, 0 replies; 18+ messages in thread
From: Peter Maydell @ 2014-04-01 16:09 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Anthony Liguori, Stefan Weil, QEMU Developers, Keith Busch,
	Stefan Hajnoczi, Paolo Bonzini

On 31 March 2014 22:10, Andreas Färber <afaerber@suse.de> wrote:
> Hello Peter,
>
> This is my QOM (devices) patch queue. Please pull.
>
> Regards,
> Andreas
>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: Anthony Liguori <anthony@codemonkey.ws>
>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: Stefan Weil <sw@weilnetz.de>
> Cc: Keith Busch <keith.busch@intel.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
>
> 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

Applied, thanks.

-- PMM

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-04-01 16:10 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-31 21:10 [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 01/16] Revert "qtest: Fix crash if SIGABRT during qtest_init()" Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 02/16] qtest: Keep list of qtest instances for SIGABRT handler Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 03/16] tests: Remove unsupported tests for MinGW Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 04/16] tests: Skip POSIX-only tests on Windows Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 05/16] tests: Correctly skip qtest on non-POSIX hosts Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 06/16] nvme: Permit zero-length block devices Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 07/16] tests: Add nvme qtest Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 08/16] tests: Add virtio-9p qtest Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 09/16] tests: Add pvpanic qtest Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 10/16] qtest: Factor out qtest_qmp_receive() Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 11/16] pvpanic-test: Assert pause event Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 12/16] tests: Add i82801b11 qtest Andreas Färber
2014-03-31 21:10 ` [Qemu-devel] [PULL for-2.0 13/16] tmp105: Read temperature in milli-celsius Andreas Färber
2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 14/16] tmp105-test: Wrap simple building blocks for testing Andreas Färber
2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 15/16] tmp105-test: Add a second sensor and test that one Andreas Färber
2014-03-31 21:11 ` [Qemu-devel] [PULL for-2.0 16/16] tmp105-test: Test QOM property and precision Andreas Färber
2014-04-01 16:09 ` [Qemu-devel] [PULL for-2.0 00/16] QOM devices patch queue 2014-03-31 Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.