@samitouri / QOSamiQemu / commits / f2fa57afff

tests/qtest: pca9555: test polarity inversion

Add tests for the polarity inversion register: the inversion is applied when reading the INPUT register, both for input pins (pull-up) and for output-driven pins, and it does not affect the OUTPUT register readback. 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-12-82a63fead90c@free.fr Signed-off-by: Cédric Le Goater <clg@redhat.com>

Emmanuel Blot committed Jul 9, 2026 at 17:23 UTC f2fa57afffde5885d69d2db3a7a22a8c5d1eba1a
1 file changed +44
tests/qtest/pca9555-test.c
+44
@@ -99,6 +99,46 @@ static void test_port_independence(void *obj, void *data,
99 g_assert_cmphex(i2c_get8(dev, PCA9535_OUTPUT1), ==, 0xAA);
100 }
101
102 +/*
103 + * Polarity inversion: reading INPUT with polarity bits set should
104 + * return the XOR of the actual input state and the polarity register.
105 + */
106 +static void test_polarity_inversion(void *obj, void *data,
107 + QGuestAllocator *alloc)
108 +{
109 + QI2CDevice *dev = (QI2CDevice *)obj;
110 +
111 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0xFF);
112 +
113 + i2c_set8(dev, PCA9535_POLARITY0, 0xFF);
114 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0x00);
115 +
116 + i2c_set8(dev, PCA9535_POLARITY0, 0x0F);
117 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0xF0);
118 +
119 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT1), ==, 0xFF);
120 +
121 + i2c_set8(dev, PCA9535_POLARITY1, 0xAA);
122 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT1), ==, 0x55);
123 +}
124 +
125 +/* Polarity inversion combined with output-driven pins. */
126 +static void test_polarity_with_output(void *obj, void *data,
127 + QGuestAllocator *alloc)
128 +{
129 + QI2CDevice *dev = (QI2CDevice *)obj;
130 +
131 + i2c_set8(dev, PCA9535_CONFIG0, 0x00);
132 + i2c_set8(dev, PCA9535_OUTPUT0, 0xA5);
133 +
134 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0xA5);
135 +
136 + i2c_set8(dev, PCA9535_POLARITY0, 0xFF);
137 + g_assert_cmphex(i2c_get8(dev, PCA9535_INPUT0), ==, 0x5A);
138 +
139 + g_assert_cmphex(i2c_get8(dev, PCA9535_OUTPUT0), ==, 0xA5);
140 +}
141 +
142 static void pca9555_register_nodes(void)
143 {
144 QOSGraphEdgeOptions opts = {
@@ -114,6 +154,10 @@ static void pca9555_register_nodes(void)
154 NULL);
155 qos_add_test("input-pullup", "pca9555", test_input_pullup, NULL);
156 qos_add_test("port-independence", "pca9555", test_port_independence, NULL);
157 + qos_add_test("polarity-inversion", "pca9555", test_polarity_inversion,
158 + NULL);
159 + qos_add_test("polarity-with-output", "pca9555", test_polarity_with_output,
160 + NULL);
161 }
162
163 libqos_init(pca9555_register_nodes);