qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 20/24] tests: convert ds1338-test to qtest
Date: Mon,  3 Jun 2019 19:10:39 +0200	[thread overview]
Message-ID: <1559581843-3968-21-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1559581843-3968-1-git-send-email-pbonzini@redhat.com>

This way, ds1338-test will run for every machine that exposes
an i2c-bus.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/Makefile.include |  9 ++++-----
 tests/ds1338-test.c    | 37 +++++++++++++------------------------
 tests/libqos/i2c-imx.c | 19 -------------------
 tests/libqos/i2c.h     |  2 --
 4 files changed, 17 insertions(+), 50 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 0f1ddde..46a36c2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -255,7 +255,6 @@ check-qtest-sparc64-$(CONFIG_ISA_TESTDEV) = tests/endianness-test$(EXESUF)
 check-qtest-sparc64-y += tests/prom-env-test$(EXESUF)
 check-qtest-sparc64-y += tests/boot-serial-test$(EXESUF)
 
-check-qtest-arm-y += tests/ds1338-test$(EXESUF)
 check-qtest-arm-y += tests/microbit-test$(EXESUF)
 check-qtest-arm-y += tests/m25p80-test$(EXESUF)
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
@@ -676,7 +675,7 @@ libqgraph-obj-y = tests/libqos/qgraph.o
 
 libqos-obj-y = $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg.o
 libqos-obj-y += tests/libqos/malloc.o
-libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
+libqos-obj-y += tests/libqos/libqos.o
 libqos-spapr-obj-y = $(libqos-obj-y) tests/libqos/malloc-spapr.o
 libqos-spapr-obj-y += tests/libqos/libqos-spapr.o
 libqos-spapr-obj-y += tests/libqos/rtas.o
@@ -684,14 +683,14 @@ libqos-spapr-obj-y += tests/libqos/pci-spapr.o
 libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
 libqos-pc-obj-y += tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o
 libqos-pc-obj-y += tests/libqos/ahci.o
-libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o
 libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
 
 # Devices
 qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y)
 qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 qos-test-obj-y += tests/libqos/e1000e.o
-qos-test-obj-y += $(libqos-imx-obj-y)
+qos-test-obj-y += tests/libqos/i2c.o
+qos-test-obj-y += tests/libqos/i2c-imx.o
 qos-test-obj-y += tests/libqos/i2c-omap.o
 qos-test-obj-y += tests/libqos/sdhci.o
 qos-test-obj-y += tests/libqos/tpci200.o
@@ -720,6 +719,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o
 
 # Tests
 qos-test-obj-y += tests/ac97-test.o
+qos-test-obj-y += tests/ds1338-test.o
 qos-test-obj-y += tests/e1000-test.o
 qos-test-obj-y += tests/e1000e-test.o
 qos-test-obj-y += tests/eepro100-test.o
@@ -771,7 +771,6 @@ tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y)
 tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
 	tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y)
 tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y)
-tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
 tests/microbit-test$(EXESUF): tests/microbit-test.o
 tests/m25p80-test$(EXESUF): tests/m25p80-test.o
 tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c
index bd72a15..fd8fbad 100644
--- a/tests/ds1338-test.c
+++ b/tests/ds1338-test.c
@@ -21,25 +21,23 @@
 #include "libqtest.h"
 #include "libqos/i2c.h"
 
-#define IMX25_I2C_0_BASE 0x43F80000
-
 #define DS1338_ADDR 0x68
 
-static I2CAdapter *i2c;
-static uint8_t addr;
-
 static inline uint8_t bcd2bin(uint8_t x)
 {
     return ((x) & 0x0f) + ((x) >> 4) * 10;
 }
 
-static void send_and_receive(void)
+static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
 {
+    QI2CDevice *i2cdev = (QI2CDevice *)obj;
+    I2CAdapter *i2c = i2cdev->bus;
+
     uint8_t resp[7];
     time_t now = time(NULL);
     struct tm *tm_ptr = gmtime(&now);
 
-    i2c_read_block(i2c, addr, 0, resp, sizeof(resp));
+    i2c_read_block(i2c, DS1338_ADDR, 0, resp, sizeof(resp));
 
     /* check retrieved time againt local time */
     g_assert_cmpuint(bcd2bin(resp[4]), == , tm_ptr->tm_mday);
@@ -47,23 +45,14 @@ static void send_and_receive(void)
     g_assert_cmpuint(2000 + bcd2bin(resp[6]), == , 1900 + tm_ptr->tm_year);
 }
 
-int main(int argc, char **argv)
+static void ds1338_register_nodes(void)
 {
-    QTestState *s = NULL;
-    int ret;
-
-    g_test_init(&argc, &argv, NULL);
-
-    s = qtest_start("-display none -machine imx25-pdk -device ds1338,address=0x68");
-    i2c = imx_i2c_create(s, IMX25_I2C_0_BASE);
-    addr = DS1338_ADDR;
-
-    qtest_add_func("/ds1338/tx-rx", send_and_receive);
-
-    ret = g_test_run();
-
-    qtest_quit(s);
-    g_free(i2c);
+    QOSGraphEdgeOptions opts = {
+        .extra_device_opts = "address=0x68"
+    };
 
-    return ret;
+    qos_node_create_driver("ds1338", i2c_device_create);
+    qos_node_consumes("ds1338", "i2c-bus", &opts);
+    qos_add_test("tx-rx", "ds1338", send_and_receive, NULL);
 }
+libqos_init(ds1338_register_nodes);
diff --git a/tests/libqos/i2c-imx.c b/tests/libqos/i2c-imx.c
index 86d84a7..f33ece5 100644
--- a/tests/libqos/i2c-imx.c
+++ b/tests/libqos/i2c-imx.c
@@ -207,25 +207,6 @@ void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr)
     s->parent.qts = qts;
 }
 
-I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr)
-{
-    IMXI2C *s = g_malloc0(sizeof(*s));
-
-    imx_i2c_init(s, qts, addr);
-    return &s->parent;
-}
-
-void imx_i2c_free(I2CAdapter *i2c)
-{
-    IMXI2C *s;
-
-    if (!i2c) {
-        return;
-    }
-    s = container_of(i2c, IMXI2C, parent);
-    g_free(s);
-}
-
 static void imx_i2c_register_nodes(void)
 {
     qos_node_create_driver("imx.i2c", NULL);
diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h
index 66b0e0d..2c8cc3e 100644
--- a/tests/libqos/i2c.h
+++ b/tests/libqos/i2c.h
@@ -75,7 +75,5 @@ typedef struct IMXI2C {
 } IMXI2C;
 
 void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
-I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr);
-void imx_i2c_free(I2CAdapter *i2c);
 
 #endif
-- 
1.8.3.1




  parent reply	other threads:[~2019-06-03 17:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03 17:10 [Qemu-devel] [PULL 00/24] Misc patches for 2019-06-03 Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 01/24] test-thread-pool: be more reliable Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 02/24] vl: make -accel help to list enabled accelerators only Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 03/24] checkpatch: allow SPDX-License-Identifier Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 04/24] memory: Remove memory_region_get_dirty() Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 05/24] i386: Enable IA32_MISC_ENABLE MWAIT bit when exposing mwait/monitor Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 06/24] edu: mmio: allow 64-bit access Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 07/24] edu: mmio: allow 64-bit access in read dispatch Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 08/24] edu: uses uint64_t in dma operation Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 09/24] qgraph: allow extra_device_opts on contains nodes Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 10/24] qgraph: fix qos_node_contains with options Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 11/24] libqos: move common i2c code to libqos Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 12/24] libqos: fix omap-i2c receiving more than 4 bytes Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 13/24] pca9552-test: do not rely on state across tests Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 14/24] imx25-pdk: create ds1338 for qtest inside the test Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 15/24] libqos: split I2CAdapter initialization and allocation Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 16/24] libqos: convert I2C to qgraph Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 17/24] libqos: add ARM n800 machine object Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 18/24] libqos: add ARM imx25-pdk " Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 19/24] tests: convert OMAP i2c tests to qgraph Paolo Bonzini
2019-06-03 17:10 ` Paolo Bonzini [this message]
2019-06-03 17:10 ` [Qemu-devel] [PULL 21/24] libqos: i2c: move address into QI2CDevice Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 22/24] ci: store Patchew configuration in the tree Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 23/24] configure: remove tpm_passthrough & tpm_emulator Paolo Bonzini
2019-06-03 17:10 ` [Qemu-devel] [PULL 24/24] q35: Revert to kernel irqchip Paolo Bonzini
2019-06-05  9:14   ` Greg Kurz
2019-06-03 18:18 ` [Qemu-devel] [PULL 00/24] Misc patches for 2019-06-03 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1559581843-3968-21-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).