[U-Boot] [PATCH] test/py: Add basic QSPI testing
Michal Simek
michal.simek at xilinx.com
Tue May 17 16:05:30 CEST 2016
This is the first attempt how to test qspi.
Detect SPI size. Read it all, random size, erase every block,
write random data with random size and read it back,
erase the whole qspi and at the end load kernel image via tftp
and save it to memory.
Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---
test/py/tests/test_qspi.py | 134 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 134 insertions(+)
create mode 100644 test/py/tests/test_qspi.py
diff --git a/test/py/tests/test_qspi.py b/test/py/tests/test_qspi.py
new file mode 100644
index 000000000000..f8dea6de83da
--- /dev/null
+++ b/test/py/tests/test_qspi.py
@@ -0,0 +1,134 @@
+# Copyright (c) 2016, Xilinx Inc. Michal Simek
+#
+# SPDX-License-Identifier: GPL-2.0
+
+import pytest
+import re
+import random
+import u_boot_utils
+
+qspi_detected = False
+page_size = 0
+erase_size = 0
+total_size = 0
+
+# Find out qspi memory parameters
+def qspi_pre_commands(u_boot_console):
+ output = u_boot_console.run_command('sf probe')
+ if not "SF: Detected" in output:
+ pytest.skip('No QSPI device available')
+
+ m = re.search('page size (.+?) Bytes', output)
+ if m:
+ try:
+ global page_size
+ page_size = int(m.group(1))
+ except ValueError:
+ pytest.fail("QSPI page size not recognized")
+
+ print 'Page size is: ' + str(page_size) + " B"
+
+ m = re.search('erase size (.+?) KiB', output)
+ if m:
+ try:
+ global erase_size
+ erase_size = int(m.group(1))
+ except ValueError:
+ pytest.fail("QSPI erase size not recognized")
+
+ erase_size *= 1024
+ print 'Erase size is: ' + str(erase_size) + " B"
+
+ m = re.search('total (.+?) MiB', output)
+ if m:
+ try:
+ global total_size
+ total_size = int(m.group(1))
+ except ValueError:
+ pytest.fail("QSPI total size not recognized")
+
+ total_size *= 1024 * 1024
+ print 'Total size is: ' + str(total_size) + " B"
+
+ global qspi_detected
+ qspi_detected = True
+
+# Read the whole QSPI flash twice, random_size till full flash size, random till page size
+ at pytest.mark.buildconfigspec('cmd_sf')
+ at pytest.mark.buildconfigspec('cmd_memory')
+def test_qspi_read_twice(u_boot_console):
+ qspi_pre_commands(u_boot_console)
+
+ if not qspi_detected:
+ pytest.skip('QSPI not detected')
+
+ expected_read = "Read: OK"
+
+ # TODO maybe add alignment and different start for pages
+ for size in random.randint(4, page_size), random.randint(4, total_size), total_size:
+ addr = u_boot_utils.find_ram_base(u_boot_console)
+ # FIXME using 0 is failing for me
+ output = u_boot_console.run_command('sf read %x 0 %x' % (addr + total_size, size))
+ assert expected_read in output
+ output = u_boot_console.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)
+ output = u_boot_console.run_command('sf read %x 0 %x' % (addr + total_size + 10, size))
+ assert expected_read in output
+ output = u_boot_console.run_command('crc32 %x %x' % (addr + total_size + 10, size))
+ assert expected_crc32 in output
+
+# This test check crossing boundary for dual/parralel configurations
+ at pytest.mark.buildconfigspec('cmd_sf')
+def test_qspi_erase_block(u_boot_console):
+ qspi_pre_commands(u_boot_console)
+
+ if not qspi_detected:
+ pytest.skip('QSPI not detected')
+
+ expected_erase = "Erased: OK"
+ for start in range(0, total_size, erase_size):
+ output = u_boot_console.run_command('sf erase %x %x' % (start, erase_size))
+ assert expected_erase in output
+
+# Random write till page size, random till size and full size
+ at pytest.mark.buildconfigspec('cmd_sf')
+ at pytest.mark.buildconfigspec('cmd_memory')
+def test_qspi_write_twice(u_boot_console):
+ qspi_pre_commands(u_boot_console)
+
+ if not qspi_detected:
+ pytest.skip('QSPI not detected')
+
+ expected_write = "Written: OK"
+ expected_read = "Read: OK"
+
+ # TODO maybe add alignment and different start for pages
+ for size in random.randint(4, page_size), random.randint(page_size, total_size), total_size:
+ addr = u_boot_utils.find_ram_base(u_boot_console)
+ output = u_boot_console.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)
+
+ output = u_boot_console.run_command('sf write %x 0 %x' % (addr + total_size, size))
+ assert expected_write in output
+ output = u_boot_console.run_command('sf read %x 0 %x' % (addr + total_size + 10, size))
+ assert expected_read in output
+ output = u_boot_console.run_command('crc32 %x %x' % (addr + total_size + 10, size))
+ assert expected_crc32 in output
+
+ at pytest.mark.buildconfigspec('cmd_sf')
+def test_qspi_erase_all(u_boot_console):
+ qspi_pre_commands(u_boot_console)
+
+ if not qspi_detected:
+ pytest.skip('QSPI not detected')
+
+ expected_erase = "Erased: OK"
+ start = 0
+ output = u_boot_console.run_command('sf erase 0 ' + str(hex(total_size)))
+ assert expected_erase in output
--
1.9.1
More information about the U-Boot
mailing list