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

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@amd.com --- Changes in v2: - Take the configured eeprom value from env to read back and compare --- test/py/tests/test_i2c.py | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 test/py/tests/test_i2c.py
diff --git a/test/py/tests/test_i2c.py b/test/py/tests/test_i2c.py new file mode 100644 index 000000000000..75321ee2fc20 --- /dev/null +++ b/test/py/tests/test_i2c.py @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: GPL-2.0 +# (C) Copyright 2023, Advanced Micro Devices, Inc. + +import pytest +import random +import re + +""" +Note: This test doesn't rely on boardenv_* configuration value but they can +change test behavior. + +For example: + +# Setup env__i2c_device_test_skip to True if tests with i2c devices should be +# skipped. For example: Missing QEMU model or broken i2c device +env__i2c_device_test_skip = True + +# Setup env__i2c_eeprom_device_test to set the i2c bus number, eeprom address +# and configured value for i2c_eeprom test case. Test will be skipped if +# env__i2c_eeprom_device_test is not set +env__i2c_eeprom_device_test = { + "bus": 3, + "eeprom_addr": 0x54, + "eeprom_val": "30 31", +} + +# Setup env__i2c_device_test to provide the i2c bus list to test against it +# for i2c_probe_all_buses case instead of probing all the buses available. If +# it is not set, it list down all the buses and probes it +env__i2c_device_test = { + "bus_list": [0, 2, 5, 12, 16, 18] +} +""" + +@pytest.mark.buildconfigspec("cmd_i2c") +def test_i2c_bus(u_boot_console): + if u_boot_console.config.env.get("env__i2c_device_test_skip", False): + pytest.skip("I2C device test is not enabled!") + expected_response = "Bus" + response = u_boot_console.run_command("i2c bus") + assert expected_response in response + +@pytest.mark.buildconfigspec("cmd_i2c") +def test_i2c_dev(u_boot_console): + if u_boot_console.config.env.get("env__i2c_device_test_skip", False): + pytest.skip("I2C device test is not enabled!") + expected_response = "Current bus" + response = u_boot_console.run_command("i2c dev") + assert expected_response in response + +@pytest.mark.buildconfigspec("cmd_i2c") +def test_i2c_probe(u_boot_console): + if u_boot_console.config.env.get("env__i2c_device_test_skip", False): + pytest.skip("I2C device test is not enabled!") + expected_response = "Setting bus to 0" + response = u_boot_console.run_command("i2c dev 0") + assert expected_response in response + expected_response = "Valid chip addresses:" + response = u_boot_console.run_command("i2c probe") + assert expected_response in response + +@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!") + + value = f.get("eeprom_val") + if not value: + pytest.fail("No eeprom configured value provided 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") + output = u_boot_console.run_command("i2c md %x 0 5" % addr) + assert value in output + +@pytest.mark.buildconfigspec("cmd_i2c") +def test_i2c_probe_all_buses(u_boot_console): + if u_boot_console.config.env.get("env__i2c_device_test_skip", False): + pytest.skip("I2C device test is not enabled!") + expected_response = "Bus" + response = u_boot_console.run_command("i2c bus") + assert expected_response in response + + # Get all the bus list + f = u_boot_console.config.env.get("env__i2c_device_test", None) + if f: + bus_list = f.get("bus_list") + else: + buses = re.findall("Bus (.+?):", response) + bus_list = [int(x) for x in buses] + + for dev in bus_list: + expected_response = f"Setting bus to {dev}" + response = u_boot_console.run_command(f"i2c dev {dev}") + assert expected_response in response + expected_response = "Valid chip addresses:" + response = u_boot_console.run_command("i2c probe") + assert expected_response in response

On Tue, Nov 21, 2023 at 05:28:43PM +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@amd.com
Reviewed-by: Tom Rini trini@konsulko.com

On Tue, Nov 21, 2023 at 05:28:43PM +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@amd.com Reviewed-by: Tom Rini trini@konsulko.com
Changes in v2:
- Take the configured eeprom value from env to read back and compare
test/py/tests/test_i2c.py | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 test/py/tests/test_i2c.py
So this leads to failures in CI on other platforms. Please put this and the other tests through CI: https://docs.u-boot.org/en/latest/develop/ci_testing.html Thanks!

On 12/20/23 16:46, Tom Rini wrote:
On Tue, Nov 21, 2023 at 05:28:43PM +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@amd.com Reviewed-by: Tom Rini trini@konsulko.com
Changes in v2:
- Take the configured eeprom value from env to read back and compare
test/py/tests/test_i2c.py | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 test/py/tests/test_i2c.py
So this leads to failures in CI on other platforms. Please put this and the other tests through CI: https://docs.u-boot.org/en/latest/develop/ci_testing.html
Can you give me link to that gitlab build to see it? I can push it via my tree but it will be just resource wasting to see errors which you have seen already.
Thanks, Michal

On Wed, Dec 20, 2023 at 05:45:24PM +0100, Michal Simek wrote:
On 12/20/23 16:46, Tom Rini wrote:
On Tue, Nov 21, 2023 at 05:28:43PM +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@amd.com Reviewed-by: Tom Rini trini@konsulko.com
Changes in v2:
- Take the configured eeprom value from env to read back and compare
test/py/tests/test_i2c.py | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 test/py/tests/test_i2c.py
So this leads to failures in CI on other platforms. Please put this and the other tests through CI: https://docs.u-boot.org/en/latest/develop/ci_testing.html
Can you give me link to that gitlab build to see it? I can push it via my tree but it will be just resource wasting to see errors which you have seen already.
The first failure is https://source.denx.de/u-boot/u-boot/-/jobs/758375#L268 but I suspect that like the mii or mdio (I forget which now) test, they end up needing to be opt-in, but should also have their comments expanded to make sure it's clear what expected values to configure the test are.
participants (3)
-
Love Kumar
-
Michal Simek
-
Tom Rini