diff options
author | 2018-06-13 21:44:43 -0600 | |
---|---|---|
committer | 2018-06-14 14:07:40 +1000 | |
commit | 2f0d07e678e05f260b575342867a26d466bdec85 (patch) | |
tree | 6c4987ff6139b4a1ad7a45f8f9c9aa19df95057c /tests/pylibfdt_tests.py | |
parent | 354d3dc55939499954b5e1f4948517da24591cd2 (diff) |
pylibfdt: Add functions to set and get properties as strings
It is common to want to set a property to a nul-terminated string in a
device tree. Add python methods to handle this.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests/pylibfdt_tests.py')
-rw-r--r-- | tests/pylibfdt_tests.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py index c9653a5..f3be0ac 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -68,6 +68,8 @@ TEST_VALUE64_1L = 0x01abcdef TEST_VALUE64_1 = (TEST_VALUE64_1H << 32) | TEST_VALUE64_1L TEST_STRING_1 = 'hello world' +TEST_STRING_2 = 'hi world' +TEST_STRING_3 = u'unicode ' + unichr(467) def get_err(err_code): @@ -440,6 +442,29 @@ class PyLibfdtTests(unittest.TestCase): self.assertEquals(struct.pack('>Q', TEST_VALUE64_1), self.fdt.getprop(node, prop)) + def testSetPropStr(self): + """Test that we can set a property to a particular string""" + node = 0 + prop = 'prop-str' + self.assertEquals(TEST_STRING_1, self.fdt.getprop(node, prop).as_str()) + self.fdt.setprop_str(node, prop, TEST_STRING_2) + self.assertEquals(TEST_STRING_2, self.fdt.getprop(node, prop).as_str()) + with self.assertRaises(ValueError) as e: + self.fdt.getprop(node, 'prop-int').as_str() + self.assertIn('lacks nul termination', str(e.exception)) + + node2 = self.fdt.path_offset('/subnode@1/subsubnode') + with self.assertRaises(ValueError) as e: + self.fdt.getprop(node2, 'compatible').as_str() + self.assertIn('embedded nul', str(e.exception)) + + # Expand the device tree so we now have room + self.fdt.resize(self.fdt.totalsize() + 50) + prop = 'prop-unicode' + self.fdt.setprop_str(node, prop, TEST_STRING_3) + self.assertEquals(TEST_STRING_3, + self.fdt.getprop(node, prop).as_str()) + if __name__ == "__main__": unittest.main() |