[PATCH v3] test/py: nand: Add tests for NAND flash device

Simon Glass sjg at chromium.org
Sat May 23 16:17:07 CEST 2026


Hi Love,

On 2026-05-05T07:40:25, Love Kumar <love.kumar at amd.com> wrote:
> test/py: nand: Add tests for NAND flash device
>
> Add tests for nand commands to test various NAND flash operations such
> as erase, write and read.
>
> Signed-off-by: Love Kumar <love.kumar at amd.com>
>
> doc/develop/pytest/test_nand.rst |   8 ++
>  test/py/tests/test_nand.py       | 237 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 245 insertions(+)

Reviewed-by: Simon Glass <sjg at chromium.org>

> diff --git a/test/py/tests/test_nand.py b/test/py/tests/test_nand.py
> @@ -0,0 +1,237 @@
> +        output = ubman.run_command('crc32 %x %x' % (addr + total_size, size))
> +        m = re.search('==> (.+?)', output)
> +        if not m:
> +            pytest.fail('CRC32 failed')
> +        expected_crc32 = m.group(1)

This regex is missing the $ anchor that test_spi.py uses. With
non-greedy .+? and no terminator, group(1) is just the first character
after '==> ', so expected_crc32 ends up as a single hex digit. The
later 'assert expected_crc32 in output' then matches almost any output
and the test never really checks the CRC. Please use '==> (.+?)$'
(same fix needed in test_nand_write_twice).

> diff --git a/test/py/tests/test_nand.py b/test/py/tests/test_nand.py
> @@ -0,0 +1,237 @@
> +    output = ubman.run_command('nand bad')
> +    if not 'bad blocks:' in output:
> +        pytest.skip('No NAND device available')
> +
> +    count = 0
> +    m = re.search(r'bad blocks:([\n\s\s\d\w]*)', output)
> +    if m:
> +        print(m.group(1))
> +        var = m.group(1).split()
> +        count = len(var)
> +    print('bad blocks count= ' + str(count))

Using a 'nand bad' miss as the "no device" signal seems wrong; you
already detected the device from 'nand info' above. If 'nand bad'
fails to print the header, that's a different problem and should not
be silently skipped

The bare print() calls look like leftover debug output?

> diff --git a/test/py/tests/test_nand.py b/test/py/tests/test_nand.py
> @@ -0,0 +1,237 @@
> +    expected_erase = '100% complete.'
> +    with ubman.temporary_timeout(timeout):
> +        output = ubman.run_command(
> +            'nand erase.spread 0 ' + str(hex(total_size))
> +        )
> +        assert expected_erase in output

Please use %x formatting like everywhere else in the file rather than
str(hex(...)). We should use f-strings in most cases.

> diff --git a/doc/develop/pytest/test_nand.rst b/doc/develop/pytest/test_nand.rst
> @@ -0,0 +1,8 @@
> +test_nand
> +=========
> +
> +.. automodule:: test_nand
> +   :synopsis:
> +   :member-order: bysource
> +   :members:
> +   :undoc-members:

Please add the SPDX-License-Identifier: GPL-2.0+ comment at the top,
matching test_fit.rst.

Regards,
Simon


More information about the U-Boot mailing list