Skip to contentSkip to conversation

test/py: add MMC/SD block read test

PATCH New Stephen Warren 2 participants 6 messages Feb 20, 2018 – Mar 14, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 test/py: add MMC/SD block read test

From: Stephen Warren <[email protected]>

Add a standalone MMC block read test. This allows direct testing of MMC access rather than relying on doing so as a side-effect of e.g. DFU or UMS testing, which may not be enabled on all platforms.

---
 test/py/tests/test_mmc_rd.py | 129 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 129 insertions(+)
 create mode 100644 test/py/tests/test_mmc_rd.py
test/py/tests/test_mmc_rd.py new file +129 -0
new file mode 100644
index 000000000000..7ff76228e2e9
@@ -0,0 +1,129 @@
+# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+# Test U-Boot's "mmc read" command. The test reads data from the eMMC or SD
+# card, and validates the no errors occurred, and that the expected data was
+# read if the test configuration contains a CRC of the expected data.
+
+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_rd_configs = (
+    {
+        "fixture_id": "emmc-boot0",
+        "is_emmc": True,
+        "devid": 0,
+        "partid": 1,
+        "sector": 0x10,
+        "count": 1,
+    },
+    {
+        "fixture_id": "emmc-boot1",
+        "is_emmc": True,
+        "devid": 0,
+        "partid": 2,
+        "sector": 0x10,
+        "count": 1,
+    },
+    {
+        "fixture_id": "emmc-data",
+        "is_emmc": True,
+        "devid": 0,
+        "partid": 0,
+        "sector": 0x10,
+        "count": 0x1000,
+    },
+    {
+        "fixture_id": "sd-mbr",
+        "is_emmc": False,
+        "devid": 1,
+        "partid": None,
+        "sector": 0,
+        "count": 1,
+        "crc32": "8f6ecf0d",
+    },
+    {
+        "fixture_id": "sd-large",
+        "is_emmc": False,
+        "devid": 1,
+        "partid": None,
+        "sector": 0x10,
+        "count": 0x1000,
+    },
+)
+"""
+
+ at pytest.mark.buildconfigspec('cmd_mmc')
+def test_mmc_rd(u_boot_console, env__mmc_rd_config):
+    """Test the "mmc read" command.
+
+    Args:
+        u_boot_console: A U-Boot console connection.
+        env__mmc_rd_config: The single MMC configuration on which
+            to run the test. See the file-level comment above for details
+            of the format.
+
+    Returns:
+        Nothing.
+    """
+
+    is_emmc = env__mmc_rd_config['is_emmc']
+    devid = env__mmc_rd_config['devid']
+    partid = env__mmc_rd_config.get('partid', 0)
+    sector = env__mmc_rd_config.get('sector', 0)
+    count_sectors = env__mmc_rd_config.get('count', 1)
+    expected_crc32 = env__mmc_rd_config.get('crc32', None)
+
+    count_bytes = count_sectors * 512
+    bcfg = u_boot_console.config.buildconfig
+    has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
+    has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
+    ram_base = u_boot_utils.find_ram_base(u_boot_console)
+    addr = '0x%08x' % ram_base
+
+    # Select MMC device
+    cmd = 'mmc dev %d' % devid
+    if is_emmc:
+        cmd += ' %d' % partid
+    response = u_boot_console.run_command(cmd)
+    assert 'no card present' not in response
+    if is_emmc:
+        partid_response = "(part %d)" % partid
+    else:
+        partid_response = ""
+    good_response = 'mmc%d%s is current device' % (devid, partid_response)
+    assert good_response in response
+
+    # Clear target RAM
+    if expected_crc32:
+        if has_cmd_memory and has_cmd_crc32:
+            cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
+            u_boot_console.run_command(cmd)
+
+            cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
+            response = u_boot_console.run_command(cmd)
+            assert expected_crc32 not in response
+        else:
+            u_boot_console.log.warning(
+                'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
+
+    # Read data
+    cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
+    response = u_boot_console.run_command(cmd)
+    good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
+        devid, sector, count_sectors, count_sectors)
+    assert good_response in response
+
+    # Check target RAM
+    if expected_crc32:
+        if has_cmd_crc32:
+            cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
+            response = u_boot_console.run_command(cmd)
+            assert expected_crc32 in response
+        else:
+            u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')
Signature · 1 line
2.16.1
#1 lore raw

PATCH 1/2 test/py: add MMC/SD block read test

Quoted 5 lines · Stephen Warren

From: Stephen Warren <[email protected]>

Add a standalone MMC block read test. This allows direct testing of MMC access rather than relying on doing so as a side-effect of e.g. DFU or UMS testing, which may not be enabled on all platforms.

I assume you were only waiting for the merge window to open before applying this; there weren't any other issues? Thanks.

#2 lore raw

PATCH 1/2 test/py: add MMC/SD block read test

Quoted 9 lines · Stephen Warren
Quoted 5 lines · Stephen Warren

From: Stephen Warren <[email protected]>

Add a standalone MMC block read test. This allows direct testing of MMC access rather than relying on doing so as a side-effect of e.g. DFU or UMS testing, which may not be enabled on all platforms.

I assume you were only waiting for the merge window to open before applying this; there weren't any other issues? Thanks.

Indeed, thanks for the reminder, I'm going to be picking this (and other stuff) up soon.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180313/1d05e814/attachment.sig>
#3 lore raw

PATCH 2/2 test/py: highlight warnings in the log summary

In reply to Stephen Warren

From: Stephen Warren <[email protected]>

Currently, if a test emits a warning message but otherwise passes, there's no indication of this in the log summary, which can lead to warnings being missed. Enhance the test logic to explicitly mention warnings in otherwise passing tests, and not to collapse the log sections for tests with warnings, so that they're more easily seen when scanning the log.

---
 test/py/conftest.py         | 19 ++++++++++++++++---
 test/py/multiplexed_log.css |  4 ++++
 test/py/multiplexed_log.py  | 30 ++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 3 deletions(-)
test/py/conftest.py +16 -3
index 3fe91e874606..83eaca46a908 100644
@@ -344,6 +344,7 @@ tests_failed = []
 tests_xpassed = []
 tests_xfailed = []
 tests_skipped = []
+tests_warning = []
 tests_passed = []
 
 def pytest_itemcollected(item):
@@ -380,6 +381,11 @@ def cleanup():
     if log:
         with log.section('Status Report', 'status_report'):
             log.status_pass('%d passed' % len(tests_passed))
+            if tests_warning:
+                log.status_warning('%d passed with warning' % len(tests_warning))
+                for test in tests_warning:
+                    anchor = anchors.get(test, None)
+                    log.status_warning('... ' + test, anchor)
             if tests_skipped:
                 log.status_skipped('%d skipped' % len(tests_skipped))
                 for test in tests_skipped:
@@ -520,7 +526,9 @@ def pytest_runtest_protocol(item, nextitem):
         A list of pytest reports (test result data).
     """
 
