+class TestFdtUtil(unittest.TestCase):
+ """Tests for the fdt_util module
+
+ This module will likely be mostly replaced at some point, once upstream
+ libfdt has better Python support. For now, this provides tests for current
+ functionality.
+ """
+ @classmethod
+ def setUpClass(cls):
+ tools.PrepareOutputDir(None)
+
+ def setUp(self):
+ self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts')
+ self.node = self.dtb.GetNode('/spl-test')
+
+ def testGetInt(self):
+ self.assertEqual(1, fdt_util.GetInt(self.node, 'intval'))
+ self.assertEqual(3, fdt_util.GetInt(self.node, 'missing', 3))
+
+ with self.assertRaises(ValueError) as e:
+ self.assertEqual(3, fdt_util.GetInt(self.node, 'intarray'))
+ self.assertIn("property 'intarray' has list value: expecting a single "
+ 'integer', str(e.exception))
+
+ def testGetString(self):
+ self.assertEqual('message', fdt_util.GetString(self.node, 'stringval'))
+ self.assertEqual('test', fdt_util.GetString(self.node, 'missing',
+ 'test'))
+
+ with self.assertRaises(ValueError) as e:
+ self.assertEqual(3, fdt_util.GetString(self.node, 'stringarray'))
+ self.assertIn("property 'stringarray' has list value: expecting a "
+ 'single string', str(e.exception))
+
+ def testGetBool(self):
+ self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval'))
+ self.assertEqual(False, fdt_util.GetBool(self.node, 'missing'))
+ self.assertEqual(True, fdt_util.GetBool(self.node, 'missing', True))
+ self.assertEqual(False, fdt_util.GetBool(self.node, 'missing', False))
+
+ def testFdtCellsToCpu(self):
+ val = self.node.props['intarray'].value
+ self.assertEqual(0, fdt_util.fdt_cells_to_cpu(val, 0))
+ self.assertEqual(2, fdt_util.fdt_cells_to_cpu(val, 1))
+
+ dtb2 = fdt.FdtScan('tools/dtoc/dtoc_test_addr64.dts')
+ node2 = dtb2.GetNode('/test1')
+ val = node2.props['reg'].value
+ self.assertEqual(0x1234, fdt_util.fdt_cells_to_cpu(val, 2))
+
+ def testEnsureCompiled(self):
+ """Test a degenerate case of this function"""
+ dtb = fdt_util.EnsureCompiled('tools/dtoc/dtoc_test_simple.dts')
+ self.assertEqual(dtb, fdt_util.EnsureCompiled(dtb))
+
+ def testGetPlainBytes(self):
+ self.assertEqual('fred', fdt_util.get_plain_bytes('fred'))
+
+
+def RunTestCoverage():
+ """Run the tests and check that we get 100% coverage"""
+ test_util.RunTestCoverage('tools/dtoc/test_fdt.py', None,
+ ['tools/patman/*.py', '*test_fdt.py'], options.build_dir)
+
+