Reviewed-by: Glenn Miles <[email protected]>

Thanks,

Glenn

On Thu, 2026-07-09 at 17:23 +0200, Emmanuel Blot wrote:
> 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]>
> ---
>  tests/qtest/meson.build    |  1 +
>  tests/qtest/pca9554-test.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+)
> 
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 2c283708a5..2f35bde630 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -318,6 +318,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',
> diff --git a/tests/qtest/pca9554-test.c b/tests/qtest/pca9554-test.c
> new file mode 100644
> index 0000000000..a5f213a59c
> --- /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);
> 


Reply via email to