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