diff options
author | Simon Glass | 2020-11-08 20:36:17 -0700 |
---|---|---|
committer | Simon Glass | 2020-12-13 07:58:17 -0700 |
commit | 5ea9dccf02eb26d146dbc1fdb3106135612820ae (patch) | |
tree | 0ab49a5e6f160873d22cfdedc1feef38be990990 /tools/dtoc/test_fdt.py | |
parent | ddaa94978583d07ec515e7226e397221d8cc44c8 (diff) |
fdt: Use an Enum for the data type
Use an Enum instead of the current ad-hoc constants, so that there is a
data type associated with each 'type' value.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/test_fdt.py')
-rwxr-xr-x | tools/dtoc/test_fdt.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index cfe3e04c7ad..10e7f33a595 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -19,7 +19,7 @@ sys.path.insert(1, os.path.join(our_path, '..')) from dtoc import fdt from dtoc import fdt_util from dtoc.fdt_util import fdt32_to_cpu -from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, BytesToValue +from fdt import Type, BytesToValue import libfdt from patman import command from patman import test_util @@ -127,7 +127,7 @@ class TestFdt(unittest.TestCase): def testBytesToValue(self): self.assertEqual(BytesToValue(b'this\0is\0'), - (TYPE_STRING, ['this', 'is'])) + (Type.STRING, ['this', 'is'])) class TestNode(unittest.TestCase): """Test operation of the Node class""" @@ -249,46 +249,46 @@ class TestProp(unittest.TestCase): 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(Type.BOOL, prop.type) self.assertEqual(True, prop.value) prop = self._ConvertProp('intval') - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertEqual(1, fdt32_to_cpu(prop.value)) prop = self._ConvertProp('intarray') - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(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(Type.BYTE, prop.type) self.assertEqual(5, ord(prop.value)) prop = self._ConvertProp('longbytearray') - self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(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(Type.STRING, prop.type) self.assertEqual('message', prop.value) prop = self._ConvertProp('stringarray') - self.assertEqual(fdt.TYPE_STRING, prop.type) + self.assertEqual(Type.STRING, prop.type) self.assertEqual(['multi-word', 'message'], prop.value) prop = self._ConvertProp('notstring') - self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(Type.BYTE, prop.type) val = [ord(val) for val in prop.value] self.assertEqual([0x20, 0x21, 0x22, 0x10, 0], val) def testGetEmpty(self): """Tests the GetEmpty() function for the various supported types""" - self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL)) - self.assertEqual(chr(0), fdt.Prop.GetEmpty(fdt.TYPE_BYTE)) - self.assertEqual(tools.GetBytes(0, 4), fdt.Prop.GetEmpty(fdt.TYPE_INT)) - self.assertEqual('', fdt.Prop.GetEmpty(fdt.TYPE_STRING)) + self.assertEqual(True, fdt.Prop.GetEmpty(Type.BOOL)) + self.assertEqual(chr(0), fdt.Prop.GetEmpty(Type.BYTE)) + self.assertEqual(tools.GetBytes(0, 4), fdt.Prop.GetEmpty(Type.INT)) + self.assertEqual('', fdt.Prop.GetEmpty(Type.STRING)) def testGetOffset(self): """Test we can get the offset of a property""" @@ -304,13 +304,13 @@ class TestProp(unittest.TestCase): # No action prop2 = node2.props['intval'] prop.Widen(prop2) - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertEqual(1, fdt32_to_cpu(prop.value)) # Convert singla value to array prop2 = self.node.props['intarray'] prop.Widen(prop2) - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertTrue(isinstance(prop.value, list)) # A 4-byte array looks like a single integer. When widened by a longer |