mirror of https://github.com/xemu-project/xemu.git
tests: convert OMAP i2c tests to qgraph
This way, pca9952-test and tmp105-test will run for every machine that exposes an i2c-bus. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
751a7a5d00
commit
93c3fe2a34
|
@ -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/prom-env-test$(EXESUF)
|
||||||
check-qtest-sparc64-y += tests/boot-serial-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/ds1338-test$(EXESUF)
|
||||||
check-qtest-arm-y += tests/microbit-test$(EXESUF)
|
check-qtest-arm-y += tests/microbit-test$(EXESUF)
|
||||||
check-qtest-arm-y += tests/m25p80-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 = $(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/malloc-pc.o tests/libqos/libqos-pc.o
|
||||||
libqos-pc-obj-y += tests/libqos/ahci.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-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
|
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 += $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
|
||||||
qos-test-obj-y += tests/libqos/e1000e.o
|
qos-test-obj-y += tests/libqos/e1000e.o
|
||||||
qos-test-obj-y += $(libqos-imx-obj-y)
|
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/sdhci.o
|
||||||
qos-test-obj-y += tests/libqos/tpci200.o
|
qos-test-obj-y += tests/libqos/tpci200.o
|
||||||
qos-test-obj-y += tests/libqos/virtio.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/megasas-test.o
|
||||||
qos-test-obj-y += tests/ne2000-test.o
|
qos-test-obj-y += tests/ne2000-test.o
|
||||||
qos-test-obj-y += tests/nvme-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/pci-test.o
|
||||||
qos-test-obj-y += tests/pcnet-test.o
|
qos-test-obj-y += tests/pcnet-test.o
|
||||||
qos-test-obj-y += tests/sdhci-test.o
|
qos-test-obj-y += tests/sdhci-test.o
|
||||||
qos-test-obj-y += tests/spapr-phb-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-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-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y)
|
||||||
qos-test-obj-y += tests/virtio-test.o
|
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/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
|
||||||
tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y)
|
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/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/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
|
||||||
tests/microbit-test$(EXESUF): tests/microbit-test.o
|
tests/microbit-test$(EXESUF): tests/microbit-test.o
|
||||||
tests/m25p80-test$(EXESUF): tests/m25p80-test.o
|
tests/m25p80-test$(EXESUF): tests/m25p80-test.o
|
||||||
|
|
|
@ -187,25 +187,6 @@ void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr)
|
||||||
s->parent.qts = qts;
|
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)
|
static void omap_i2c_register_nodes(void)
|
||||||
{
|
{
|
||||||
qos_node_create_driver("omap_i2c", NULL);
|
qos_node_create_driver("omap_i2c", NULL);
|
||||||
|
|
|
@ -38,8 +38,6 @@ struct QI2CDevice {
|
||||||
I2CAdapter *bus;
|
I2CAdapter *bus;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define OMAP2_I2C_1_BASE 0x48070000
|
|
||||||
|
|
||||||
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
|
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
|
||||||
|
|
||||||
void i2c_send(I2CAdapter *i2c, uint8_t addr,
|
void i2c_send(I2CAdapter *i2c, uint8_t addr,
|
||||||
|
@ -67,8 +65,6 @@ typedef struct OMAPI2C {
|
||||||
} OMAPI2C;
|
} OMAPI2C;
|
||||||
|
|
||||||
void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
|
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 */
|
/* i2c-imx.c */
|
||||||
typedef struct IMXI2C {
|
typedef struct IMXI2C {
|
||||||
|
|
|
@ -10,23 +10,26 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "libqtest.h"
|
||||||
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/i2c.h"
|
#include "libqos/i2c.h"
|
||||||
#include "hw/misc/pca9552_regs.h"
|
#include "hw/misc/pca9552_regs.h"
|
||||||
|
|
||||||
#define PCA9552_TEST_ID "pca9552-test"
|
#define PCA9552_TEST_ID "pca9552-test"
|
||||||
#define PCA9552_TEST_ADDR 0x60
|
#define PCA9552_TEST_ADDR 0x60
|
||||||
|
|
||||||
static I2CAdapter *i2c;
|
static void pca9552_init(QI2CDevice *i2cdev)
|
||||||
|
|
||||||
static void pca9552_init(I2CAdapter *i2c)
|
|
||||||
{
|
{
|
||||||
|
I2CAdapter *i2c = i2cdev->bus;
|
||||||
|
|
||||||
/* Switch on LEDs 0 and 12 */
|
/* Switch on LEDs 0 and 12 */
|
||||||
i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
|
i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
|
||||||
i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 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 resp;
|
||||||
uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
|
uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
|
||||||
|
|
||||||
|
@ -51,8 +54,10 @@ static void receive_autoinc(void)
|
||||||
g_assert_cmphex(resp, ==, 0x54);
|
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;
|
uint8_t value;
|
||||||
|
|
||||||
value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
|
value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
|
||||||
|
@ -76,27 +81,16 @@ static void send_and_receive(void)
|
||||||
g_assert_cmphex(value, ==, 0x10);
|
g_assert_cmphex(value, ==, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
static void pca9552_register_nodes(void)
|
||||||
{
|
{
|
||||||
QTestState *s = NULL;
|
QOSGraphEdgeOptions opts = {
|
||||||
int ret;
|
.extra_device_opts = "address=0x60"
|
||||||
|
};
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
qos_node_create_driver("pca9552", i2c_device_create);
|
||||||
|
qos_node_consumes("pca9552", "i2c-bus", &opts);
|
||||||
|
|
||||||
s = qtest_start("-machine n800 "
|
qos_add_test("tx-rx", "pca9552", send_and_receive, NULL);
|
||||||
"-device pca9552,bus=i2c-bus.0,id=" PCA9552_TEST_ID
|
qos_add_test("rx-autoinc", "pca9552", receive_autoinc, NULL);
|
||||||
",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();
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
qtest_quit(s);
|
|
||||||
}
|
|
||||||
omap_i2c_free(i2c);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
libqos_init(pca9552_register_nodes);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "libqtest.h"
|
||||||
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/i2c.h"
|
#include "libqos/i2c.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "hw/misc/tmp105_regs.h"
|
#include "hw/misc/tmp105_regs.h"
|
||||||
|
@ -17,8 +18,6 @@
|
||||||
#define TMP105_TEST_ID "tmp105-test"
|
#define TMP105_TEST_ID "tmp105-test"
|
||||||
#define TMP105_TEST_ADDR 0x49
|
#define TMP105_TEST_ADDR 0x49
|
||||||
|
|
||||||
static I2CAdapter *i2c;
|
|
||||||
|
|
||||||
static int qmp_tmp105_get_temperature(const char *id)
|
static int qmp_tmp105_get_temperature(const char *id)
|
||||||
{
|
{
|
||||||
QDict *response;
|
QDict *response;
|
||||||
|
@ -43,9 +42,11 @@ static void qmp_tmp105_set_temperature(const char *id, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TMP105_PRECISION (1000/16)
|
#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;
|
uint16_t value;
|
||||||
|
QI2CDevice *i2cdev = (QI2CDevice *)obj;
|
||||||
|
I2CAdapter *i2c = i2cdev->bus;
|
||||||
|
|
||||||
value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
|
value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
|
||||||
g_assert_cmpuint(value, ==, 0);
|
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);
|
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;
|
QOSGraphEdgeOptions opts = {
|
||||||
int ret;
|
.extra_device_opts = "id=" TMP105_TEST_ID ",address=0x49"
|
||||||
|
};
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
qos_node_create_driver("tmp105", i2c_device_create);
|
||||||
|
qos_node_consumes("tmp105", "i2c-bus", &opts);
|
||||||
|
|
||||||
s = qtest_start("-machine n800 "
|
qos_add_test("tx-rx", "tmp105", send_and_receive, NULL);
|
||||||
"-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
|
|
||||||
",address=0x49");
|
|
||||||
i2c = omap_i2c_create(s, OMAP2_I2C_1_BASE);
|
|
||||||
|
|
||||||
qtest_add_func("/tmp105/tx-rx", send_and_receive);
|
|
||||||
|
|
||||||
ret = g_test_run();
|
|
||||||
|
|
||||||
qtest_quit(s);
|
|
||||||
omap_i2c_free(i2c);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
libqos_init(tmp105_register_nodes);
|
||||||
|
|
Loading…
Reference in New Issue