@samitouri / QOSamiQemu / commits / e1338eb6da

tests/qtest: pca9554: test polarity inversion

Verify that the polarity register inverts the value read back from the INPUT register, both on pulled-up inputs and on output-driven pins, while leaving the OUTPUT register itself unchanged. 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-21-82a63fead90c@free.fr Signed-off-by: Cédric Le Goater <clg@redhat.com>

Emmanuel Blot committed Jul 9, 2026 at 17:23 UTC e1338eb6da3041be64c096ba60e8680dbcd51a68
1 file changed +39
tests/qtest/pca9554-test.c
+39
@@ -67,6 +67,41 @@ static void test_input_pullup(void *obj, void *data, QGuestAllocator *alloc)
67 g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0x00);
68 }
69
70 +/*
71 + * Polarity inversion: reading INPUT returns the XOR of the pin levels and the
72 + * polarity register.
73 + */
74 +static void test_polarity_inversion(void *obj, void *data,
75 + QGuestAllocator *alloc)
76 +{
77 + QI2CDevice *dev = (QI2CDevice *)obj;
78 +
79 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0xFF);
80 +
81 + i2c_set8(dev, PCA9554_POLARITY, 0xFF);
82 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0x00);
83 +
84 + i2c_set8(dev, PCA9554_POLARITY, 0x0F);
85 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0xF0);
86 +}
87 +
88 +/* Polarity inversion combined with output-driven pins. */
89 +static void test_polarity_with_output(void *obj, void *data,
90 + QGuestAllocator *alloc)
91 +{
92 + QI2CDevice *dev = (QI2CDevice *)obj;
93 +
94 + i2c_set8(dev, PCA9554_CONFIG, 0x00);
95 + i2c_set8(dev, PCA9554_OUTPUT, 0xA5);
96 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0xA5);
97 +
98 + i2c_set8(dev, PCA9554_POLARITY, 0xFF);
99 + g_assert_cmphex(i2c_get8(dev, PCA9554_INPUT), ==, 0x5A);
100 +
101 + /* Inversion only affects the INPUT read, not the OUTPUT register. */
102 + g_assert_cmphex(i2c_get8(dev, PCA9554_OUTPUT), ==, 0xA5);
103 +}
104 +
105 static void pca9554_register_nodes(void)
106 {
107 QOSGraphEdgeOptions opts = {
@@ -81,6 +116,10 @@ static void pca9554_register_nodes(void)
116 qos_add_test("output-drives-input", "pca9554", test_output_drives_input,
117 NULL);
118 qos_add_test("input-pullup", "pca9554", test_input_pullup, NULL);
119 + qos_add_test("polarity-inversion", "pca9554", test_polarity_inversion,
120 + NULL);
121 + qos_add_test("polarity-with-output", "pca9554", test_polarity_with_output,
122 + NULL);
123 }
124
125 libqos_init(pca9554_register_nodes);