fdt: Fix alignment issue when reading 64-bits properties from fdt
[oweals/u-boot.git] / test / py / tests / test_mmc_wr.py
1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2019, Texas Instrument
3 # Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
4
5 # Test U-Boot's "mmc write" command. The test generates random data, writes it
6 # to the eMMC or SD card, then reads it back and performs a comparison.
7
8 import pytest
9 import u_boot_utils
10
11 """
12 This test relies on boardenv_* to containing configuration values to define
13 which MMC devices should be tested. For example:
14
15 env__mmc_wr_configs = (
16     {
17         "fixture_id": "emmc-boot0",
18         "is_emmc": True,
19         "devid": 1,
20         "partid": 1,
21         "sector": 0x10,
22         "count": 100,
23         "test_iterations": 50,
24     },
25     {
26         "fixture_id": "emmc-boot1",
27         "is_emmc": True,
28         "devid": 1,
29         "partid": 2,
30         "sector": 0x10,
31         "count": 100,
32         "test_iterations": 50,
33     },
34 )
35
36 """
37
38 @pytest.mark.buildconfigspec('cmd_mmc','cmd_memory', 'cmd_random')
39 def test_mmc_wr(u_boot_console, env__mmc_wr_config):
40     """Test the "mmc write" command.
41
42     Args:
43         u_boot_console: A U-Boot console connection.
44         env__mmc_wr_config: The single MMC configuration on which
45             to run the test. See the file-level comment above for details
46             of the format.
47
48     Returns:
49         Nothing.
50     """
51
52     is_emmc = env__mmc_wr_config['is_emmc']
53     devid = env__mmc_wr_config['devid']
54     partid = env__mmc_wr_config.get('partid', 0)
55     sector = env__mmc_wr_config.get('sector', 0)
56     count_sectors = env__mmc_wr_config.get('count', 1)
57     test_iterations = env__mmc_wr_config.get('test_iterations', 1)
58
59
60     count_bytes = count_sectors * 512
61     bcfg = u_boot_console.config.buildconfig
62     ram_base = u_boot_utils.find_ram_base(u_boot_console)
63     src_addr = '0x%08x' % ram_base
64     dst_addr = '0x%08x' % (ram_base + count_bytes)
65
66
67     for i in range(test_iterations):
68         # Generate random data
69         cmd = 'random %s %x' % (src_addr, count_bytes)
70         response = u_boot_console.run_command(cmd)
71         good_response = '%d bytes filled with random data' % (count_bytes)
72         assert good_response in response
73
74         # Select MMC device
75         cmd = 'mmc dev %d' % devid
76         if is_emmc:
77                 cmd += ' %d' % partid
78         response = u_boot_console.run_command(cmd)
79         assert 'no card present' not in response
80         if is_emmc:
81                 partid_response = "(part %d)" % partid
82         else:
83                 partid_response = ""
84         good_response = 'mmc%d%s is current device' % (devid, partid_response)
85         assert good_response in response
86
87         # Write data
88         cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
89         response = u_boot_console.run_command(cmd)
90         good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (
91                 devid, sector, count_sectors, count_sectors)
92         assert good_response in response
93
94         # Read data
95         cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
96         response = u_boot_console.run_command(cmd)
97         good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
98                 devid, sector, count_sectors, count_sectors)
99         assert good_response in response
100
101         # Compare src and dst data
102         cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
103         response = u_boot_console.run_command(cmd)
104         good_response = 'Total of %d byte(s) were the same' % (count_bytes)
105         assert good_response in response