[Qemu-devel] [PATCH 05/13] pca9552-test: do not rely on state across tests

Paolo Bonzini posted 13 patches 6 years, 10 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Thomas Huth <thuth@redhat.com>, Jean-Christophe Dubois <jcd@tribudubois.net>, Laurent Vivier <lvivier@redhat.com>
[Qemu-devel] [PATCH 05/13] pca9552-test: do not rely on state across tests
Posted by Paolo Bonzini 6 years, 10 months ago
receive_autoinc is relying on the LED state that is set by
send_and_receive.  Stop doing that, because qgraph resets the
machine between tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/pca9552-test.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c
index 06359b7435..89b4445e29 100644
--- a/tests/pca9552-test.c
+++ b/tests/pca9552-test.c
@@ -18,11 +18,20 @@
 
 static I2CAdapter *i2c;
 
+static void pca9552_init(I2CAdapter *i2c)
+{
+    /* Switch on LEDs 0 and 12 */
+    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
+    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
+}
+
 static void receive_autoinc(void)
 {
     uint8_t resp;
     uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
 
+    pca9552_init(i2cdev);
+
     i2c_send(i2c, PCA9552_TEST_ADDR, &reg, 1);
 
     /* PCA9552_LS0 */
@@ -52,16 +61,14 @@ static void send_and_receive(void)
     value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
     g_assert_cmphex(value, ==, 0x0);
 
-    /* Switch on LED 0 */
-    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
+    pca9552_init(i2cdev);
+
     value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
     g_assert_cmphex(value, ==, 0x54);
 
     value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
     g_assert_cmphex(value, ==, 0x01);
 
-    /* Switch on LED 12 */
-    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
     value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3);
     g_assert_cmphex(value, ==, 0x54);
 
-- 
2.20.1



Re: [Qemu-devel] [PATCH 05/13] pca9552-test: do not rely on state across tests
Posted by Thomas Huth 6 years, 10 months ago
On 18/03/2019 18.15, Paolo Bonzini wrote:
> receive_autoinc is relying on the LED state that is set by
> send_and_receive.  Stop doing that, because qgraph resets the
> machine between tests.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/pca9552-test.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c
> index 06359b7435..89b4445e29 100644
> --- a/tests/pca9552-test.c
> +++ b/tests/pca9552-test.c
> @@ -18,11 +18,20 @@
>  
>  static I2CAdapter *i2c;
>  
> +static void pca9552_init(I2CAdapter *i2c)
> +{
> +    /* Switch on LEDs 0 and 12 */
> +    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
> +    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
> +}
> +
>  static void receive_autoinc(void)
>  {
>      uint8_t resp;
>      uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
>  
> +    pca9552_init(i2cdev);
> +
>      i2c_send(i2c, PCA9552_TEST_ADDR, &reg, 1);
>  
>      /* PCA9552_LS0 */
> @@ -52,16 +61,14 @@ static void send_and_receive(void)
>      value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
>      g_assert_cmphex(value, ==, 0x0);
>  
> -    /* Switch on LED 0 */
> -    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
> +    pca9552_init(i2cdev);
> +
>      value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
>      g_assert_cmphex(value, ==, 0x54);
>  
>      value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
>      g_assert_cmphex(value, ==, 0x01);
>  
> -    /* Switch on LED 12 */
> -    i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
>      value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3);
>      g_assert_cmphex(value, ==, 0x54);

Reviewed-by: Thomas Huth <thuth@redhat.com>