blob: c517fd5c4ef039391515f67555039fe5471714a0 [file] [log] [blame]
Simon Glass3c19dc82019-10-31 07:42:55 -06001#!/usr/bin/env python3
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glassc0791922017-06-18 22:09:06 -06003# Copyright (c) 2012 The Chromium OS Authors.
4#
Simon Glassc0791922017-06-18 22:09:06 -06005
6"""Tests for the dtb_platdata module
7
Simon Glass3def0cf2018-07-06 10:27:20 -06008This includes unit tests for some functions and functional tests for the dtoc
9tool.
Simon Glassc0791922017-06-18 22:09:06 -060010"""
11
12import collections
Simon Glass10cbd3b2020-12-28 20:34:52 -070013import glob
Simon Glassc0791922017-06-18 22:09:06 -060014import os
Simon Glass1e0f3f42020-12-28 20:35:03 -070015import shutil
Simon Glassc0791922017-06-18 22:09:06 -060016import struct
Walter Lozano6c74d1b2020-07-28 19:06:23 -030017import tempfile
Simon Glassc0791922017-06-18 22:09:06 -060018import unittest
Simon Glass1e0f3f42020-12-28 20:35:03 -070019from unittest import mock
Simon Glassc0791922017-06-18 22:09:06 -060020
Simon Glassc0791922017-06-18 22:09:06 -060021from dtb_platdata import conv_name_to_c
22from dtb_platdata import get_compat_name
23from dtb_platdata import get_value
24from dtb_platdata import tab_to
Simon Glass67b5ec52020-12-28 20:34:47 -070025from dtoc import dtb_platdata
Simon Glassbf776672020-04-17 18:09:04 -060026from dtoc import fdt
27from dtoc import fdt_util
28from patman import test_util
29from patman import tools
Simon Glassc0791922017-06-18 22:09:06 -060030
Simon Glass67b5ec52020-12-28 20:34:47 -070031OUR_PATH = os.path.dirname(os.path.realpath(__file__))
Simon Glassc0791922017-06-18 22:09:06 -060032
33
Simon Glassaab660f2017-11-12 21:52:17 -070034HEADER = '''/*
35 * DO NOT MODIFY
36 *
Simon Glassd1055d62020-12-28 20:35:00 -070037 * Defines the structs used to hold devicetree data.
38 * This was generated by dtoc from a .dtb (device tree binary) file.
Simon Glassaab660f2017-11-12 21:52:17 -070039 */
40
41#include <stdbool.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090042#include <linux/libfdt.h>'''
Simon Glassaab660f2017-11-12 21:52:17 -070043
44C_HEADER = '''/*
45 * DO NOT MODIFY
46 *
Simon Glassd1055d62020-12-28 20:35:00 -070047 * Declares the U_BOOT_DRIVER() records and platform data.
48 * This was generated by dtoc from a .dtb (device tree binary) file.
Simon Glassaab660f2017-11-12 21:52:17 -070049 */
50
Simon Glass20e442a2020-12-28 20:34:54 -070051/* Allow use of U_BOOT_DRVINFO() in this file */
Simon Glassf31fa992020-12-28 20:35:01 -070052#define DT_PLAT_C
Simon Glasscb43ac12020-10-03 11:31:41 -060053
Simon Glassaab660f2017-11-12 21:52:17 -070054#include <common.h>
55#include <dm.h>
56#include <dt-structs.h>
57'''
58
Walter Lozano51f12632020-06-25 01:10:13 -030059C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
60}
61'''
Simon Glassaab660f2017-11-12 21:52:17 -070062
Simon Glass67b5ec52020-12-28 20:34:47 -070063# This is a test so is allowed to access private things in the module it is
64# testing
65# pylint: disable=W0212
Simon Glassfe57c782018-07-06 10:27:37 -060066
67def get_dtb_file(dts_fname, capture_stderr=False):
Simon Glassc0791922017-06-18 22:09:06 -060068 """Compile a .dts file to a .dtb
69
70 Args:
Simon Glass67b5ec52020-12-28 20:34:47 -070071 dts_fname (str): Filename of .dts file in the current directory
72 capture_stderr (bool): True to capture and discard stderr output
Simon Glassc0791922017-06-18 22:09:06 -060073
74 Returns:
Simon Glass67b5ec52020-12-28 20:34:47 -070075 str: Filename of compiled file in output directory
Simon Glassc0791922017-06-18 22:09:06 -060076 """
Simon Glass67b5ec52020-12-28 20:34:47 -070077 return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname),
Simon Glassfe57c782018-07-06 10:27:37 -060078 capture_stderr=capture_stderr)
Simon Glassc0791922017-06-18 22:09:06 -060079
80
81class TestDtoc(unittest.TestCase):
82 """Tests for dtoc"""
83 @classmethod
84 def setUpClass(cls):
85 tools.PrepareOutputDir(None)
Simon Glassf02d0eb2020-07-07 21:32:06 -060086 cls.maxDiff = None
Simon Glassc0791922017-06-18 22:09:06 -060087
88 @classmethod
89 def tearDownClass(cls):
Simon Glass67b5ec52020-12-28 20:34:47 -070090 tools.FinaliseOutputDir()
Simon Glassc0791922017-06-18 22:09:06 -060091
Simon Glass67b5ec52020-12-28 20:34:47 -070092 @staticmethod
93 def _write_python_string(fname, data):
Simon Glass57f0bc42018-07-06 10:27:25 -060094 """Write a string with tabs expanded as done in this Python file
95
96 Args:
Simon Glass67b5ec52020-12-28 20:34:47 -070097 fname (str): Filename to write to
98 data (str): Raw string to convert
Simon Glass57f0bc42018-07-06 10:27:25 -060099 """
100 data = data.replace('\t', '\\t')
Simon Glass67b5ec52020-12-28 20:34:47 -0700101 with open(fname, 'w') as fout:
102 fout.write(data)
Simon Glass57f0bc42018-07-06 10:27:25 -0600103
Simon Glass67b5ec52020-12-28 20:34:47 -0700104 def _check_strings(self, expected, actual):
Simon Glass57f0bc42018-07-06 10:27:25 -0600105 """Check that a string matches its expected value
106
107 If the strings do not match, they are written to the /tmp directory in
108 the same Python format as is used here in the test. This allows for
109 easy comparison and update of the tests.
110
111 Args:
Simon Glass67b5ec52020-12-28 20:34:47 -0700112 expected (str): Expected string
113 actual (str): Actual string
Simon Glass57f0bc42018-07-06 10:27:25 -0600114 """
115 if expected != actual:
Simon Glass67b5ec52020-12-28 20:34:47 -0700116 self._write_python_string('/tmp/binman.expected', expected)
117 self._write_python_string('/tmp/binman.actual', actual)
Simon Glass90a81322019-05-17 22:00:31 -0600118 print('Failures written to /tmp/binman.{expected,actual}')
Simon Glass67b5ec52020-12-28 20:34:47 -0700119 self.assertEqual(expected, actual)
Simon Glass57f0bc42018-07-06 10:27:25 -0600120
Simon Glass67b5ec52020-12-28 20:34:47 -0700121 @staticmethod
122 def run_test(args, dtb_file, output):
123 """Run a test using dtoc
Walter Lozano361e7332020-06-25 01:10:08 -0300124
Simon Glass67b5ec52020-12-28 20:34:47 -0700125 Args:
126 args (list of str): List of arguments for dtoc
127 dtb_file (str): Filename of .dtb file
128 output (str): Filename of output file
129 """
Simon Glass192c1112020-12-28 20:34:50 -0700130 dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
Walter Lozano361e7332020-06-25 01:10:08 -0300131
Simon Glassc0791922017-06-18 22:09:06 -0600132 def test_name(self):
133 """Test conversion of device tree names to C identifiers"""
134 self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12'))
135 self.assertEqual('vendor_clock_frequency',
136 conv_name_to_c('vendor,clock-frequency'))
137 self.assertEqual('rockchip_rk3399_sdhci_5_1',
138 conv_name_to_c('rockchip,rk3399-sdhci-5.1'))
139
140 def test_tab_to(self):
141 """Test operation of tab_to() function"""
142 self.assertEqual('fred ', tab_to(0, 'fred'))
143 self.assertEqual('fred\t', tab_to(1, 'fred'))
144 self.assertEqual('fred was here ', tab_to(1, 'fred was here'))
145 self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here'))
146 self.assertEqual('exactly8 ', tab_to(1, 'exactly8'))
147 self.assertEqual('exactly8\t', tab_to(2, 'exactly8'))
148
149 def test_get_value(self):
150 """Test operation of get_value() function"""
151 self.assertEqual('0x45',
Simon Glass5ea9dcc2020-11-08 20:36:17 -0700152 get_value(fdt.Type.INT, struct.pack('>I', 0x45)))
Simon Glassc0791922017-06-18 22:09:06 -0600153 self.assertEqual('0x45',
Simon Glass5ea9dcc2020-11-08 20:36:17 -0700154 get_value(fdt.Type.BYTE, struct.pack('<I', 0x45)))
Simon Glassc0791922017-06-18 22:09:06 -0600155 self.assertEqual('0x0',
Simon Glass5ea9dcc2020-11-08 20:36:17 -0700156 get_value(fdt.Type.BYTE, struct.pack('>I', 0x45)))
157 self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test'))
158 self.assertEqual('true', get_value(fdt.Type.BOOL, None))
Simon Glassc0791922017-06-18 22:09:06 -0600159
160 def test_get_compat_name(self):
161 """Test operation of get_compat_name() function"""
162 Prop = collections.namedtuple('Prop', ['value'])
163 Node = collections.namedtuple('Node', ['props'])
164
165 prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1'])
166 node = Node({'compatible': prop})
Walter Lozanodcb3ed62020-07-23 00:22:03 -0300167 self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']),
Simon Glassc0791922017-06-18 22:09:06 -0600168 get_compat_name(node))
169
170 prop = Prop(['rockchip,rk3399-sdhci-5.1'])
171 node = Node({'compatible': prop})
Walter Lozanodcb3ed62020-07-23 00:22:03 -0300172 self.assertEqual((['rockchip_rk3399_sdhci_5_1']),
Simon Glassc0791922017-06-18 22:09:06 -0600173 get_compat_name(node))
174
175 prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third'])
176 node = Node({'compatible': prop})
Walter Lozanodcb3ed62020-07-23 00:22:03 -0300177 self.assertEqual((['rockchip_rk3399_sdhci_5_1',
Simon Glass67b5ec52020-12-28 20:34:47 -0700178 'arasan_sdhci_5_1', 'third']),
Simon Glassc0791922017-06-18 22:09:06 -0600179 get_compat_name(node))
180
181 def test_empty_file(self):
182 """Test output from a device tree file with no nodes"""
183 dtb_file = get_dtb_file('dtoc_test_empty.dts')
184 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300185 self.run_test(['struct'], dtb_file, output)
Simon Glassc0791922017-06-18 22:09:06 -0600186 with open(output) as infile:
187 lines = infile.read().splitlines()
Simon Glassaab660f2017-11-12 21:52:17 -0700188 self.assertEqual(HEADER.splitlines(), lines)
Simon Glassc0791922017-06-18 22:09:06 -0600189
Walter Lozano361e7332020-06-25 01:10:08 -0300190 self.run_test(['platdata'], dtb_file, output)
Simon Glassc0791922017-06-18 22:09:06 -0600191 with open(output) as infile:
192 lines = infile.read().splitlines()
Walter Lozano51f12632020-06-25 01:10:13 -0300193 self.assertEqual(C_HEADER.splitlines() + [''] +
194 C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
Simon Glassc0791922017-06-18 22:09:06 -0600195
Simon Glassde846cb2020-12-28 20:34:49 -0700196 struct_text = HEADER + '''
Simon Glass5ec741f2017-08-29 14:15:51 -0600197struct dtd_sandbox_i2c_test {
198};
199struct dtd_sandbox_pmic_test {
200\tbool\t\tlow_power;
201\tfdt64_t\t\treg[2];
202};
Simon Glassc0791922017-06-18 22:09:06 -0600203struct dtd_sandbox_spl_test {
Simon Glassf02d0eb2020-07-07 21:32:06 -0600204\tconst char * acpi_name;
Simon Glassc0791922017-06-18 22:09:06 -0600205\tbool\t\tboolval;
206\tunsigned char\tbytearray[3];
207\tunsigned char\tbyteval;
208\tfdt32_t\t\tintarray[4];
209\tfdt32_t\t\tintval;
210\tunsigned char\tlongbytearray[9];
Simon Glass2a2d91d2018-07-06 10:27:28 -0600211\tunsigned char\tnotstring[5];
Simon Glassc0791922017-06-18 22:09:06 -0600212\tconst char *\tstringarray[3];
213\tconst char *\tstringval;
214};
Simon Glassde846cb2020-12-28 20:34:49 -0700215'''
Simon Glassc0791922017-06-18 22:09:06 -0600216
Simon Glassde846cb2020-12-28 20:34:49 -0700217 platdata_text = C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600218/* Node /i2c@0 index 0 */
219static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
220};
Simon Glass20e442a2020-12-28 20:34:54 -0700221U_BOOT_DRVINFO(i2c_at_0) = {
Simon Glass1b272732020-10-03 11:31:25 -0600222\t.name\t\t= "sandbox_i2c_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700223\t.plat\t= &dtv_i2c_at_0,
Simon Glass4f500862020-12-03 16:55:19 -0700224\t.plat_size\t= sizeof(dtv_i2c_at_0),
Simon Glasse41651f2020-10-03 11:31:35 -0600225\t.parent_idx\t= -1,
Simon Glass1b272732020-10-03 11:31:25 -0600226};
227
228/* Node /i2c@0/pmic@9 index 1 */
229static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
230\t.low_power\t\t= true,
231\t.reg\t\t\t= {0x9, 0x0},
232};
Simon Glass20e442a2020-12-28 20:34:54 -0700233U_BOOT_DRVINFO(pmic_at_9) = {
Simon Glass1b272732020-10-03 11:31:25 -0600234\t.name\t\t= "sandbox_pmic_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700235\t.plat\t= &dtv_pmic_at_9,
Simon Glass4f500862020-12-03 16:55:19 -0700236\t.plat_size\t= sizeof(dtv_pmic_at_9),
Simon Glasse41651f2020-10-03 11:31:35 -0600237\t.parent_idx\t= 0,
Simon Glass1b272732020-10-03 11:31:25 -0600238};
239
240/* Node /spl-test index 2 */
Walter Lozano51f12632020-06-25 01:10:13 -0300241static struct dtd_sandbox_spl_test dtv_spl_test = {
Simon Glass1953ce72019-05-17 22:00:32 -0600242\t.boolval\t\t= true,
Simon Glassc0791922017-06-18 22:09:06 -0600243\t.bytearray\t\t= {0x6, 0x0, 0x0},
244\t.byteval\t\t= 0x5,
Simon Glass1953ce72019-05-17 22:00:32 -0600245\t.intarray\t\t= {0x2, 0x3, 0x4, 0x0},
Simon Glassc0791922017-06-18 22:09:06 -0600246\t.intval\t\t\t= 0x1,
Simon Glass21d54ac2017-08-29 14:15:49 -0600247\t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
248\t\t0x11},
Simon Glass1953ce72019-05-17 22:00:32 -0600249\t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0},
Simon Glassc0791922017-06-18 22:09:06 -0600250\t.stringarray\t\t= {"multi-word", "message", ""},
Simon Glass1953ce72019-05-17 22:00:32 -0600251\t.stringval\t\t= "message",
Simon Glassc0791922017-06-18 22:09:06 -0600252};
Simon Glass20e442a2020-12-28 20:34:54 -0700253U_BOOT_DRVINFO(spl_test) = {
Simon Glassc0791922017-06-18 22:09:06 -0600254\t.name\t\t= "sandbox_spl_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700255\t.plat\t= &dtv_spl_test,
Simon Glass4f500862020-12-03 16:55:19 -0700256\t.plat_size\t= sizeof(dtv_spl_test),
Simon Glasse41651f2020-10-03 11:31:35 -0600257\t.parent_idx\t= -1,
Simon Glassc0791922017-06-18 22:09:06 -0600258};
259
Simon Glass1b272732020-10-03 11:31:25 -0600260/* Node /spl-test2 index 3 */
Walter Lozano51f12632020-06-25 01:10:13 -0300261static struct dtd_sandbox_spl_test dtv_spl_test2 = {
Simon Glassf02d0eb2020-07-07 21:32:06 -0600262\t.acpi_name\t\t= "\\\\_SB.GPO0",
Simon Glassc0791922017-06-18 22:09:06 -0600263\t.bytearray\t\t= {0x1, 0x23, 0x34},
264\t.byteval\t\t= 0x8,
Simon Glass1953ce72019-05-17 22:00:32 -0600265\t.intarray\t\t= {0x5, 0x0, 0x0, 0x0},
Simon Glassc0791922017-06-18 22:09:06 -0600266\t.intval\t\t\t= 0x3,
Simon Glasse144caf2020-10-03 11:31:27 -0600267\t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0,
Simon Glass21d54ac2017-08-29 14:15:49 -0600268\t\t0x0},
Simon Glassc0791922017-06-18 22:09:06 -0600269\t.stringarray\t\t= {"another", "multi-word", "message"},
Simon Glass1953ce72019-05-17 22:00:32 -0600270\t.stringval\t\t= "message2",
Simon Glassc0791922017-06-18 22:09:06 -0600271};
Simon Glass20e442a2020-12-28 20:34:54 -0700272U_BOOT_DRVINFO(spl_test2) = {
Simon Glassc0791922017-06-18 22:09:06 -0600273\t.name\t\t= "sandbox_spl_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700274\t.plat\t= &dtv_spl_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700275\t.plat_size\t= sizeof(dtv_spl_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600276\t.parent_idx\t= -1,
Simon Glassc0791922017-06-18 22:09:06 -0600277};
278
Simon Glass1b272732020-10-03 11:31:25 -0600279/* Node /spl-test3 index 4 */
Walter Lozano51f12632020-06-25 01:10:13 -0300280static struct dtd_sandbox_spl_test dtv_spl_test3 = {
Simon Glasse144caf2020-10-03 11:31:27 -0600281\t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
282\t\t0x0},
Simon Glassc0791922017-06-18 22:09:06 -0600283\t.stringarray\t\t= {"one", "", ""},
284};
Simon Glass20e442a2020-12-28 20:34:54 -0700285U_BOOT_DRVINFO(spl_test3) = {
Simon Glassc0791922017-06-18 22:09:06 -0600286\t.name\t\t= "sandbox_spl_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700287\t.plat\t= &dtv_spl_test3,
Simon Glass4f500862020-12-03 16:55:19 -0700288\t.plat_size\t= sizeof(dtv_spl_test3),
Simon Glasse41651f2020-10-03 11:31:35 -0600289\t.parent_idx\t= -1,
Simon Glassc0791922017-06-18 22:09:06 -0600290};
291
Simon Glassde846cb2020-12-28 20:34:49 -0700292''' + C_EMPTY_POPULATE_PHANDLE_DATA
293
294 def test_simple(self):
295 """Test output from some simple nodes with various types of data"""
296 dtb_file = get_dtb_file('dtoc_test_simple.dts')
297 output = tools.GetOutputFilename('output')
298 self.run_test(['struct'], dtb_file, output)
299 with open(output) as infile:
300 data = infile.read()
301
302 self._check_strings(self.struct_text, data)
303
304 self.run_test(['platdata'], dtb_file, output)
305 with open(output) as infile:
306 data = infile.read()
307
308 self._check_strings(self.platdata_text, data)
Simon Glassc0791922017-06-18 22:09:06 -0600309
Simon Glass10cbd3b2020-12-28 20:34:52 -0700310 # Try the 'all' command
311 self.run_test(['all'], dtb_file, output)
312 data = tools.ReadFile(output, binary=False)
313 self._check_strings(self.platdata_text + self.struct_text, data)
314
Walter Lozanodac82282020-07-03 08:07:17 -0300315 def test_driver_alias(self):
316 """Test output from a device tree file with a driver alias"""
317 dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
318 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300319 self.run_test(['struct'], dtb_file, output)
Walter Lozanodac82282020-07-03 08:07:17 -0300320 with open(output) as infile:
321 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700322 self._check_strings(HEADER + '''
Walter Lozanodac82282020-07-03 08:07:17 -0300323struct dtd_sandbox_gpio {
324\tconst char *\tgpio_bank_name;
325\tbool\t\tgpio_controller;
326\tfdt32_t\t\tsandbox_gpio_count;
327};
Walter Lozanodac82282020-07-03 08:07:17 -0300328''', data)
329
Walter Lozano361e7332020-06-25 01:10:08 -0300330 self.run_test(['platdata'], dtb_file, output)
Walter Lozanodac82282020-07-03 08:07:17 -0300331 with open(output) as infile:
332 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700333 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600334/* Node /gpios@0 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300335static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
Walter Lozanodac82282020-07-03 08:07:17 -0300336\t.gpio_bank_name\t\t= "a",
337\t.gpio_controller\t= true,
338\t.sandbox_gpio_count\t= 0x14,
339};
Simon Glass20e442a2020-12-28 20:34:54 -0700340U_BOOT_DRVINFO(gpios_at_0) = {
Walter Lozanodac82282020-07-03 08:07:17 -0300341\t.name\t\t= "sandbox_gpio",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700342\t.plat\t= &dtv_gpios_at_0,
Simon Glass4f500862020-12-03 16:55:19 -0700343\t.plat_size\t= sizeof(dtv_gpios_at_0),
Simon Glasse41651f2020-10-03 11:31:35 -0600344\t.parent_idx\t= -1,
Walter Lozanodac82282020-07-03 08:07:17 -0300345};
346
Walter Lozano51f12632020-06-25 01:10:13 -0300347void dm_populate_phandle_data(void) {
348}
Walter Lozanodac82282020-07-03 08:07:17 -0300349''', data)
350
Walter Lozano361e7332020-06-25 01:10:08 -0300351 def test_invalid_driver(self):
352 """Test output from a device tree file with an invalid driver"""
353 dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
354 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700355 with test_util.capture_sys_output() as _:
Simon Glass192c1112020-12-28 20:34:50 -0700356 dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
Walter Lozano361e7332020-06-25 01:10:08 -0300357 with open(output) as infile:
358 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700359 self._check_strings(HEADER + '''
Walter Lozano361e7332020-06-25 01:10:08 -0300360struct dtd_invalid {
361};
362''', data)
363
Simon Glass67b5ec52020-12-28 20:34:47 -0700364 with test_util.capture_sys_output() as _:
Simon Glass192c1112020-12-28 20:34:50 -0700365 dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
Walter Lozano361e7332020-06-25 01:10:08 -0300366 with open(output) as infile:
367 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700368 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600369/* Node /spl-test index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300370static struct dtd_invalid dtv_spl_test = {
Walter Lozano361e7332020-06-25 01:10:08 -0300371};
Simon Glass20e442a2020-12-28 20:34:54 -0700372U_BOOT_DRVINFO(spl_test) = {
Walter Lozano361e7332020-06-25 01:10:08 -0300373\t.name\t\t= "invalid",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700374\t.plat\t= &dtv_spl_test,
Simon Glass4f500862020-12-03 16:55:19 -0700375\t.plat_size\t= sizeof(dtv_spl_test),
Simon Glasse41651f2020-10-03 11:31:35 -0600376\t.parent_idx\t= -1,
Walter Lozano361e7332020-06-25 01:10:08 -0300377};
378
Walter Lozano51f12632020-06-25 01:10:13 -0300379void dm_populate_phandle_data(void) {
380}
Walter Lozano361e7332020-06-25 01:10:08 -0300381''', data)
382
Simon Glassc0791922017-06-18 22:09:06 -0600383 def test_phandle(self):
384 """Test output from a node containing a phandle reference"""
385 dtb_file = get_dtb_file('dtoc_test_phandle.dts')
386 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300387 self.run_test(['struct'], dtb_file, output)
Simon Glassc0791922017-06-18 22:09:06 -0600388 with open(output) as infile:
389 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700390 self._check_strings(HEADER + '''
Simon Glassc0791922017-06-18 22:09:06 -0600391struct dtd_source {
Simon Glass634eba42017-08-29 14:15:59 -0600392\tstruct phandle_2_arg clocks[4];
Simon Glassc0791922017-06-18 22:09:06 -0600393};
394struct dtd_target {
395\tfdt32_t\t\tintval;
396};
397''', data)
398
Walter Lozano361e7332020-06-25 01:10:08 -0300399 self.run_test(['platdata'], dtb_file, output)
Simon Glassc0791922017-06-18 22:09:06 -0600400 with open(output) as infile:
401 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700402 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600403/* Node /phandle2-target index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300404static struct dtd_target dtv_phandle2_target = {
Simon Glass634eba42017-08-29 14:15:59 -0600405\t.intval\t\t\t= 0x1,
406};
Simon Glass20e442a2020-12-28 20:34:54 -0700407U_BOOT_DRVINFO(phandle2_target) = {
Simon Glass634eba42017-08-29 14:15:59 -0600408\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700409\t.plat\t= &dtv_phandle2_target,
Simon Glass4f500862020-12-03 16:55:19 -0700410\t.plat_size\t= sizeof(dtv_phandle2_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600411\t.parent_idx\t= -1,
Simon Glass634eba42017-08-29 14:15:59 -0600412};
413
Simon Glass1b272732020-10-03 11:31:25 -0600414/* Node /phandle3-target index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300415static struct dtd_target dtv_phandle3_target = {
Simon Glass634eba42017-08-29 14:15:59 -0600416\t.intval\t\t\t= 0x2,
417};
Simon Glass20e442a2020-12-28 20:34:54 -0700418U_BOOT_DRVINFO(phandle3_target) = {
Simon Glass634eba42017-08-29 14:15:59 -0600419\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700420\t.plat\t= &dtv_phandle3_target,
Simon Glass4f500862020-12-03 16:55:19 -0700421\t.plat_size\t= sizeof(dtv_phandle3_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600422\t.parent_idx\t= -1,
Simon Glass634eba42017-08-29 14:15:59 -0600423};
424
Simon Glass1b272732020-10-03 11:31:25 -0600425/* Node /phandle-target index 4 */
426static struct dtd_target dtv_phandle_target = {
427\t.intval\t\t\t= 0x0,
428};
Simon Glass20e442a2020-12-28 20:34:54 -0700429U_BOOT_DRVINFO(phandle_target) = {
Simon Glass1b272732020-10-03 11:31:25 -0600430\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700431\t.plat\t= &dtv_phandle_target,
Simon Glass4f500862020-12-03 16:55:19 -0700432\t.plat_size\t= sizeof(dtv_phandle_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600433\t.parent_idx\t= -1,
Simon Glass1b272732020-10-03 11:31:25 -0600434};
435
436/* Node /phandle-source index 2 */
Walter Lozano51f12632020-06-25 01:10:13 -0300437static struct dtd_source dtv_phandle_source = {
Simon Glass35d50372017-08-29 14:15:57 -0600438\t.clocks\t\t\t= {
Simon Glass8a38abf2020-10-03 11:31:40 -0600439\t\t\t{4, {}},
440\t\t\t{0, {11}},
441\t\t\t{1, {12, 13}},
442\t\t\t{4, {}},},
Simon Glassc0791922017-06-18 22:09:06 -0600443};
Simon Glass20e442a2020-12-28 20:34:54 -0700444U_BOOT_DRVINFO(phandle_source) = {
Simon Glassc0791922017-06-18 22:09:06 -0600445\t.name\t\t= "source",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700446\t.plat\t= &dtv_phandle_source,
Simon Glass4f500862020-12-03 16:55:19 -0700447\t.plat_size\t= sizeof(dtv_phandle_source),
Simon Glasse41651f2020-10-03 11:31:35 -0600448\t.parent_idx\t= -1,
Simon Glassc0791922017-06-18 22:09:06 -0600449};
450
Simon Glass1b272732020-10-03 11:31:25 -0600451/* Node /phandle-source2 index 3 */
Walter Lozano51f12632020-06-25 01:10:13 -0300452static struct dtd_source dtv_phandle_source2 = {
Simon Glass760b7172018-07-06 10:27:31 -0600453\t.clocks\t\t\t= {
Simon Glass8a38abf2020-10-03 11:31:40 -0600454\t\t\t{4, {}},},
Simon Glass760b7172018-07-06 10:27:31 -0600455};
Simon Glass20e442a2020-12-28 20:34:54 -0700456U_BOOT_DRVINFO(phandle_source2) = {
Simon Glass760b7172018-07-06 10:27:31 -0600457\t.name\t\t= "source",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700458\t.plat\t= &dtv_phandle_source2,
Simon Glass4f500862020-12-03 16:55:19 -0700459\t.plat_size\t= sizeof(dtv_phandle_source2),
Simon Glasse41651f2020-10-03 11:31:35 -0600460\t.parent_idx\t= -1,
Simon Glass760b7172018-07-06 10:27:31 -0600461};
462
Walter Lozano51f12632020-06-25 01:10:13 -0300463void dm_populate_phandle_data(void) {
Walter Lozano51f12632020-06-25 01:10:13 -0300464}
Simon Glassc0791922017-06-18 22:09:06 -0600465''', data)
466
Simon Glass8512ea22018-07-06 10:27:35 -0600467 def test_phandle_single(self):
468 """Test output from a node containing a phandle reference"""
469 dtb_file = get_dtb_file('dtoc_test_phandle_single.dts')
470 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300471 self.run_test(['struct'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600472 with open(output) as infile:
473 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700474 self._check_strings(HEADER + '''
Simon Glass8512ea22018-07-06 10:27:35 -0600475struct dtd_source {
476\tstruct phandle_0_arg clocks[1];
477};
478struct dtd_target {
479\tfdt32_t\t\tintval;
480};
481''', data)
482
483 def test_phandle_reorder(self):
484 """Test that phandle targets are generated before their references"""
485 dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts')
486 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300487 self.run_test(['platdata'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600488 with open(output) as infile:
489 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700490 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600491/* Node /phandle-target index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300492static struct dtd_target dtv_phandle_target = {
Simon Glass8512ea22018-07-06 10:27:35 -0600493};
Simon Glass20e442a2020-12-28 20:34:54 -0700494U_BOOT_DRVINFO(phandle_target) = {
Simon Glass8512ea22018-07-06 10:27:35 -0600495\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700496\t.plat\t= &dtv_phandle_target,
Simon Glass4f500862020-12-03 16:55:19 -0700497\t.plat_size\t= sizeof(dtv_phandle_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600498\t.parent_idx\t= -1,
Simon Glass8512ea22018-07-06 10:27:35 -0600499};
500
Simon Glass1b272732020-10-03 11:31:25 -0600501/* Node /phandle-source2 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300502static struct dtd_source dtv_phandle_source2 = {
Simon Glass8512ea22018-07-06 10:27:35 -0600503\t.clocks\t\t\t= {
Simon Glass8a38abf2020-10-03 11:31:40 -0600504\t\t\t{1, {}},},
Simon Glass8512ea22018-07-06 10:27:35 -0600505};
Simon Glass20e442a2020-12-28 20:34:54 -0700506U_BOOT_DRVINFO(phandle_source2) = {
Simon Glass8512ea22018-07-06 10:27:35 -0600507\t.name\t\t= "source",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700508\t.plat\t= &dtv_phandle_source2,
Simon Glass4f500862020-12-03 16:55:19 -0700509\t.plat_size\t= sizeof(dtv_phandle_source2),
Simon Glasse41651f2020-10-03 11:31:35 -0600510\t.parent_idx\t= -1,
Simon Glass8512ea22018-07-06 10:27:35 -0600511};
512
Walter Lozano51f12632020-06-25 01:10:13 -0300513void dm_populate_phandle_data(void) {
Walter Lozano51f12632020-06-25 01:10:13 -0300514}
Simon Glass8512ea22018-07-06 10:27:35 -0600515''', data)
516
Walter Lozano6c3fc502020-06-25 01:10:17 -0300517 def test_phandle_cd_gpio(self):
518 """Test that phandle targets are generated when unsing cd-gpios"""
519 dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
520 output = tools.GetOutputFilename('output')
Simon Glass192c1112020-12-28 20:34:50 -0700521 dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
Walter Lozano6c3fc502020-06-25 01:10:17 -0300522 with open(output) as infile:
523 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700524 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600525/* Node /phandle2-target index 0 */
Walter Lozano6c3fc502020-06-25 01:10:17 -0300526static struct dtd_target dtv_phandle2_target = {
527\t.intval\t\t\t= 0x1,
528};
Simon Glass20e442a2020-12-28 20:34:54 -0700529U_BOOT_DRVINFO(phandle2_target) = {
Walter Lozano6c3fc502020-06-25 01:10:17 -0300530\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700531\t.plat\t= &dtv_phandle2_target,
Simon Glass4f500862020-12-03 16:55:19 -0700532\t.plat_size\t= sizeof(dtv_phandle2_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600533\t.parent_idx\t= -1,
Walter Lozano6c3fc502020-06-25 01:10:17 -0300534};
535
Simon Glass1b272732020-10-03 11:31:25 -0600536/* Node /phandle3-target index 1 */
Walter Lozano6c3fc502020-06-25 01:10:17 -0300537static struct dtd_target dtv_phandle3_target = {
538\t.intval\t\t\t= 0x2,
539};
Simon Glass20e442a2020-12-28 20:34:54 -0700540U_BOOT_DRVINFO(phandle3_target) = {
Walter Lozano6c3fc502020-06-25 01:10:17 -0300541\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700542\t.plat\t= &dtv_phandle3_target,
Simon Glass4f500862020-12-03 16:55:19 -0700543\t.plat_size\t= sizeof(dtv_phandle3_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600544\t.parent_idx\t= -1,
Walter Lozano6c3fc502020-06-25 01:10:17 -0300545};
546
Simon Glass1b272732020-10-03 11:31:25 -0600547/* Node /phandle-target index 4 */
548static struct dtd_target dtv_phandle_target = {
549\t.intval\t\t\t= 0x0,
550};
Simon Glass20e442a2020-12-28 20:34:54 -0700551U_BOOT_DRVINFO(phandle_target) = {
Simon Glass1b272732020-10-03 11:31:25 -0600552\t.name\t\t= "target",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700553\t.plat\t= &dtv_phandle_target,
Simon Glass4f500862020-12-03 16:55:19 -0700554\t.plat_size\t= sizeof(dtv_phandle_target),
Simon Glasse41651f2020-10-03 11:31:35 -0600555\t.parent_idx\t= -1,
Simon Glass1b272732020-10-03 11:31:25 -0600556};
557
558/* Node /phandle-source index 2 */
Walter Lozano6c3fc502020-06-25 01:10:17 -0300559static struct dtd_source dtv_phandle_source = {
560\t.cd_gpios\t\t= {
Simon Glass8a38abf2020-10-03 11:31:40 -0600561\t\t\t{4, {}},
562\t\t\t{0, {11}},
563\t\t\t{1, {12, 13}},
564\t\t\t{4, {}},},
Walter Lozano6c3fc502020-06-25 01:10:17 -0300565};
Simon Glass20e442a2020-12-28 20:34:54 -0700566U_BOOT_DRVINFO(phandle_source) = {
Walter Lozano6c3fc502020-06-25 01:10:17 -0300567\t.name\t\t= "source",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700568\t.plat\t= &dtv_phandle_source,
Simon Glass4f500862020-12-03 16:55:19 -0700569\t.plat_size\t= sizeof(dtv_phandle_source),
Simon Glasse41651f2020-10-03 11:31:35 -0600570\t.parent_idx\t= -1,
Walter Lozano6c3fc502020-06-25 01:10:17 -0300571};
572
Simon Glass1b272732020-10-03 11:31:25 -0600573/* Node /phandle-source2 index 3 */
Walter Lozano6c3fc502020-06-25 01:10:17 -0300574static struct dtd_source dtv_phandle_source2 = {
575\t.cd_gpios\t\t= {
Simon Glass8a38abf2020-10-03 11:31:40 -0600576\t\t\t{4, {}},},
Walter Lozano6c3fc502020-06-25 01:10:17 -0300577};
Simon Glass20e442a2020-12-28 20:34:54 -0700578U_BOOT_DRVINFO(phandle_source2) = {
Walter Lozano6c3fc502020-06-25 01:10:17 -0300579\t.name\t\t= "source",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700580\t.plat\t= &dtv_phandle_source2,
Simon Glass4f500862020-12-03 16:55:19 -0700581\t.plat_size\t= sizeof(dtv_phandle_source2),
Simon Glasse41651f2020-10-03 11:31:35 -0600582\t.parent_idx\t= -1,
Walter Lozano6c3fc502020-06-25 01:10:17 -0300583};
584
585void dm_populate_phandle_data(void) {
Walter Lozano6c3fc502020-06-25 01:10:17 -0300586}
587''', data)
588
Simon Glass8512ea22018-07-06 10:27:35 -0600589 def test_phandle_bad(self):
590 """Test a node containing an invalid phandle fails"""
Simon Glass4b4bc062018-10-01 21:12:43 -0600591 dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts',
592 capture_stderr=True)
Simon Glass8512ea22018-07-06 10:27:35 -0600593 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700594 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300595 self.run_test(['struct'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600596 self.assertIn("Cannot parse 'clocks' in node 'phandle-source'",
Simon Glass67b5ec52020-12-28 20:34:47 -0700597 str(exc.exception))
Simon Glass8512ea22018-07-06 10:27:35 -0600598
599 def test_phandle_bad2(self):
600 """Test a phandle target missing its #*-cells property"""
Simon Glass4b4bc062018-10-01 21:12:43 -0600601 dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts',
602 capture_stderr=True)
Simon Glass8512ea22018-07-06 10:27:35 -0600603 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700604 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300605 self.run_test(['struct'], dtb_file, output)
Walter Lozanoad340172020-06-25 01:10:16 -0300606 self.assertIn("Node 'phandle-target' has no cells property",
Simon Glass67b5ec52020-12-28 20:34:47 -0700607 str(exc.exception))
Simon Glass8512ea22018-07-06 10:27:35 -0600608
Simon Glassc20ee0e2017-08-29 14:15:50 -0600609 def test_addresses64(self):
610 """Test output from a node with a 'reg' property with na=2, ns=2"""
611 dtb_file = get_dtb_file('dtoc_test_addr64.dts')
612 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300613 self.run_test(['struct'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600614 with open(output) as infile:
615 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700616 self._check_strings(HEADER + '''
Simon Glassc20ee0e2017-08-29 14:15:50 -0600617struct dtd_test1 {
618\tfdt64_t\t\treg[2];
619};
620struct dtd_test2 {
621\tfdt64_t\t\treg[2];
622};
623struct dtd_test3 {
624\tfdt64_t\t\treg[4];
625};
626''', data)
627
Walter Lozano361e7332020-06-25 01:10:08 -0300628 self.run_test(['platdata'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600629 with open(output) as infile:
630 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700631 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600632/* Node /test1 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300633static struct dtd_test1 dtv_test1 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600634\t.reg\t\t\t= {0x1234, 0x5678},
635};
Simon Glass20e442a2020-12-28 20:34:54 -0700636U_BOOT_DRVINFO(test1) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600637\t.name\t\t= "test1",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700638\t.plat\t= &dtv_test1,
Simon Glass4f500862020-12-03 16:55:19 -0700639\t.plat_size\t= sizeof(dtv_test1),
Simon Glasse41651f2020-10-03 11:31:35 -0600640\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600641};
642
Simon Glass1b272732020-10-03 11:31:25 -0600643/* Node /test2 index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300644static struct dtd_test2 dtv_test2 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600645\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
646};
Simon Glass20e442a2020-12-28 20:34:54 -0700647U_BOOT_DRVINFO(test2) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600648\t.name\t\t= "test2",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700649\t.plat\t= &dtv_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700650\t.plat_size\t= sizeof(dtv_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600651\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600652};
653
Simon Glass1b272732020-10-03 11:31:25 -0600654/* Node /test3 index 2 */
Walter Lozano51f12632020-06-25 01:10:13 -0300655static struct dtd_test3 dtv_test3 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600656\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
657};
Simon Glass20e442a2020-12-28 20:34:54 -0700658U_BOOT_DRVINFO(test3) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600659\t.name\t\t= "test3",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700660\t.plat\t= &dtv_test3,
Simon Glass4f500862020-12-03 16:55:19 -0700661\t.plat_size\t= sizeof(dtv_test3),
Simon Glasse41651f2020-10-03 11:31:35 -0600662\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600663};
664
Walter Lozano51f12632020-06-25 01:10:13 -0300665''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600666
667 def test_addresses32(self):
668 """Test output from a node with a 'reg' property with na=1, ns=1"""
669 dtb_file = get_dtb_file('dtoc_test_addr32.dts')
670 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300671 self.run_test(['struct'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600672 with open(output) as infile:
673 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700674 self._check_strings(HEADER + '''
Simon Glassc20ee0e2017-08-29 14:15:50 -0600675struct dtd_test1 {
676\tfdt32_t\t\treg[2];
677};
678struct dtd_test2 {
679\tfdt32_t\t\treg[4];
680};
681''', data)
682
Walter Lozano361e7332020-06-25 01:10:08 -0300683 self.run_test(['platdata'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600684 with open(output) as infile:
685 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700686 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600687/* Node /test1 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300688static struct dtd_test1 dtv_test1 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600689\t.reg\t\t\t= {0x1234, 0x5678},
690};
Simon Glass20e442a2020-12-28 20:34:54 -0700691U_BOOT_DRVINFO(test1) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600692\t.name\t\t= "test1",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700693\t.plat\t= &dtv_test1,
Simon Glass4f500862020-12-03 16:55:19 -0700694\t.plat_size\t= sizeof(dtv_test1),
Simon Glasse41651f2020-10-03 11:31:35 -0600695\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600696};
697
Simon Glass1b272732020-10-03 11:31:25 -0600698/* Node /test2 index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300699static struct dtd_test2 dtv_test2 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600700\t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
701};
Simon Glass20e442a2020-12-28 20:34:54 -0700702U_BOOT_DRVINFO(test2) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600703\t.name\t\t= "test2",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700704\t.plat\t= &dtv_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700705\t.plat_size\t= sizeof(dtv_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600706\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600707};
708
Walter Lozano51f12632020-06-25 01:10:13 -0300709''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600710
711 def test_addresses64_32(self):
712 """Test output from a node with a 'reg' property with na=2, ns=1"""
713 dtb_file = get_dtb_file('dtoc_test_addr64_32.dts')
714 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300715 self.run_test(['struct'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600716 with open(output) as infile:
717 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700718 self._check_strings(HEADER + '''
Simon Glassc20ee0e2017-08-29 14:15:50 -0600719struct dtd_test1 {
720\tfdt64_t\t\treg[2];
721};
722struct dtd_test2 {
723\tfdt64_t\t\treg[2];
724};
725struct dtd_test3 {
726\tfdt64_t\t\treg[4];
727};
728''', data)
729
Walter Lozano361e7332020-06-25 01:10:08 -0300730 self.run_test(['platdata'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600731 with open(output) as infile:
732 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700733 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600734/* Node /test1 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300735static struct dtd_test1 dtv_test1 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600736\t.reg\t\t\t= {0x123400000000, 0x5678},
737};
Simon Glass20e442a2020-12-28 20:34:54 -0700738U_BOOT_DRVINFO(test1) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600739\t.name\t\t= "test1",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700740\t.plat\t= &dtv_test1,
Simon Glass4f500862020-12-03 16:55:19 -0700741\t.plat_size\t= sizeof(dtv_test1),
Simon Glasse41651f2020-10-03 11:31:35 -0600742\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600743};
744
Simon Glass1b272732020-10-03 11:31:25 -0600745/* Node /test2 index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300746static struct dtd_test2 dtv_test2 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600747\t.reg\t\t\t= {0x1234567890123456, 0x98765432},
748};
Simon Glass20e442a2020-12-28 20:34:54 -0700749U_BOOT_DRVINFO(test2) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600750\t.name\t\t= "test2",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700751\t.plat\t= &dtv_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700752\t.plat_size\t= sizeof(dtv_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600753\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600754};
755
Simon Glass1b272732020-10-03 11:31:25 -0600756/* Node /test3 index 2 */
Walter Lozano51f12632020-06-25 01:10:13 -0300757static struct dtd_test3 dtv_test3 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600758\t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
759};
Simon Glass20e442a2020-12-28 20:34:54 -0700760U_BOOT_DRVINFO(test3) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600761\t.name\t\t= "test3",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700762\t.plat\t= &dtv_test3,
Simon Glass4f500862020-12-03 16:55:19 -0700763\t.plat_size\t= sizeof(dtv_test3),
Simon Glasse41651f2020-10-03 11:31:35 -0600764\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600765};
766
Walter Lozano51f12632020-06-25 01:10:13 -0300767''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600768
769 def test_addresses32_64(self):
770 """Test output from a node with a 'reg' property with na=1, ns=2"""
771 dtb_file = get_dtb_file('dtoc_test_addr32_64.dts')
772 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300773 self.run_test(['struct'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600774 with open(output) as infile:
775 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700776 self._check_strings(HEADER + '''
Simon Glassc20ee0e2017-08-29 14:15:50 -0600777struct dtd_test1 {
778\tfdt64_t\t\treg[2];
779};
780struct dtd_test2 {
781\tfdt64_t\t\treg[2];
782};
783struct dtd_test3 {
784\tfdt64_t\t\treg[4];
785};
786''', data)
787
Walter Lozano361e7332020-06-25 01:10:08 -0300788 self.run_test(['platdata'], dtb_file, output)
Simon Glassc20ee0e2017-08-29 14:15:50 -0600789 with open(output) as infile:
790 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700791 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600792/* Node /test1 index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300793static struct dtd_test1 dtv_test1 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600794\t.reg\t\t\t= {0x1234, 0x567800000000},
795};
Simon Glass20e442a2020-12-28 20:34:54 -0700796U_BOOT_DRVINFO(test1) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600797\t.name\t\t= "test1",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700798\t.plat\t= &dtv_test1,
Simon Glass4f500862020-12-03 16:55:19 -0700799\t.plat_size\t= sizeof(dtv_test1),
Simon Glasse41651f2020-10-03 11:31:35 -0600800\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600801};
802
Simon Glass1b272732020-10-03 11:31:25 -0600803/* Node /test2 index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300804static struct dtd_test2 dtv_test2 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600805\t.reg\t\t\t= {0x12345678, 0x9876543210987654},
806};
Simon Glass20e442a2020-12-28 20:34:54 -0700807U_BOOT_DRVINFO(test2) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600808\t.name\t\t= "test2",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700809\t.plat\t= &dtv_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700810\t.plat_size\t= sizeof(dtv_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600811\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600812};
813
Simon Glass1b272732020-10-03 11:31:25 -0600814/* Node /test3 index 2 */
Walter Lozano51f12632020-06-25 01:10:13 -0300815static struct dtd_test3 dtv_test3 = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600816\t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
817};
Simon Glass20e442a2020-12-28 20:34:54 -0700818U_BOOT_DRVINFO(test3) = {
Simon Glassc20ee0e2017-08-29 14:15:50 -0600819\t.name\t\t= "test3",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700820\t.plat\t= &dtv_test3,
Simon Glass4f500862020-12-03 16:55:19 -0700821\t.plat_size\t= sizeof(dtv_test3),
Simon Glasse41651f2020-10-03 11:31:35 -0600822\t.parent_idx\t= -1,
Simon Glassc20ee0e2017-08-29 14:15:50 -0600823};
824
Walter Lozano51f12632020-06-25 01:10:13 -0300825''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
Simon Glass8512ea22018-07-06 10:27:35 -0600826
827 def test_bad_reg(self):
828 """Test that a reg property with an invalid type generates an error"""
Simon Glassfe57c782018-07-06 10:27:37 -0600829 # Capture stderr since dtc will emit warnings for this file
830 dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True)
Simon Glass8512ea22018-07-06 10:27:35 -0600831 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700832 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300833 self.run_test(['struct'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600834 self.assertIn("Node 'spl-test' reg property is not an int",
Simon Glass67b5ec52020-12-28 20:34:47 -0700835 str(exc.exception))
Simon Glass8512ea22018-07-06 10:27:35 -0600836
837 def test_bad_reg2(self):
838 """Test that a reg property with an invalid cell count is detected"""
Simon Glassfe57c782018-07-06 10:27:37 -0600839 # Capture stderr since dtc will emit warnings for this file
840 dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True)
Simon Glass8512ea22018-07-06 10:27:35 -0600841 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700842 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300843 self.run_test(['struct'], dtb_file, output)
Simon Glass67b5ec52020-12-28 20:34:47 -0700844 self.assertIn(
845 "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
846 str(exc.exception))
Simon Glass8512ea22018-07-06 10:27:35 -0600847
848 def test_add_prop(self):
849 """Test that a subequent node can add a new property to a struct"""
850 dtb_file = get_dtb_file('dtoc_test_add_prop.dts')
851 output = tools.GetOutputFilename('output')
Walter Lozano361e7332020-06-25 01:10:08 -0300852 self.run_test(['struct'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600853 with open(output) as infile:
854 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700855 self._check_strings(HEADER + '''
Simon Glass8512ea22018-07-06 10:27:35 -0600856struct dtd_sandbox_spl_test {
857\tfdt32_t\t\tintarray;
858\tfdt32_t\t\tintval;
859};
860''', data)
861
Walter Lozano361e7332020-06-25 01:10:08 -0300862 self.run_test(['platdata'], dtb_file, output)
Simon Glass8512ea22018-07-06 10:27:35 -0600863 with open(output) as infile:
864 data = infile.read()
Simon Glass67b5ec52020-12-28 20:34:47 -0700865 self._check_strings(C_HEADER + '''
Simon Glass1b272732020-10-03 11:31:25 -0600866/* Node /spl-test index 0 */
Walter Lozano51f12632020-06-25 01:10:13 -0300867static struct dtd_sandbox_spl_test dtv_spl_test = {
Simon Glass8512ea22018-07-06 10:27:35 -0600868\t.intval\t\t\t= 0x1,
869};
Simon Glass20e442a2020-12-28 20:34:54 -0700870U_BOOT_DRVINFO(spl_test) = {
Simon Glass8512ea22018-07-06 10:27:35 -0600871\t.name\t\t= "sandbox_spl_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700872\t.plat\t= &dtv_spl_test,
Simon Glass4f500862020-12-03 16:55:19 -0700873\t.plat_size\t= sizeof(dtv_spl_test),
Simon Glasse41651f2020-10-03 11:31:35 -0600874\t.parent_idx\t= -1,
Simon Glass8512ea22018-07-06 10:27:35 -0600875};
876
Simon Glass1b272732020-10-03 11:31:25 -0600877/* Node /spl-test2 index 1 */
Walter Lozano51f12632020-06-25 01:10:13 -0300878static struct dtd_sandbox_spl_test dtv_spl_test2 = {
Simon Glass8512ea22018-07-06 10:27:35 -0600879\t.intarray\t\t= 0x5,
880};
Simon Glass20e442a2020-12-28 20:34:54 -0700881U_BOOT_DRVINFO(spl_test2) = {
Simon Glass8512ea22018-07-06 10:27:35 -0600882\t.name\t\t= "sandbox_spl_test",
Simon Glasscaa4daa2020-12-03 16:55:18 -0700883\t.plat\t= &dtv_spl_test2,
Simon Glass4f500862020-12-03 16:55:19 -0700884\t.plat_size\t= sizeof(dtv_spl_test2),
Simon Glasse41651f2020-10-03 11:31:35 -0600885\t.parent_idx\t= -1,
Simon Glass8512ea22018-07-06 10:27:35 -0600886};
887
Walter Lozano51f12632020-06-25 01:10:13 -0300888''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
Simon Glass8512ea22018-07-06 10:27:35 -0600889
Simon Glass67b5ec52020-12-28 20:34:47 -0700890 def test_stdout(self):
Simon Glass8512ea22018-07-06 10:27:35 -0600891 """Test output to stdout"""
892 dtb_file = get_dtb_file('dtoc_test_simple.dts')
Simon Glassde846cb2020-12-28 20:34:49 -0700893 with test_util.capture_sys_output() as (stdout, _):
Simon Glassf62cea02020-12-28 20:34:48 -0700894 self.run_test(['struct'], dtb_file, None)
Simon Glassde846cb2020-12-28 20:34:49 -0700895 self._check_strings(self.struct_text, stdout.getvalue())
Simon Glass8512ea22018-07-06 10:27:35 -0600896
Simon Glassbe44f272020-12-28 20:34:51 -0700897 def test_multi_to_file(self):
898 """Test output of multiple pieces to a single file"""
899 dtb_file = get_dtb_file('dtoc_test_simple.dts')
900 output = tools.GetOutputFilename('output')
Simon Glass10cbd3b2020-12-28 20:34:52 -0700901 self.run_test(['all'], dtb_file, output)
Simon Glassbe44f272020-12-28 20:34:51 -0700902 data = tools.ReadFile(output, binary=False)
Simon Glass10cbd3b2020-12-28 20:34:52 -0700903 self._check_strings(self.platdata_text + self.struct_text, data)
Simon Glassbe44f272020-12-28 20:34:51 -0700904
Simon Glass67b5ec52020-12-28 20:34:47 -0700905 def test_no_command(self):
Simon Glass8512ea22018-07-06 10:27:35 -0600906 """Test running dtoc without a command"""
Simon Glass67b5ec52020-12-28 20:34:47 -0700907 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300908 self.run_test([], '', '')
Simon Glass8512ea22018-07-06 10:27:35 -0600909 self.assertIn("Please specify a command: struct, platdata",
Simon Glass67b5ec52020-12-28 20:34:47 -0700910 str(exc.exception))
Simon Glass8512ea22018-07-06 10:27:35 -0600911
Simon Glass67b5ec52020-12-28 20:34:47 -0700912 def test_bad_command(self):
Simon Glass8512ea22018-07-06 10:27:35 -0600913 """Test running dtoc with an invalid command"""
914 dtb_file = get_dtb_file('dtoc_test_simple.dts')
915 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700916 with self.assertRaises(ValueError) as exc:
Walter Lozano361e7332020-06-25 01:10:08 -0300917 self.run_test(['invalid-cmd'], dtb_file, output)
Simon Glass10cbd3b2020-12-28 20:34:52 -0700918 self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
Simon Glass67b5ec52020-12-28 20:34:47 -0700919 str(exc.exception))
Walter Lozano6c74d1b2020-07-28 19:06:23 -0300920
Simon Glass67b5ec52020-12-28 20:34:47 -0700921 @staticmethod
922 def test_scan_drivers():
Walter Lozano6c74d1b2020-07-28 19:06:23 -0300923 """Test running dtoc with additional drivers to scan"""
924 dtb_file = get_dtb_file('dtoc_test_simple.dts')
925 output = tools.GetOutputFilename('output')
Simon Glass67b5ec52020-12-28 20:34:47 -0700926 with test_util.capture_sys_output() as _:
927 dtb_platdata.run_steps(
Simon Glass192c1112020-12-28 20:34:50 -0700928 ['struct'], dtb_file, False, output, [], True,
Simon Glass67b5ec52020-12-28 20:34:47 -0700929 [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
Walter Lozano6c74d1b2020-07-28 19:06:23 -0300930
Simon Glass67b5ec52020-12-28 20:34:47 -0700931 @staticmethod
932 def test_unicode_error():
Walter Lozano6c74d1b2020-07-28 19:06:23 -0300933 """Test running dtoc with an invalid unicode file
934
935 To be able to perform this test without adding a weird text file which
936 would produce issues when using checkpatch.pl or patman, generate the
937 file at runtime and then process it.
938 """
939 dtb_file = get_dtb_file('dtoc_test_simple.dts')
940 output = tools.GetOutputFilename('output')
941 driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
Simon Glass67b5ec52020-12-28 20:34:47 -0700942 with open(driver_fn, 'wb+') as fout:
943 fout.write(b'\x81')
Walter Lozano6c74d1b2020-07-28 19:06:23 -0300944
Simon Glass67b5ec52020-12-28 20:34:47 -0700945 with test_util.capture_sys_output() as _:
Simon Glass192c1112020-12-28 20:34:50 -0700946 dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
947 True, [driver_fn])
Simon Glass7d637c12020-12-23 08:11:23 -0700948
Simon Glass67b5ec52020-12-28 20:34:47 -0700949 def test_driver(self):
Simon Glass7d637c12020-12-23 08:11:23 -0700950 """Test the Driver class"""
951 drv1 = dtb_platdata.Driver('fred')
952 drv2 = dtb_platdata.Driver('mary')
953 drv3 = dtb_platdata.Driver('fred')
954 self.assertEqual("Driver(name='fred')", str(drv1))
955 self.assertEqual(drv1, drv3)
956 self.assertNotEqual(drv1, drv2)
957 self.assertNotEqual(drv2, drv3)
Simon Glass10cbd3b2020-12-28 20:34:52 -0700958
959 def test_output_conflict(self):
960 """Test a conflict between and output dirs and output file"""
961 with self.assertRaises(ValueError) as exc:
962 dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True)
963 self.assertIn("Must specify either output or output_dirs, not both",
964 str(exc.exception))
965
966 def test_output_dirs(self):
967 """Test outputting files to a directory"""
968 # Remove the directory so that files from other tests are not there
969 tools._RemoveOutputDir()
970 tools.PrepareOutputDir(None)
971
972 # This should create the .dts and .dtb in the output directory
973 dtb_file = get_dtb_file('dtoc_test_simple.dts')
974 outdir = tools.GetOutputDir()
975 fnames = glob.glob(outdir + '/*')
976 self.assertEqual(2, len(fnames))
977
978 dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
979 fnames = glob.glob(outdir + '/*')
980 self.assertEqual(4, len(fnames))
981
982 leafs = set(os.path.basename(fname) for fname in fnames)
983 self.assertEqual(
Simon Glassf31fa992020-12-28 20:35:01 -0700984 {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
Simon Glass10cbd3b2020-12-28 20:34:52 -0700985 leafs)
Simon Glass1e0f3f42020-12-28 20:35:03 -0700986
987 def test_scan_dirs(self):
988 """Test scanning of source directories"""
989 def add_file(fname):
990 pathname = os.path.join(indir, fname)
991 dirname = os.path.dirname(pathname)
992 os.makedirs(dirname, exist_ok=True)
993 tools.WriteFile(pathname, '', binary=False)
994 fname_list.append(pathname)
995
996 try:
997 outdir = tools.GetOutputDir()
998 indir = tempfile.mkdtemp(prefix='dtoc.')
999 dtb_file = get_dtb_file('dtoc_test_simple.dts')
1000
1001 fname_list = []
1002 add_file('fname.c')
1003 add_file('dir/fname2.c')
1004
1005 # Mock out scan_driver and check that it is called with the
1006 # expected files
1007 with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \
1008 as mocked:
1009 dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir],
1010 True, basedir=indir)
1011 self.assertEqual(2, len(mocked.mock_calls))
1012 self.assertEqual(mock.call(fname_list[0]),
1013 mocked.mock_calls[0])
1014 self.assertEqual(mock.call(fname_list[1]),
1015 mocked.mock_calls[1])
1016 finally:
1017 shutil.rmtree(indir)