@samitouri / QOSamiQemu / commits / 71aa15068c

tests/qtest: add PCA9555 register access tests

Introduce a qtest for the PCA9555 16-bit I/O port expander. This first set covers the power-on reset defaults and the read/write behaviour of the OUTPUT, CONFIG and POLARITY register pairs. 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-10-814575bc076b@free.fr Signed-off-by: Cédric Le Goater <clg@redhat.com>

Emmanuel Blot committed Jul 9, 2026 at 17:23 UTC 71aa15068ccaa8b330f4f324c33315557d54742c
2 files changed +45
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 + 'pca9555-test.c',
323 'pci-test.c',
324 'pcnet-test.c',
325 'rs5c372-test.c',
tests/qtest/pca9555-test.c new
+44
@@ -0,0 +1,44 @@
1 +/*
2 + * QTest testcase for the PCA9555 16-bit I/O port expander
3 + *
4 + * Copyright (c) Meta Platforms, Inc. and affiliates.
5 + *
6 + * SPDX-License-Identifier: GPL-2.0-or-later
7 + */
8 +
9 +#include "qemu/osdep.h"
10 +#include "hw/gpio/pca9552_regs.h"
11 +#include "libqos/i2c.h"
12 +#include "libqos/qgraph.h"
13 +
14 +#define PCA9555_TEST_ADDR 0x20
15 +
16 +/* Verify power-on reset defaults match the PCA9555 datasheet. */
17 +static void test_reset_defaults(void *obj, void *data, QGuestAllocator *alloc)
18 +{
19 + QI2CDevice *dev = (QI2CDevice *)obj;
20 +
21 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0xFF);
22 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT1), ==, 0xFF);
23 + g_assert_cmphex(i2c_get8(dev, PCA9535_OUTPUT0), ==, 0xFF);
24 + g_assert_cmphex(i2c_get8(dev, PCA9535_OUTPUT1), ==, 0xFF);
25 + g_assert_cmphex(i2c_get8(dev, PCA9535_POLARITY0), ==, 0x00);
26 + g_assert_cmphex(i2c_get8(dev, PCA9535_POLARITY1), ==, 0x00);
27 + g_assert_cmphex(i2c_get8(dev, PCA9535_CONFIG0), ==, 0xFF);
28 + g_assert_cmphex(i2c_get8(dev, PCA9535_CONFIG1), ==, 0xFF);
29 +}
30 +
31 +static void pca9555_register_nodes(void)
32 +{
33 + QOSGraphEdgeOptions opts = {
34 + .extra_device_opts = "address=0x20"
35 + };
36 + add_qi2c_address(&opts, &(QI2CAddress) { PCA9555_TEST_ADDR });
37 +
38 + qos_node_create_driver("pca9555", i2c_device_create);
39 + qos_node_consumes("pca9555", "i2c-bus", &opts);
40 +
41 + qos_add_test("reset-defaults", "pca9555", test_reset_defaults, NULL);
42 +}
43 +
44 +libqos_init(pca9555_register_nodes);