+
+ self.run_test(['platdata'], dtb_file, output)
+ with open(output) as infile:
+ data = infile.read()
+ self._CheckStrings(C_HEADER + '''
+/* Node /spl-test index 0 */
+static struct dtd_sandbox_spl_test dtv_spl_test = {
+\t.intval\t\t\t= 0x1,
+};
+U_BOOT_DEVICE(spl_test) = {
+\t.name\t\t= "sandbox_spl_test",
+\t.platdata\t= &dtv_spl_test,
+\t.platdata_size\t= sizeof(dtv_spl_test),
+\t.parent_idx\t= -1,
+};
+
+/* Node /spl-test2 index 1 */
+static struct dtd_sandbox_spl_test dtv_spl_test2 = {
+\t.intarray\t\t= 0x5,
+};
+U_BOOT_DEVICE(spl_test2) = {
+\t.name\t\t= "sandbox_spl_test",
+\t.platdata\t= &dtv_spl_test2,
+\t.platdata_size\t= sizeof(dtv_spl_test2),
+\t.parent_idx\t= -1,
+};
+
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+
+ def testStdout(self):
+ """Test output to stdout"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ with test_util.capture_sys_output() as (stdout, stderr):
+ self.run_test(['struct'], dtb_file, '-')
+
+ def testNoCommand(self):
+ """Test running dtoc without a command"""
+ with self.assertRaises(ValueError) as e:
+ self.run_test([], '', '')
+ self.assertIn("Please specify a command: struct, platdata",
+ str(e.exception))
+
+ def testBadCommand(self):
+ """Test running dtoc with an invalid command"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ with self.assertRaises(ValueError) as e:
+ self.run_test(['invalid-cmd'], dtb_file, output)
+ self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
+ str(e.exception))
+
+ def testScanDrivers(self):
+ """Test running dtoc with additional drivers to scan"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ with test_util.capture_sys_output() as (stdout, stderr):
+ dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
+ [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+
+ def testUnicodeError(self):
+ """Test running dtoc with an invalid unicode file
+
+ To be able to perform this test without adding a weird text file which
+ would produce issues when using checkpatch.pl or patman, generate the
+ file at runtime and then process it.
+ """
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
+ with open(driver_fn, 'wb+') as df:
+ df.write(b'\x81')
+
+ with test_util.capture_sys_output() as (stdout, stderr):
+ dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
+ [driver_fn])