[U-Boot] [PATCH 13/29] dtoc: Update fdt tests to increase code coverage

Simon Glass sjg at chromium.org
Wed Jun 6 00:46:49 UTC 2018


At present only some of the fdt functionality is tested. Add more tests to
cover most things. Also turn on test coverage, which currently sits at
99%.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/dtoc/test_fdt.py | 62 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index ba660ca9b75..6dd24f74e5b 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -119,6 +119,8 @@ class TestNode(unittest.TestCase):
         self.node.DeleteProp('intarray')
         offset3 = node2.Offset()
         self.assertTrue(offset3 < offset2)
+        with self.assertRaises(ValueError):
+            self.node.DeleteProp('missing')
 
     def testFindNode(self):
         """Tests that we can find a node using the _FindNode() functoin"""
@@ -126,6 +128,7 @@ class TestNode(unittest.TestCase):
         self.assertEqual('i2c at 0', node.name)
         subnode = node._FindNode('pmic at 9')
         self.assertEqual('pmic at 9', subnode.name)
+        self.assertEqual(None, node._FindNode('missing'))
 
 
 class TestProp(unittest.TestCase):
@@ -144,6 +147,53 @@ class TestProp(unittest.TestCase):
         self.node = self.dtb.GetNode('/spl-test')
         self.fdt = self.dtb.GetFdtObj()
 
+    def testPhandle(self):
+        dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
+        node = dtb.GetNode('/phandle-source')
+
+    def _ConvertProp(self, prop_name):
+        """Helper function to look up a property in self.node and return it
+
+        Args:
+            Property name to find
+
+        Return fdt.Prop object for this property
+        """
+        p = self.fdt.get_property(self.node.Offset(), prop_name)
+        return fdt.Prop(self.node, -1, prop_name, p)
+
+    def testMakeProp(self):
+        """Test we can convert all the the types that are supported"""
+        prop = self._ConvertProp('boolval')
+        self.assertEqual(fdt.TYPE_BOOL, prop.type)
+        self.assertEqual(True, prop.value)
+
+        prop = self._ConvertProp('intval')
+        self.assertEqual(fdt.TYPE_INT, prop.type)
+        self.assertEqual(1, fdt32_to_cpu(prop.value))
+
+        prop = self._ConvertProp('intarray')
+        self.assertEqual(fdt.TYPE_INT, prop.type)
+        val = [fdt32_to_cpu(val) for val in prop.value]
+        self.assertEqual([2, 3, 4], val)
+
+        prop = self._ConvertProp('byteval')
+        self.assertEqual(fdt.TYPE_BYTE, prop.type)
+        self.assertEqual(5, ord(prop.value))
+
+        prop = self._ConvertProp('longbytearray')
+        self.assertEqual(fdt.TYPE_BYTE, prop.type)
+        val = [ord(val) for val in prop.value]
+        self.assertEqual([9, 10, 11, 12, 13, 14, 15, 16, 17], val)
+
+        prop = self._ConvertProp('stringval')
+        self.assertEqual(fdt.TYPE_STRING, prop.type)
+        self.assertEqual('message', prop.value)
+
+        prop = self._ConvertProp('stringarray')
+        self.assertEqual(fdt.TYPE_STRING, prop.type)
+        self.assertEqual(['multi-word', 'message'], prop.value)
+
     def testGetEmpty(self):
         """Tests the GetEmpty() function for the various supported types"""
         self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL))
@@ -207,6 +257,12 @@ class TestProp(unittest.TestCase):
         self.assertEqual(3, len(prop.value))
 
 
+def RunTestCoverage():
+    """Run the tests and check that we get 100% coverage"""
+    test_util.RunTestCoverage('tools/dtoc/test_fdt.py', '/fdt.py',
+            ['tools/patman/*.py'], options.build_dir)
+
+
 def RunTests(args):
     """Run all the test we have for the fdt model
 
@@ -237,10 +293,16 @@ if __name__ != '__main__':
     sys.exit(1)
 
 parser = OptionParser()
+parser.add_option('-B', '--build-dir', type='string', default='b',
+        help='Directory containing the build output')
 parser.add_option('-t', '--test', action='store_true', dest='test',
                   default=False, help='run tests')
+parser.add_option('-T', '--test-coverage', action='store_true',
+                default=False, help='run tests and check for 100% coverage')
 (options, args) = parser.parse_args()
 
 # Run our meagre tests
 if options.test:
     RunTests(args)
+elif options.test_coverage:
+    RunTestCoverage()
-- 
2.17.1.1185.g55be947832-goog



More information about the U-Boot mailing list