aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-09-12 12:27:13 -0600
committerDavid Gibson <david@gibson.dropbear.id.au>2023-09-15 16:00:43 +1000
commit52157f13ef3d45984ab17fd79bf0d9c69b57ae66 (patch)
treee9e3c8de02b06367c87bd88e2096216a6ba9fd51 /tests
parentd774337275666e013a5930aebace1c6f76e343b1 (diff)
downloaddtc-52157f13ef3d45984ab17fd79bf0d9c69b57ae66.zip
dtc-52157f13ef3d45984ab17fd79bf0d9c69b57ae66.tar.gz
dtc-52157f13ef3d45984ab17fd79bf0d9c69b57ae66.tar.bz2
pylibfdt: Support boolean propertiesHEADmastermain
Boolean properties are unusual in that their presense or absence indicates the value of the property. This makes them a little painful to support using the existing getprop() support. Add new methods to deal with booleans specifically. Signed-off-by: Simon Glass <sjg@chromium.org> Message-ID: <20230912182716.248253-1-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/pylibfdt_tests.py33
-rw-r--r--tests/test_props.dts1
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 34c2764..a4f73ed 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -496,6 +496,39 @@ class PyLibfdtBasicTests(unittest.TestCase):
self.assertEqual(TEST_STRING_3,
self.fdt.getprop(node, prop).as_str())
+ def testHasProp(self):
+ """Test that we can check if a node has a property"""
+ node = 0
+ self.assertFalse(self.fdt2.hasprop(node, 'missing'))
+ self.assertTrue(self.fdt2.hasprop(node, 'prop-bool'))
+
+ # Test a property with a non-empty value
+ self.assertTrue(self.fdt2.hasprop(node, 'prop-uint64'))
+
+ def testSetPropBool(self):
+ """Test that we can update and create boolean properties"""
+ node = 0
+ prop = 'prop-bool'
+
+ # Make some space and then try setting a new boolean property
+ self.fdt.resize(self.fdt.totalsize() + 50)
+ self.fdt.hasprop(node, 'missing')
+ self.fdt.setprop_bool(node, 'missing', True)
+ self.assertTrue(self.fdt.hasprop(node, 'missing'))
+
+ # Trying toggling an existing boolean property. Do each operation twice
+ # to make sure that the behaviour is correct when setting the property
+ # to the same value.
+ self.assertTrue(self.fdt2.hasprop(node, prop))
+ self.fdt2.setprop_bool(node, prop, False)
+ self.assertFalse(self.fdt2.hasprop(node, prop))
+ self.fdt2.setprop_bool(node, prop, False)
+ self.assertFalse(self.fdt2.hasprop(node, prop))
+ self.fdt2.setprop_bool(node, prop, True)
+ self.assertTrue(self.fdt2.hasprop(node, prop))
+ self.fdt2.setprop_bool(node, prop, True)
+ self.assertTrue(self.fdt2.hasprop(node, prop))
+
def testSetName(self):
"""Test that we can update a node name"""
node = self.fdt.path_offset('/subnode@1')
diff --git a/tests/test_props.dts b/tests/test_props.dts
index 5089023..09be197 100644
--- a/tests/test_props.dts
+++ b/tests/test_props.dts
@@ -12,4 +12,5 @@
prop-uint32-array = <0x1>, <0x98765432>, <0xdeadbeef>;
prop-int64-array = /bits/ 64 <0x100000000 0xfffffffffffffffe>;
prop-uint64-array = /bits/ 64 <0x100000000 0x1>;
+ prop-bool;
};