@samitouri / QOSamiQemu / commits / ab707882d8

tests/qtest: add PCA9554 register access tests

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 <emmanuel.blot@free.fr> Reviewed-by: Glenn Miles <milesg@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260709-catalina-upgrade-v1-19-82a63fead90c@free.fr Signed-off-by: Cédric Le Goater <clg@redhat.com>

Emmanuel Blot committed Jul 9, 2026 at 17:23 UTC ab707882d83b013521ab15d266ab41dbb6c9efbc
2 files changed +42
tests/qtest/meson.build
+1
@@ -319,6 +319,7 @@ qos_test_ss.add(
319 'tulip-test.c',
320 'nvme-test.c',
321 'pca9552-test.c',
322 + 'pca9554-test.c',
323 'pca9555-test.c',
324 'pci-test.c',
325 'pcnet-test.c',
tests/qtest/pca9554-test.c new
+41
@@ -0,0 +1,41 @@
1 +/*
2 + * QTest testcase for the PCA9554/PCA9536 I/O port expanders
3 + *
4 + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com)
5 + *
6 + * SPDX-License-Identifier: GPL-2.0-or-later
7 + */
8 +
9 +#include "qemu/osdep.h"
10 +#include "hw/gpio/pca9554_regs.h"
11 +#include "libqos/i2c.h"
12 +#include "libqos/qgraph.h"
13 +
14 +#define PCA9554_TEST_ADDR 0x20
15 +
16 +/* Verify power-on reset defaults match the PCA9554 datasheet. */
17 +static void test_reset_defaults(void *obj, void *data, QGuestAllocator *alloc)
18 +{
19 + QI2CDevice *dev = (QI2CDevice *)obj;
20 +
21 + /* All pins are inputs, pulled high, with no polarity inversion. */
22 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0xFF);
23 + g_assert_cmphex(i2c_get8(dev, PCA9554_OUTPUT), ==, 0xFF);
24 + g_assert_cmphex(i2c_get8(dev, PCA9554_POLARITY), ==, 0x00);
25 + g_assert_cmphex(i2c_get8(dev, PCA9554_CONFIG), ==, 0xFF);
26 +}
27 +
28 +static void pca9554_register_nodes(void)
29 +{
30 + QOSGraphEdgeOptions opts = {
31 + .extra_device_opts = "address=0x20"
32 + };
33 + add_qi2c_address(&opts, &(QI2CAddress) { PCA9554_TEST_ADDR });
34 +
35 + qos_node_create_driver("pca9554", i2c_device_create);
36 + qos_node_consumes("pca9554", "i2c-bus", &opts);
37 +
38 + qos_add_test("reset-defaults", "pca9554", test_reset_defaults, NULL);
39 +}
40 +
41 +libqos_init(pca9554_register_nodes);