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