Simon Glass | bfb0bb2 | 2019-10-31 07:42:55 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. |
| 4 | # |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 5 | |
| 6 | """Tests for the dtb_platdata module |
| 7 | |
Simon Glass | 70cd0d7 | 2018-07-06 10:27:20 -0600 | [diff] [blame] | 8 | This includes unit tests for some functions and functional tests for the dtoc |
| 9 | tool. |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | import collections |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 13 | import glob |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 14 | import os |
| 15 | import struct |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 16 | import tempfile |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 17 | import unittest |
| 18 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 19 | from dtb_platdata import conv_name_to_c |
| 20 | from dtb_platdata import get_compat_name |
| 21 | from dtb_platdata import get_value |
| 22 | from dtb_platdata import tab_to |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 23 | from dtoc import dtb_platdata |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 24 | from dtoc import fdt |
| 25 | from dtoc import fdt_util |
| 26 | from patman import test_util |
| 27 | from patman import tools |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 28 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 29 | OUR_PATH = os.path.dirname(os.path.realpath(__file__)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 30 | |
| 31 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 32 | HEADER = '''/* |
| 33 | * DO NOT MODIFY |
| 34 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame^] | 35 | * Defines the structs used to hold devicetree data. |
| 36 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | #include <stdbool.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 40 | #include <linux/libfdt.h>''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 41 | |
| 42 | C_HEADER = '''/* |
| 43 | * DO NOT MODIFY |
| 44 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame^] | 45 | * Declares the U_BOOT_DRIVER() records and platform data. |
| 46 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 47 | */ |
| 48 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 49 | /* Allow use of U_BOOT_DRVINFO() in this file */ |
Simon Glass | 4c73d7b | 2020-10-03 11:31:41 -0600 | [diff] [blame] | 50 | #define DT_PLATDATA_C |
| 51 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 52 | #include <common.h> |
| 53 | #include <dm.h> |
| 54 | #include <dt-structs.h> |
| 55 | ''' |
| 56 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 57 | C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) { |
| 58 | } |
| 59 | ''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 60 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 61 | # This is a test so is allowed to access private things in the module it is |
| 62 | # testing |
| 63 | # pylint: disable=W0212 |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 64 | |
| 65 | def get_dtb_file(dts_fname, capture_stderr=False): |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 66 | """Compile a .dts file to a .dtb |
| 67 | |
| 68 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 69 | dts_fname (str): Filename of .dts file in the current directory |
| 70 | capture_stderr (bool): True to capture and discard stderr output |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 71 | |
| 72 | Returns: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 73 | str: Filename of compiled file in output directory |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 74 | """ |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 75 | return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname), |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 76 | capture_stderr=capture_stderr) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class TestDtoc(unittest.TestCase): |
| 80 | """Tests for dtoc""" |
| 81 | @classmethod |
| 82 | def setUpClass(cls): |
| 83 | tools.PrepareOutputDir(None) |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 84 | cls.maxDiff = None |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 85 | |
| 86 | @classmethod |
| 87 | def tearDownClass(cls): |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 88 | tools.FinaliseOutputDir() |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 89 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 90 | @staticmethod |
| 91 | def _write_python_string(fname, data): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 92 | """Write a string with tabs expanded as done in this Python file |
| 93 | |
| 94 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 95 | fname (str): Filename to write to |
| 96 | data (str): Raw string to convert |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 97 | """ |
| 98 | data = data.replace('\t', '\\t') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 99 | with open(fname, 'w') as fout: |
| 100 | fout.write(data) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 101 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 102 | def _check_strings(self, expected, actual): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 103 | """Check that a string matches its expected value |
| 104 | |
| 105 | If the strings do not match, they are written to the /tmp directory in |
| 106 | the same Python format as is used here in the test. This allows for |
| 107 | easy comparison and update of the tests. |
| 108 | |
| 109 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 110 | expected (str): Expected string |
| 111 | actual (str): Actual string |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 112 | """ |
| 113 | if expected != actual: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 114 | self._write_python_string('/tmp/binman.expected', expected) |
| 115 | self._write_python_string('/tmp/binman.actual', actual) |
Simon Glass | 61b88e5 | 2019-05-17 22:00:31 -0600 | [diff] [blame] | 116 | print('Failures written to /tmp/binman.{expected,actual}') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 117 | self.assertEqual(expected, actual) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 118 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 119 | @staticmethod |
| 120 | def run_test(args, dtb_file, output): |
| 121 | """Run a test using dtoc |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 122 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 123 | Args: |
| 124 | args (list of str): List of arguments for dtoc |
| 125 | dtb_file (str): Filename of .dtb file |
| 126 | output (str): Filename of output file |
| 127 | """ |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 128 | dtb_platdata.run_steps(args, dtb_file, False, output, [], True) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 129 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 130 | def test_name(self): |
| 131 | """Test conversion of device tree names to C identifiers""" |
| 132 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 133 | self.assertEqual('vendor_clock_frequency', |
| 134 | conv_name_to_c('vendor,clock-frequency')) |
| 135 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 136 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 137 | |
| 138 | def test_tab_to(self): |
| 139 | """Test operation of tab_to() function""" |
| 140 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 141 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 142 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 143 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 144 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 145 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 146 | |
| 147 | def test_get_value(self): |
| 148 | """Test operation of get_value() function""" |
| 149 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 150 | get_value(fdt.Type.INT, struct.pack('>I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 151 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 152 | get_value(fdt.Type.BYTE, struct.pack('<I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 153 | self.assertEqual('0x0', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 154 | get_value(fdt.Type.BYTE, struct.pack('>I', 0x45))) |
| 155 | self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test')) |
| 156 | self.assertEqual('true', get_value(fdt.Type.BOOL, None)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 157 | |
| 158 | def test_get_compat_name(self): |
| 159 | """Test operation of get_compat_name() function""" |
| 160 | Prop = collections.namedtuple('Prop', ['value']) |
| 161 | Node = collections.namedtuple('Node', ['props']) |
| 162 | |
| 163 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 164 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 165 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 166 | get_compat_name(node)) |
| 167 | |
| 168 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 169 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 170 | self.assertEqual((['rockchip_rk3399_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 171 | get_compat_name(node)) |
| 172 | |
| 173 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 174 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 175 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 176 | 'arasan_sdhci_5_1', 'third']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 177 | get_compat_name(node)) |
| 178 | |
| 179 | def test_empty_file(self): |
| 180 | """Test output from a device tree file with no nodes""" |
| 181 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
| 182 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 183 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 184 | with open(output) as infile: |
| 185 | lines = infile.read().splitlines() |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 186 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 187 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 188 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 189 | with open(output) as infile: |
| 190 | lines = infile.read().splitlines() |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 191 | self.assertEqual(C_HEADER.splitlines() + [''] + |
| 192 | C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 193 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 194 | struct_text = HEADER + ''' |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 195 | struct dtd_sandbox_i2c_test { |
| 196 | }; |
| 197 | struct dtd_sandbox_pmic_test { |
| 198 | \tbool\t\tlow_power; |
| 199 | \tfdt64_t\t\treg[2]; |
| 200 | }; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 201 | struct dtd_sandbox_spl_test { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 202 | \tconst char * acpi_name; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 203 | \tbool\t\tboolval; |
| 204 | \tunsigned char\tbytearray[3]; |
| 205 | \tunsigned char\tbyteval; |
| 206 | \tfdt32_t\t\tintarray[4]; |
| 207 | \tfdt32_t\t\tintval; |
| 208 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 9c52633 | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 209 | \tunsigned char\tnotstring[5]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 210 | \tconst char *\tstringarray[3]; |
| 211 | \tconst char *\tstringval; |
| 212 | }; |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 213 | ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 214 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 215 | platdata_text = C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 216 | /* Node /i2c@0 index 0 */ |
| 217 | static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { |
| 218 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 219 | U_BOOT_DRVINFO(i2c_at_0) = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 220 | \t.name\t\t= "sandbox_i2c_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 221 | \t.plat\t= &dtv_i2c_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 222 | \t.plat_size\t= sizeof(dtv_i2c_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 223 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | /* Node /i2c@0/pmic@9 index 1 */ |
| 227 | static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { |
| 228 | \t.low_power\t\t= true, |
| 229 | \t.reg\t\t\t= {0x9, 0x0}, |
| 230 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 231 | U_BOOT_DRVINFO(pmic_at_9) = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 232 | \t.name\t\t= "sandbox_pmic_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 233 | \t.plat\t= &dtv_pmic_at_9, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 234 | \t.plat_size\t= sizeof(dtv_pmic_at_9), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 235 | \t.parent_idx\t= 0, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | /* Node /spl-test index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 239 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 240 | \t.boolval\t\t= true, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 241 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 242 | \t.byteval\t\t= 0x5, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 243 | \t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 244 | \t.intval\t\t\t= 0x1, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 245 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 246 | \t\t0x11}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 247 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 248 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 249 | \t.stringval\t\t= "message", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 250 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 251 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 252 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 253 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 254 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 255 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 256 | }; |
| 257 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 258 | /* Node /spl-test2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 259 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 260 | \t.acpi_name\t\t= "\\\\_SB.GPO0", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 261 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 262 | \t.byteval\t\t= 0x8, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 263 | \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 264 | \t.intval\t\t\t= 0x3, |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 265 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 266 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 267 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 268 | \t.stringval\t\t= "message2", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 269 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 270 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 271 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 272 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 273 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 274 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 275 | }; |
| 276 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 277 | /* Node /spl-test3 index 4 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 278 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 279 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 280 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 281 | \t.stringarray\t\t= {"one", "", ""}, |
| 282 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 283 | U_BOOT_DRVINFO(spl_test3) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 284 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 285 | \t.plat\t= &dtv_spl_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 286 | \t.plat_size\t= sizeof(dtv_spl_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 287 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 288 | }; |
| 289 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 290 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA |
| 291 | |
| 292 | def test_simple(self): |
| 293 | """Test output from some simple nodes with various types of data""" |
| 294 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 295 | output = tools.GetOutputFilename('output') |
| 296 | self.run_test(['struct'], dtb_file, output) |
| 297 | with open(output) as infile: |
| 298 | data = infile.read() |
| 299 | |
| 300 | self._check_strings(self.struct_text, data) |
| 301 | |
| 302 | self.run_test(['platdata'], dtb_file, output) |
| 303 | with open(output) as infile: |
| 304 | data = infile.read() |
| 305 | |
| 306 | self._check_strings(self.platdata_text, data) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 307 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 308 | # Try the 'all' command |
| 309 | self.run_test(['all'], dtb_file, output) |
| 310 | data = tools.ReadFile(output, binary=False) |
| 311 | self._check_strings(self.platdata_text + self.struct_text, data) |
| 312 | |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 313 | def test_driver_alias(self): |
| 314 | """Test output from a device tree file with a driver alias""" |
| 315 | dtb_file = get_dtb_file('dtoc_test_driver_alias.dts') |
| 316 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 317 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 318 | with open(output) as infile: |
| 319 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 320 | self._check_strings(HEADER + ''' |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 321 | struct dtd_sandbox_gpio { |
| 322 | \tconst char *\tgpio_bank_name; |
| 323 | \tbool\t\tgpio_controller; |
| 324 | \tfdt32_t\t\tsandbox_gpio_count; |
| 325 | }; |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 326 | ''', data) |
| 327 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 328 | self.run_test(['platdata'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 329 | with open(output) as infile: |
| 330 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 331 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 332 | /* Node /gpios@0 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 333 | static struct dtd_sandbox_gpio dtv_gpios_at_0 = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 334 | \t.gpio_bank_name\t\t= "a", |
| 335 | \t.gpio_controller\t= true, |
| 336 | \t.sandbox_gpio_count\t= 0x14, |
| 337 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 338 | U_BOOT_DRVINFO(gpios_at_0) = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 339 | \t.name\t\t= "sandbox_gpio", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 340 | \t.plat\t= &dtv_gpios_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 341 | \t.plat_size\t= sizeof(dtv_gpios_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 342 | \t.parent_idx\t= -1, |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 343 | }; |
| 344 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 345 | void dm_populate_phandle_data(void) { |
| 346 | } |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 347 | ''', data) |
| 348 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 349 | def test_invalid_driver(self): |
| 350 | """Test output from a device tree file with an invalid driver""" |
| 351 | dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') |
| 352 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 353 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 354 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, []) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 355 | with open(output) as infile: |
| 356 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 357 | self._check_strings(HEADER + ''' |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 358 | struct dtd_invalid { |
| 359 | }; |
| 360 | ''', data) |
| 361 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 362 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 363 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output, []) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 364 | with open(output) as infile: |
| 365 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 366 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 367 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 368 | static struct dtd_invalid dtv_spl_test = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 369 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 370 | U_BOOT_DRVINFO(spl_test) = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 371 | \t.name\t\t= "invalid", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 372 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 373 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 374 | \t.parent_idx\t= -1, |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 375 | }; |
| 376 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 377 | void dm_populate_phandle_data(void) { |
| 378 | } |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 379 | ''', data) |
| 380 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 381 | def test_phandle(self): |
| 382 | """Test output from a node containing a phandle reference""" |
| 383 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
| 384 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 385 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 386 | with open(output) as infile: |
| 387 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 388 | self._check_strings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 389 | struct dtd_source { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 390 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 391 | }; |
| 392 | struct dtd_target { |
| 393 | \tfdt32_t\t\tintval; |
| 394 | }; |
| 395 | ''', data) |
| 396 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 397 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 398 | with open(output) as infile: |
| 399 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 400 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 401 | /* Node /phandle2-target index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 402 | static struct dtd_target dtv_phandle2_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 403 | \t.intval\t\t\t= 0x1, |
| 404 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 405 | U_BOOT_DRVINFO(phandle2_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 406 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 407 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 408 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 409 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 410 | }; |
| 411 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 412 | /* Node /phandle3-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 413 | static struct dtd_target dtv_phandle3_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 414 | \t.intval\t\t\t= 0x2, |
| 415 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 416 | U_BOOT_DRVINFO(phandle3_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 417 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 418 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 419 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 420 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 421 | }; |
| 422 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 423 | /* Node /phandle-target index 4 */ |
| 424 | static struct dtd_target dtv_phandle_target = { |
| 425 | \t.intval\t\t\t= 0x0, |
| 426 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 427 | U_BOOT_DRVINFO(phandle_target) = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 428 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 429 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 430 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 431 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | /* Node /phandle-source index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 435 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | d0cd075 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 436 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 437 | \t\t\t{4, {}}, |
| 438 | \t\t\t{0, {11}}, |
| 439 | \t\t\t{1, {12, 13}}, |
| 440 | \t\t\t{4, {}},}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 441 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 442 | U_BOOT_DRVINFO(phandle_source) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 443 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 444 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 445 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 446 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 447 | }; |
| 448 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 449 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 450 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 451 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 452 | \t\t\t{4, {}},}, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 453 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 454 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 455 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 456 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 457 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 458 | \t.parent_idx\t= -1, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 459 | }; |
| 460 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 461 | void dm_populate_phandle_data(void) { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 462 | } |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 463 | ''', data) |
| 464 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 465 | def test_phandle_single(self): |
| 466 | """Test output from a node containing a phandle reference""" |
| 467 | dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') |
| 468 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 469 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 470 | with open(output) as infile: |
| 471 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 472 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 473 | struct dtd_source { |
| 474 | \tstruct phandle_0_arg clocks[1]; |
| 475 | }; |
| 476 | struct dtd_target { |
| 477 | \tfdt32_t\t\tintval; |
| 478 | }; |
| 479 | ''', data) |
| 480 | |
| 481 | def test_phandle_reorder(self): |
| 482 | """Test that phandle targets are generated before their references""" |
| 483 | dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') |
| 484 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 485 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 486 | with open(output) as infile: |
| 487 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 488 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 489 | /* Node /phandle-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 490 | static struct dtd_target dtv_phandle_target = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 491 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 492 | U_BOOT_DRVINFO(phandle_target) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 493 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 494 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 495 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 496 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 497 | }; |
| 498 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 499 | /* Node /phandle-source2 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 500 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 501 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 502 | \t\t\t{1, {}},}, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 503 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 504 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 505 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 506 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 507 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 508 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 509 | }; |
| 510 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 511 | void dm_populate_phandle_data(void) { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 512 | } |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 513 | ''', data) |
| 514 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 515 | def test_phandle_cd_gpio(self): |
| 516 | """Test that phandle targets are generated when unsing cd-gpios""" |
| 517 | dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') |
| 518 | output = tools.GetOutputFilename('output') |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 519 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True) |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 520 | with open(output) as infile: |
| 521 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 522 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 523 | /* Node /phandle2-target index 0 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 524 | static struct dtd_target dtv_phandle2_target = { |
| 525 | \t.intval\t\t\t= 0x1, |
| 526 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 527 | U_BOOT_DRVINFO(phandle2_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 528 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 529 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 530 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 531 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 532 | }; |
| 533 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 534 | /* Node /phandle3-target index 1 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 535 | static struct dtd_target dtv_phandle3_target = { |
| 536 | \t.intval\t\t\t= 0x2, |
| 537 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 538 | U_BOOT_DRVINFO(phandle3_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 539 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 540 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 541 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 542 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 543 | }; |
| 544 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 545 | /* Node /phandle-target index 4 */ |
| 546 | static struct dtd_target dtv_phandle_target = { |
| 547 | \t.intval\t\t\t= 0x0, |
| 548 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 549 | U_BOOT_DRVINFO(phandle_target) = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 550 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 551 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 552 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 553 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | /* Node /phandle-source index 2 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 557 | static struct dtd_source dtv_phandle_source = { |
| 558 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 559 | \t\t\t{4, {}}, |
| 560 | \t\t\t{0, {11}}, |
| 561 | \t\t\t{1, {12, 13}}, |
| 562 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 563 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 564 | U_BOOT_DRVINFO(phandle_source) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 565 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 566 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 567 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 568 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 569 | }; |
| 570 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 571 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 572 | static struct dtd_source dtv_phandle_source2 = { |
| 573 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 574 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 575 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 576 | U_BOOT_DRVINFO(phandle_source2) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 577 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 578 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 579 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 580 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | void dm_populate_phandle_data(void) { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 584 | } |
| 585 | ''', data) |
| 586 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 587 | def test_phandle_bad(self): |
| 588 | """Test a node containing an invalid phandle fails""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 589 | dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', |
| 590 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 591 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 592 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 593 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 594 | self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 595 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 596 | |
| 597 | def test_phandle_bad2(self): |
| 598 | """Test a phandle target missing its #*-cells property""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 599 | dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', |
| 600 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 601 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 602 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 603 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | 179f0b6 | 2020-06-25 01:10:16 -0300 | [diff] [blame] | 604 | self.assertIn("Node 'phandle-target' has no cells property", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 605 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 606 | |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 607 | def test_addresses64(self): |
| 608 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 609 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
| 610 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 611 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 612 | with open(output) as infile: |
| 613 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 614 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 615 | struct dtd_test1 { |
| 616 | \tfdt64_t\t\treg[2]; |
| 617 | }; |
| 618 | struct dtd_test2 { |
| 619 | \tfdt64_t\t\treg[2]; |
| 620 | }; |
| 621 | struct dtd_test3 { |
| 622 | \tfdt64_t\t\treg[4]; |
| 623 | }; |
| 624 | ''', data) |
| 625 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 626 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 627 | with open(output) as infile: |
| 628 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 629 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 630 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 631 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 632 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 633 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 634 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 635 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 636 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 637 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 638 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 639 | }; |
| 640 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 641 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 642 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 643 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 644 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 645 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 646 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 647 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 648 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 649 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 650 | }; |
| 651 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 652 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 653 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 654 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 655 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 656 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 657 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 658 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 659 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 660 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 661 | }; |
| 662 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 663 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 664 | |
| 665 | def test_addresses32(self): |
| 666 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 667 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
| 668 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 669 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 670 | with open(output) as infile: |
| 671 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 672 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 673 | struct dtd_test1 { |
| 674 | \tfdt32_t\t\treg[2]; |
| 675 | }; |
| 676 | struct dtd_test2 { |
| 677 | \tfdt32_t\t\treg[4]; |
| 678 | }; |
| 679 | ''', data) |
| 680 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 681 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 682 | with open(output) as infile: |
| 683 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 684 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 685 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 686 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 687 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 688 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 689 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 690 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 691 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 692 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 693 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 694 | }; |
| 695 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 696 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 697 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 698 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 699 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 700 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 701 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 702 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 703 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 704 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 705 | }; |
| 706 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 707 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 708 | |
| 709 | def test_addresses64_32(self): |
| 710 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 711 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
| 712 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 713 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 714 | with open(output) as infile: |
| 715 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 716 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 717 | struct dtd_test1 { |
| 718 | \tfdt64_t\t\treg[2]; |
| 719 | }; |
| 720 | struct dtd_test2 { |
| 721 | \tfdt64_t\t\treg[2]; |
| 722 | }; |
| 723 | struct dtd_test3 { |
| 724 | \tfdt64_t\t\treg[4]; |
| 725 | }; |
| 726 | ''', data) |
| 727 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 728 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 729 | with open(output) as infile: |
| 730 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 731 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 732 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 733 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 734 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 735 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 736 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 737 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 738 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 739 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 740 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 741 | }; |
| 742 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 743 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 744 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 745 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 746 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 747 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 748 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 749 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 750 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 751 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 752 | }; |
| 753 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 754 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 755 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 756 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 757 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 758 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 759 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 760 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 761 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 762 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 763 | }; |
| 764 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 765 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 766 | |
| 767 | def test_addresses32_64(self): |
| 768 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 769 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
| 770 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 771 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 772 | with open(output) as infile: |
| 773 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 774 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 775 | struct dtd_test1 { |
| 776 | \tfdt64_t\t\treg[2]; |
| 777 | }; |
| 778 | struct dtd_test2 { |
| 779 | \tfdt64_t\t\treg[2]; |
| 780 | }; |
| 781 | struct dtd_test3 { |
| 782 | \tfdt64_t\t\treg[4]; |
| 783 | }; |
| 784 | ''', data) |
| 785 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 786 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 787 | with open(output) as infile: |
| 788 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 789 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 790 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 791 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 792 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 793 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 794 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 795 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 796 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 797 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 798 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 799 | }; |
| 800 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 801 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 802 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 803 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 804 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 805 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 806 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 807 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 808 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 809 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 810 | }; |
| 811 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 812 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 813 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 814 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 815 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 816 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 817 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 818 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 819 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 820 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 821 | }; |
| 822 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 823 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 824 | |
| 825 | def test_bad_reg(self): |
| 826 | """Test that a reg property with an invalid type generates an error""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 827 | # Capture stderr since dtc will emit warnings for this file |
| 828 | dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 829 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 830 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 831 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 832 | self.assertIn("Node 'spl-test' reg property is not an int", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 833 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 834 | |
| 835 | def test_bad_reg2(self): |
| 836 | """Test that a reg property with an invalid cell count is detected""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 837 | # Capture stderr since dtc will emit warnings for this file |
| 838 | dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 839 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 840 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 841 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 842 | self.assertIn( |
| 843 | "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", |
| 844 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 845 | |
| 846 | def test_add_prop(self): |
| 847 | """Test that a subequent node can add a new property to a struct""" |
| 848 | dtb_file = get_dtb_file('dtoc_test_add_prop.dts') |
| 849 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 850 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 851 | with open(output) as infile: |
| 852 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 853 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 854 | struct dtd_sandbox_spl_test { |
| 855 | \tfdt32_t\t\tintarray; |
| 856 | \tfdt32_t\t\tintval; |
| 857 | }; |
| 858 | ''', data) |
| 859 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 860 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 861 | with open(output) as infile: |
| 862 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 863 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 864 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 865 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 866 | \t.intval\t\t\t= 0x1, |
| 867 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 868 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 869 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 870 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 871 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 872 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 873 | }; |
| 874 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 875 | /* Node /spl-test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 876 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 877 | \t.intarray\t\t= 0x5, |
| 878 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 879 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 880 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 881 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 882 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 883 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 884 | }; |
| 885 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 886 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 887 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 888 | def test_stdout(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 889 | """Test output to stdout""" |
| 890 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 891 | with test_util.capture_sys_output() as (stdout, _): |
Simon Glass | 6ca0c7a | 2020-12-28 20:34:48 -0700 | [diff] [blame] | 892 | self.run_test(['struct'], dtb_file, None) |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 893 | self._check_strings(self.struct_text, stdout.getvalue()) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 894 | |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 895 | def test_multi_to_file(self): |
| 896 | """Test output of multiple pieces to a single file""" |
| 897 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 898 | output = tools.GetOutputFilename('output') |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 899 | self.run_test(['all'], dtb_file, output) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 900 | data = tools.ReadFile(output, binary=False) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 901 | self._check_strings(self.platdata_text + self.struct_text, data) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 902 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 903 | def test_no_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 904 | """Test running dtoc without a command""" |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 905 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 906 | self.run_test([], '', '') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 907 | self.assertIn("Please specify a command: struct, platdata", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 908 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 909 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 910 | def test_bad_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 911 | """Test running dtoc with an invalid command""" |
| 912 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 913 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 914 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 915 | self.run_test(['invalid-cmd'], dtb_file, output) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 916 | self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 917 | str(exc.exception)) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 918 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 919 | @staticmethod |
| 920 | def test_scan_drivers(): |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 921 | """Test running dtoc with additional drivers to scan""" |
| 922 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 923 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 924 | with test_util.capture_sys_output() as _: |
| 925 | dtb_platdata.run_steps( |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 926 | ['struct'], dtb_file, False, output, [], True, |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 927 | [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 928 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 929 | @staticmethod |
| 930 | def test_unicode_error(): |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 931 | """Test running dtoc with an invalid unicode file |
| 932 | |
| 933 | To be able to perform this test without adding a weird text file which |
| 934 | would produce issues when using checkpatch.pl or patman, generate the |
| 935 | file at runtime and then process it. |
| 936 | """ |
| 937 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 938 | output = tools.GetOutputFilename('output') |
| 939 | driver_fn = '/tmp/' + next(tempfile._get_candidate_names()) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 940 | with open(driver_fn, 'wb+') as fout: |
| 941 | fout.write(b'\x81') |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 942 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 943 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 944 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], |
| 945 | True, [driver_fn]) |
Simon Glass | b42ed51 | 2020-12-23 08:11:23 -0700 | [diff] [blame] | 946 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 947 | def test_driver(self): |
Simon Glass | b42ed51 | 2020-12-23 08:11:23 -0700 | [diff] [blame] | 948 | """Test the Driver class""" |
| 949 | drv1 = dtb_platdata.Driver('fred') |
| 950 | drv2 = dtb_platdata.Driver('mary') |
| 951 | drv3 = dtb_platdata.Driver('fred') |
| 952 | self.assertEqual("Driver(name='fred')", str(drv1)) |
| 953 | self.assertEqual(drv1, drv3) |
| 954 | self.assertNotEqual(drv1, drv2) |
| 955 | self.assertNotEqual(drv2, drv3) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 956 | |
| 957 | def test_output_conflict(self): |
| 958 | """Test a conflict between and output dirs and output file""" |
| 959 | with self.assertRaises(ValueError) as exc: |
| 960 | dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True) |
| 961 | self.assertIn("Must specify either output or output_dirs, not both", |
| 962 | str(exc.exception)) |
| 963 | |
| 964 | def test_output_dirs(self): |
| 965 | """Test outputting files to a directory""" |
| 966 | # Remove the directory so that files from other tests are not there |
| 967 | tools._RemoveOutputDir() |
| 968 | tools.PrepareOutputDir(None) |
| 969 | |
| 970 | # This should create the .dts and .dtb in the output directory |
| 971 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 972 | outdir = tools.GetOutputDir() |
| 973 | fnames = glob.glob(outdir + '/*') |
| 974 | self.assertEqual(2, len(fnames)) |
| 975 | |
| 976 | dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True) |
| 977 | fnames = glob.glob(outdir + '/*') |
| 978 | self.assertEqual(4, len(fnames)) |
| 979 | |
| 980 | leafs = set(os.path.basename(fname) for fname in fnames) |
| 981 | self.assertEqual( |
| 982 | {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'}, |
| 983 | leafs) |