|
@@ -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
|