+    log.get_and_reset_warning()
     reports = runtestprotocol(item, nextitem=nextitem)
+    was_warning = log.get_and_reset_warning()
 
     # In pytest 3, runtestprotocol() may not call pytest_runtest_setup() if
     # the test is skipped. That call is required to create the test's section
@@ -531,9 +539,14 @@ def pytest_runtest_protocol(item, nextitem):
         start_test_section(item)
 
     failure_cleanup = False
-    test_list = tests_passed
-    msg = 'OK'
-    msg_log = log.status_pass
+    if not was_warning:
+        test_list = tests_passed
+        msg = 'OK'
+        msg_log = log.status_pass
+    else:
+        test_list = tests_warning
+        msg = 'OK (with warning)'
+        msg_log = log.status_warning
     for report in reports:
         if report.outcome == 'failed':
             if hasattr(report, 'wasxfail'):
test/py/multiplexed_log.css +4 -0
index 9b7c44fe4de0..562f69f3b6f7 100644
@@ -70,6 +70,10 @@ pre {
     color: #00ff00
 }
 
+.status-warning {
+    color: #ffff00
+}
+
 .status-skipped {
     color: #ffff00
 }
test/py/multiplexed_log.py +30 -0
index 8ca515319ce9..a2cfd7174619 100644
@@ -224,6 +224,7 @@ class Logfile(object):
         self.timestamp_start = self._get_time()
         self.timestamp_prev = self.timestamp_start
         self.timestamp_blocks = []
+        self.seen_warning = False
 
         shutil.copy(mod_dir + '/multiplexed_log.css', os.path.dirname(fn))
         self.f.write('''\
@@ -252,6 +253,7 @@ $(document).ready(function () {
     passed_bcs = passed_bcs.not(":has(.status-xfail)");
     passed_bcs = passed_bcs.not(":has(.status-xpass)");
     passed_bcs = passed_bcs.not(":has(.status-skipped)");
+    passed_bcs = passed_bcs.not(":has(.status-warning)");
     // Hide the passed blocks
     passed_bcs.addClass("hidden");
     // Flip the expand/contract button hiding for those blocks.
@@ -478,8 +480,23 @@ $(document).ready(function () {
             Nothing.
         """
 
+        self.seen_warning = True
         self._note("warning", msg)
 
+    def get_and_reset_warning(self):
+        """Get and reset the log warning flag.
+
+        Args:
+            None
+
+        Returns:
+            Whether a warning was seen since the last call.
+        """
+
+        ret = self.seen_warning
+        self.seen_warning = False
+        return ret
+
     def info(self, msg):
         """Write an informational note to the log file.
 
@@ -542,6 +559,19 @@ $(document).ready(function () {
 
         self._note("status-pass", msg, anchor)
 
+    def status_warning(self, msg, anchor=None):
+        """Write a note to the log file describing test(s) which passed.
+
+        Args:
+            msg: A message describing the passed test(s).
+            anchor: Optional internal link target.
+
+        Returns:
+            Nothing.
+        """
+
+        self._note("status-warning", msg, anchor)
+
     def status_skipped(self, msg, anchor=None):
         """Write a note to the log file describing skipped test(s).
 
Signature · 1 line
2.16.1
#4 lore raw

PATCH 2/2 test/py: highlight warnings in the log summary

Quoted 9 lines · Stephen Warren

From: Stephen Warren <[email protected]>

Currently, if a test emits a warning message but otherwise passes, there's no indication of this in the log summary, which can lead to warnings being missed. Enhance the test logic to explicitly mention warnings in otherwise passing tests, and not to collapse the log sections for tests with warnings, so that they're more easily seen when scanning the log.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180314/8cb61cd7/attachment.sig>
#5 lore raw

PATCH 1/2 test/py: add MMC/SD block read test

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren

From: Stephen Warren <[email protected]>

Add a standalone MMC block read test. This allows direct testing of MMC access rather than relying on doing so as a side-effect of e.g. DFU or UMS testing, which may not be enabled on all platforms.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180314/17f2f7b8/attachment.sig>