[PULL 52/83] tests/qtest: add PCA9554 register access tests
Cédric Le Goater <[email protected]>
| Newsgroups | org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Emmanuel Blot <[email protected]> Add a qtest for the PCA9554 8-bit I/O port expander exercising the basic register access: power-on reset defaults and read/write of the OUTPUT, CONFIG and POLARITY registers. Signed-off-by: Emmanuel Blot <[email protected]> Reviewed-by: Glenn Miles <[email protected]> Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]> --- tests/qtest/pca9554-test.c | 41 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 42 insertions(+) create mode 100644 tests/qtest/pca9554-test.c diff --git a/tests/qtest/pca9554-test.c b/tests/qtest/pca9554-test.c new file mode 100644 index 000000000000..a5f213a59cc6 --- /dev/null +++ b/tests/qtest/pca9554-test.c @@ -0,0 +1,41 @@ +/* + * QTest testcase for the PCA9554/PCA9536 I/O port expanders + * + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/gpio/pca9554_regs.h" +#include "libqos/i2c.h" +#include "libqos/qgraph.h" + +#define PCA9554_TEST_ADDR 0x20 + +/* Verify power-on reset defaults match the PCA9554 datasheet. */ +static void test_reset_defaults(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *dev = (QI2CDevice *)obj; + + /* All pins are inputs, pulled high, with no polarity inversion. */ + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0xFF); + g_assert_cmphex(i2c_get8(dev, PCA9554_OUTPUT), ==, 0xFF); + g_assert_cmphex(i2c_get8(dev, PCA9554_POLARITY), ==, 0x00); + g_assert_cmphex(i2c_get8(dev, PCA9554_CONFIG), ==, 0xFF); +} + +static void pca9554_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "address=0x20" + }; + add_qi2c_address(&opts, &(QI2CAddress) { PCA9554_TEST_ADDR }); + + qos_node_create_driver("pca9554", i2c_device_create); + qos_node_consumes("pca9554", "i2c-bus", &opts); + + qos_add_test("reset-defaults", "pca9554", test_reset_defaults, NULL); +} + +libqos_init(pca9554_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index e92130bd04dd..4d81857174ae 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -319,6 +319,7 @@ qos_test_ss.add( 'tulip-test.c', 'nvme-test.c', 'pca9552-test.c', + 'pca9554-test.c', 'pca9555-test.c', 'pci-test.c', 'pcnet-test.c', -- 2.55.0