dtlib: allow dangling aliases with DT(..., force=True)
As a first step towards being more forgiving on invalid inputs, allow string-valued aliases properties that do not point to valid nodes when the user requests permissiveness. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
176225db58
commit
15db98a400
2 changed files with 24 additions and 5 deletions
|
@ -1684,8 +1684,15 @@ class DT:
|
||||||
_err("/aliases: alias property name '{}' should include "
|
_err("/aliases: alias property name '{}' should include "
|
||||||
"only characters from [0-9a-z-]".format(prop.name))
|
"only characters from [0-9a-z-]".format(prop.name))
|
||||||
|
|
||||||
# Property.to_path() already checks that the node exists
|
# Property.to_path() checks that the node exists, has
|
||||||
alias2node[prop.name] = prop.to_path()
|
# the right type, etc. Swallow errors for invalid
|
||||||
|
# aliases with self._force.
|
||||||
|
try:
|
||||||
|
alias2node[prop.name] = prop.to_path()
|
||||||
|
except DTError:
|
||||||
|
if self._force:
|
||||||
|
continue
|
||||||
|
raise
|
||||||
|
|
||||||
self.alias2node = alias2node
|
self.alias2node = alias2node
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,15 @@ from devicetree import dtlib
|
||||||
# - to run a particular test function or functions, use
|
# - to run a particular test function or functions, use
|
||||||
# '-k test_function_pattern_goes_here'
|
# '-k test_function_pattern_goes_here'
|
||||||
|
|
||||||
def parse(dts, include_path=()):
|
def parse(dts, include_path=(), **kwargs):
|
||||||
'''Parse a DTS string 'dts', using the given include path.'''
|
'''Parse a DTS string 'dts', using the given include path.
|
||||||
|
|
||||||
|
Any kwargs are passed on to DT().'''
|
||||||
|
|
||||||
fd, path = tempfile.mkstemp(prefix='pytest-', suffix='.dts')
|
fd, path = tempfile.mkstemp(prefix='pytest-', suffix='.dts')
|
||||||
try:
|
try:
|
||||||
os.write(fd, dts.encode('utf-8'))
|
os.write(fd, dts.encode('utf-8'))
|
||||||
return dtlib.DT(path, include_path)
|
return dtlib.DT(path, include_path, **kwargs)
|
||||||
finally:
|
finally:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
@ -2250,3 +2252,13 @@ l1: l2: &foo {
|
||||||
/ {
|
/ {
|
||||||
};
|
};
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def test_dangling_alias():
|
||||||
|
dt = parse('''
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
aliases { foo = "/missing"; };
|
||||||
|
};
|
||||||
|
''', force=True)
|
||||||
|
assert dt.get_node('/aliases').props['foo'].to_string() == '/missing'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue