aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Makefile.include9
-rw-r--r--tests/libqos/i2c-omap.c19
-rw-r--r--tests/libqos/i2c.h4
-rw-r--r--tests/pca9552-test.c44
-rw-r--r--tests/tmp105-test.c32
5 files changed, 34 insertions, 74 deletions
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 506181e21a..0f1ddde84a 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -255,8 +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/tmp105-test$(EXESUF)
-check-qtest-arm-y += tests/pca9552-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)
@@ -686,7 +684,6 @@ 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-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.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
@@ -695,7 +692,7 @@ 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 += $(libqos-omap-obj-y)
+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
qos-test-obj-y += tests/libqos/virtio.o
@@ -731,10 +728,12 @@ qos-test-obj-y += tests/ipoctal232-test.o
qos-test-obj-y += tests/megasas-test.o
qos-test-obj-y += tests/ne2000-test.o
qos-test-obj-y += tests/nvme-test.o
+qos-test-obj-y += tests/pca9552-test.o
qos-test-obj-y += tests/pci-test.o
qos-test-obj-y += tests/pcnet-test.o
qos-test-obj-y += tests/sdhci-test.o
qos-test-obj-y += tests/spapr-phb-test.o
+qos-test-obj-y += tests/tmp105-test.o
qos-test-obj-y += tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y)
qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y)
qos-test-obj-y += tests/virtio-test.o
@@ -772,8 +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/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
-tests/pca9552-test$(EXESUF): tests/pca9552-test.o $(libqos-omap-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
diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c
index f94956488c..9ae8214fa8 100644
--- a/tests/libqos/i2c-omap.c
+++ b/tests/libqos/i2c-omap.c
@@ -187,25 +187,6 @@ void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr)
s->parent.qts = qts;
}
-I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr)
-{
- OMAPI2C *s = g_malloc0(sizeof(*s));
-
- omap_i2c_init(s, qts, addr);
- return &s->parent;
-}
-
-void omap_i2c_free(I2CAdapter *i2c)
-{
- OMAPI2C *s;
-
- if (!i2c) {
- return;
- }
- s = container_of(i2c, OMAPI2C, parent);
- g_free(s);
-}
-
static void omap_i2c_register_nodes(void)
{
qos_node_create_driver("omap_i2c", NULL);
diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h
index 0107cfc633..66b0e0d06e 100644
--- a/tests/libqos/i2c.h
+++ b/tests/libqos/i2c.h
@@ -38,8 +38,6 @@ struct QI2CDevice {
I2CAdapter *bus;
};
-#define OMAP2_I2C_1_BASE 0x48070000
-
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
void i2c_send(I2CAdapter *i2c, uint8_t addr,
@@ -67,8 +65,6 @@ typedef struct OMAPI2C {
} OMAPI2C;
void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
-I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr);
-void omap_i2c_free(I2CAdapter *i2c);
/* i2c-imx.c */
typedef struct IMXI2C {
diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c
index f9509324e2..0598d0b1eb 100644
--- a/tests/pca9552-test.c
+++ b/tests/pca9552-test.c
@@ -10,23 +10,26 @@
#include "qemu/osdep.h"
#include "libqtest.h"
+#include "libqos/qgraph.h"
#include "libqos/i2c.h"
#include "hw/misc/pca9552_regs.h"
#define PCA9552_TEST_ID "pca9552-test"
#define PCA9552_TEST_ADDR 0x60
-static I2CAdapter *i2c;
-
-static void pca9552_init(I2CAdapter *i2c)
+static void pca9552_init(QI2CDevice *i2cdev)
{
+ I2CAdapter *i2c = i2cdev->bus;
+
/* Switch on LEDs 0 and 12 */
i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
}
-static void receive_autoinc(void)
+static void receive_autoinc(void *obj, void *data, QGuestAllocator *alloc)
{
+ QI2CDevice *i2cdev = (QI2CDevice *)obj;
+ I2CAdapter *i2c = i2cdev->bus;
uint8_t resp;
uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
@@ -51,8 +54,10 @@ static void receive_autoinc(void)
g_assert_cmphex(resp, ==, 0x54);
}
-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 value;
value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
@@ -76,27 +81,16 @@ static void send_and_receive(void)
g_assert_cmphex(value, ==, 0x10);
}
-int main(int argc, char **argv)
+static void pca9552_register_nodes(void)
{
- QTestState *s = NULL;
- int ret;
-
- g_test_init(&argc, &argv, NULL);
-
- s = qtest_start("-machine n800 "
- "-device pca9552,bus=i2c-bus.0,id=" PCA9552_TEST_ID
- ",address=0x60");
- i2c = omap_i2c_create(s, OMAP2_I2C_1_BASE);
-
- qtest_add_func("/pca9552/tx-rx", send_and_receive);
- qtest_add_func("/pca9552/rx-autoinc", receive_autoinc);
-
- ret = g_test_run();
+ QOSGraphEdgeOptions opts = {
+ .extra_device_opts = "address=0x60"
+ };
- if (s) {
- qtest_quit(s);
- }
- omap_i2c_free(i2c);
+ qos_node_create_driver("pca9552", i2c_device_create);
+ qos_node_consumes("pca9552", "i2c-bus", &opts);
- return ret;
+ qos_add_test("tx-rx", "pca9552", send_and_receive, NULL);
+ qos_add_test("rx-autoinc", "pca9552", receive_autoinc, NULL);
}
+libqos_init(pca9552_register_nodes);
diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c
index 25ea05f5fd..4031876387 100644
--- a/tests/tmp105-test.c
+++ b/tests/tmp105-test.c
@@ -10,6 +10,7 @@
#include "qemu/osdep.h"
#include "libqtest.h"
+#include "libqos/qgraph.h"
#include "libqos/i2c.h"
#include "qapi/qmp/qdict.h"
#include "hw/misc/tmp105_regs.h"
@@ -17,8 +18,6 @@
#define TMP105_TEST_ID "tmp105-test"
#define TMP105_TEST_ADDR 0x49
-static I2CAdapter *i2c;
-
static int qmp_tmp105_get_temperature(const char *id)
{
QDict *response;
@@ -43,9 +42,11 @@ static void qmp_tmp105_set_temperature(const char *id, int value)
}
#define TMP105_PRECISION (1000/16)
-static void send_and_receive(void)
+static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
{
uint16_t value;
+ QI2CDevice *i2cdev = (QI2CDevice *)obj;
+ I2CAdapter *i2c = i2cdev->bus;
value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
g_assert_cmpuint(value, ==, 0);
@@ -105,24 +106,15 @@ static void send_and_receive(void)
g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH), ==, 0x4231);
}
-int main(int argc, char **argv)
+static void tmp105_register_nodes(void)
{
- QTestState *s = NULL;
- int ret;
-
- g_test_init(&argc, &argv, NULL);
-
- s = qtest_start("-machine n800 "
- "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
- ",address=0x49");
- i2c = omap_i2c_create(s, OMAP2_I2C_1_BASE);
+ QOSGraphEdgeOptions opts = {
+ .extra_device_opts = "id=" TMP105_TEST_ID ",address=0x49"
+ };
- qtest_add_func("/tmp105/tx-rx", send_and_receive);
+ qos_node_create_driver("tmp105", i2c_device_create);
+ qos_node_consumes("tmp105", "i2c-bus", &opts);
- ret = g_test_run();
-
- qtest_quit(s);
- omap_i2c_free(i2c);
-
- return ret;
+ qos_add_test("tx-rx", "tmp105", send_and_receive, NULL);
}
+libqos_init(tmp105_register_nodes);