[PATCH] test/py: i2c: Add tests for i2c command

Tom Rini trini at konsulko.com
Thu Nov 16 17:30:37 CET 2023


On Wed, Nov 15, 2023 at 12:08:38PM +0530, Love Kumar wrote:

> Add below test cases for i2c commands:
> i2c_bus - To show i2c bus info,
> i2c_dev - To set or show the current bus,
> i2c_probe - To probe the i2c device,
> i2c_eeprom - To test i2c eeprom device,
> i2c_probe_all_buses - To list down all the buses and probes it
> 
> Signed-off-by: Love Kumar <love.kumar at amd.com>
> ---
>  test/py/tests/test_i2c.py | 107 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 107 insertions(+)
>  create mode 100644 test/py/tests/test_i2c.py

I'm mostly happy with this test. I enabled it for one of my platforms
with an EEPROM and:

> + at pytest.mark.buildconfigspec("cmd_i2c")
> +def test_i2c_eeprom(u_boot_console):
> +    f = u_boot_console.config.env.get("env__i2c_eeprom_device_test", None)
> +    if not f:
> +        pytest.skip("No I2C eeprom to test!")
> +
> +    bus = f.get("bus", 0)
> +    if bus < 0:
> +        pytest.fail("No bus specified via env__i2c_eeprom_device_test!")
> +
> +    addr = f.get("eeprom_addr", -1)
> +    if addr < 0:
> +        pytest.fail("No eeprom address specified via env__i2c_eeprom_device_test!")
> +
> +    # Enable i2c mux bridge
> +    u_boot_console.run_command("i2c dev %x" % bus)
> +    u_boot_console.run_command("i2c probe")
> +    val_int = random.randint(0, 255)
> +    value = format(val_int, "02x")
> +    u_boot_console.run_command("i2c mw %x 0 %x 5" % (addr, val_int))
> +    expected_response = f"0000: {value} {value} {value} {value} {value} "
> +    response = u_boot_console.run_command("i2c md %x 0 5" % addr)
> +    assert expected_response in response

So this is a destructive test, yes? That's fine for QEMU but on real
hardware that's a problem. Doubly so since I need the contents to be
correct as they already are. Can we change this such that we probe the
eeprom and then read back the configured correct value instead?

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20231116/c0e10c43/attachment.sig>


More information about the U-Boot mailing list