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