test/py: nand: Add tests for NAND flash device
PATCH v3 1/1 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.
---
Changes in v3:
- Use the current test/py APIs (ubman fixture and utils helpers)
- Refactor nand_pre_commands() to return a dictionary
- Accept multi-chip nand info output (e.g. "Device 0: 2x nand0")
- Add Sphinx-rendered documentation for the test
- Update copyright year
Changes in v2:
- Fix the deprecation warning issue for invalid escape sequence
--- doc/develop/pytest/test_nand.rst | 8 ++ test/py/tests/test_nand.py | 237 +++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 doc/develop/pytest/test_nand.rst create mode 100644 test/py/tests/test_nand.py
doc/develop/pytest/test_nand.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_nand +========= + +.. automodule:: test_nand + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_nand.py new file +237 -0
237 lines not on this page · raw message
Signature · 1 line
2.43.0
Hi Love,
Quoted 10 lines · Love Kumar
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 <[email protected]>
doc/develop/pytest/test_nand.rst| 8 ++test/py/tests/test_nand.py | 237 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+)
test/py/tests/test_nand.py line 5
Quoted 7 lines
test/py/tests/test_nand.py +5
-0@@ -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).
test/py/tests/test_nand.py line 11
Quoted 13 lines
test/py/tests/test_nand.py +11
-0@@ -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?
test/py/tests/test_nand.py line 6
Quoted 8 lines
test/py/tests/test_nand.py +6
-0@@ -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.
doc/develop/pytest/test_nand.rst line 8
Quoted 10 lines
doc/develop/pytest/test_nand.rst +8
-0@@ -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