From: Jean-Jacques Hiblot Date: Tue, 2 Jul 2019 10:16:38 +0200 Subject: [U-Boot] [PATCH v1] test/py: add MMC/SD block write test In-Reply-To: References: <20190617154921.10448-1-jjhiblot@ti.com> Message-ID: <7a1e18d6-ae0c-9f37-4d31-75cf933faa80@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de On 02/07/2019 10:03, Peng Fan wrote: >> Subject: [PATCH v1] test/py: add MMC/SD block write test >> >> Add a standalone MMC block write test. This allows direct testing of MMC >> access rather than relying on doing so as a side-effect of e.g. DFU or U= MS >> testing, which may not be enabled on all platforms. >> >> Signed-off-by: Jean-Jacques Hiblot >> >> --- >> This patch relies on patch "cmd: mem: Add a command to fill the memory >> with random data". > I not able to find "cmd: mem: Add a xx" in patchwork/mailbox, has this be= en applied? You can get it from patchwork. I don't think=C2=A0 it has been applied yet. https://patchwork.ozlabs.org/patch/1116086/ > I have taken this current patch into mmc-next. > > Regards, > Peng >> test/py/tests/test_mmc_wr.py | 105 >> +++++++++++++++++++++++++++++++++++ >> 1 file changed, 105 insertions(+) >> create mode 100644 test/py/tests/test_mmc_wr.py >> >> diff --git a/test/py/tests/test_mmc_wr.py b/test/py/tests/test_mmc_wr.py >> new file mode 100644 index 0000000000..601279a6a4 >> --- /dev/null >> +++ b/test/py/tests/test_mmc_wr.py >> @@ -0,0 +1,105 @@ >> +# SPDX-License-Identifier: GPL-2.0 >> +# Copyright (c) 2019, Texas Instrument >> +# Author: Jean-Jacques Hiblot >> + >> +# Test U-Boot's "mmc write" command. The test generates random data, >> +writes it # to the eMMC or SD card, then reads it back and performs a >> comparison. >> + >> +import pytest >> +import u_boot_utils >> + >> +""" >> +This test relies on boardenv_* to containing configuration values to >> +define which MMC devices should be tested. For example: >> + >> +env__mmc_wr_configs =3D ( >> + { >> + "fixture_id": "emmc-boot0", >> + "is_emmc": True, >> + "devid": 1, >> + "partid": 1, >> + "sector": 0x10, >> + "count": 100, >> + "test_iterations": 50, >> + }, >> + { >> + "fixture_id": "emmc-boot1", >> + "is_emmc": True, >> + "devid": 1, >> + "partid": 2, >> + "sector": 0x10, >> + "count": 100, >> + "test_iterations": 50, >> + }, >> +) >> + >> +""" >> + >> + at pytest.mark.buildconfigspec('cmd_mmc','cmd_memory') >> +def test_mmc_wr(u_boot_console, env__mmc_wr_config): >> + """Test the "mmc write" command. >> + >> + Args: >> + u_boot_console: A U-Boot console connection. >> + env__mmc_wr_config: The single MMC configuration on which >> + to run the test. See the file-level comment above for detai= ls >> + of the format. >> + >> + Returns: >> + Nothing. >> + """ >> + >> + is_emmc =3D env__mmc_wr_config['is_emmc'] >> + devid =3D env__mmc_wr_config['devid'] >> + partid =3D env__mmc_wr_config.get('partid', 0) >> + sector =3D env__mmc_wr_config.get('sector', 0) >> + count_sectors =3D env__mmc_wr_config.get('count', 1) >> + test_iterations =3D env__mmc_wr_config.get('test_iterations', 1) >> + >> + >> + count_bytes =3D count_sectors * 512 >> + bcfg =3D u_boot_console.config.buildconfig >> + ram_base =3D u_boot_utils.find_ram_base(u_boot_console) >> + src_addr =3D '0x%08x' % ram_base >> + dst_addr =3D '0x%08x' % (ram_base + count_bytes) >> + >> + >> + for i in range(test_iterations): >> + # Generate random data >> + cmd =3D 'random %s %x' % (src_addr, count_bytes) >> + response =3D u_boot_console.run_command(cmd) >> + good_response =3D '%d bytes filled with random data' % (count_bytes) >> + assert good_response in response >> + >> + # Select MMC device >> + cmd =3D 'mmc dev %d' % devid >> + if is_emmc: >> + cmd +=3D ' %d' % partid >> + response =3D u_boot_console.run_command(cmd) >> + assert 'no card present' not in response >> + if is_emmc: >> + partid_response =3D "(part %d)" % partid >> + else: >> + partid_response =3D "" >> + good_response =3D 'mmc%d%s is current device' % (devid, >> partid_response) >> + assert good_response in response >> + >> + # Write data >> + cmd =3D 'mmc write %s %x %x' % (src_addr, sector, count_sectors) >> + response =3D u_boot_console.run_command(cmd) >> + good_response =3D 'MMC write: dev # %d, block # %d, count %d ... %d >> blocks written: OK' % ( >> + devid, sector, count_sectors, count_sectors) >> + assert good_response in response >> + >> + # Read data >> + cmd =3D 'mmc read %s %x %x' % (dst_addr, sector, count_sectors) >> + response =3D u_boot_console.run_command(cmd) >> + good_response =3D 'MMC read: dev # %d, block # %d, count %d ... %d >> blocks read: OK' % ( >> + devid, sector, count_sectors, count_sectors) >> + assert good_response in response >> + >> + # Compare src and dst data >> + cmd =3D 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes) >> + response =3D u_boot_console.run_command(cmd) >> + good_response =3D 'Total of %d byte(s) were the same' % (count_bytes) >> + assert good_response in response >> -- >> 2.17.1 >