コード例 #1
0
def test_child_binding():
    '''Test 'child-binding:' in bindings'''
    with from_here():
        edt = edtlib.EDT("test.dts", ["test-bindings"])
    child1 = edt.get_node("/child-binding/child-1")
    child2 = edt.get_node("/child-binding/child-2")
    grandchild = edt.get_node("/child-binding/child-1/grandchild")

    assert str(
        child1.binding_path) == hpath("test-bindings/child-binding.yaml")
    assert str(child1.description) == "child node"
    assert str(
        child1.props
    ) == "OrderedDict([('child-prop', <Property, name: child-prop, type: int, value: 1>)])"

    assert str(
        child2.binding_path) == hpath("test-bindings/child-binding.yaml")
    assert str(child2.description) == "child node"
    assert str(
        child2.props
    ) == "OrderedDict([('child-prop', <Property, name: child-prop, type: int, value: 3>)])"

    assert str(
        grandchild.binding_path) == hpath("test-bindings/child-binding.yaml")
    assert str(grandchild.description) == "grandchild node"
    assert str(
        grandchild.props
    ) == "OrderedDict([('grandchild-prop', <Property, name: grandchild-prop, type: int, value: 2>)])"

    with from_here():
        binding_file = Path("test-bindings/child-binding.yaml").resolve()
        top = edtlib.Binding(binding_file, {})
    child = top.child_binding
    assert Path(top.path) == binding_file
    assert Path(child.path) == binding_file
    assert top.compatible == 'top-binding'
    assert child.compatible is None

    with from_here():
        binding_file = Path(
            "test-bindings/child-binding-with-compat.yaml").resolve()
        top = edtlib.Binding(binding_file, {})
    child = top.child_binding
    assert Path(top.path) == binding_file
    assert Path(child.path) == binding_file
    assert top.compatible == 'top-binding-with-compat'
    assert child.compatible == 'child-compat'
コード例 #2
0
def test_wrong_props():
    '''Test Node.wrong_props (derived from DT and 'properties:' in the binding)'''

    with from_here():
        with pytest.raises(edtlib.EDTError) as e:
            edtlib.Binding(
                "test-wrong-bindings/wrong-specifier-space-type.yaml", None)
        assert (
            "'specifier-space' in 'properties: wrong-type-for-specifier-space' has type 'phandle', expected 'phandle-array'"
            in str(e.value))

        with pytest.raises(edtlib.EDTError) as e:
            edtlib.Binding("test-wrong-bindings/wrong-phandle-array-name.yaml",
                           None)
        value_str = str(e.value)
        assert value_str.startswith(
            "'wrong-phandle-array-name' in 'properties:'")
        assert value_str.endswith("but no 'specifier-space' was provided.")
コード例 #3
0
def load_base_binding():
    # Make a Binding object for base.yaml.
    #
    # This helps separate presentation for properties common to all
    # nodes from node-specific properties.

    base_yaml = ZEPHYR_BASE / 'dts' / 'bindings' / 'base' / 'base.yaml'
    if not base_yaml.is_file():
        sys.exit(f'Expected to find base.yaml at {base_yaml}')
    return edtlib.Binding(os.fspath(base_yaml), {}, require_compatible=False,
                          require_description=False)
コード例 #4
0
def test_include_filters():
    '''Test property-allowlist and property-blocklist in an include.'''

    fname2path = {
        'include.yaml': 'test-bindings-include/include.yaml',
        'include-2.yaml': 'test-bindings-include/include-2.yaml'
    }

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            edtlib.Binding("test-bindings-include/allow-and-blocklist.yaml",
                           fname2path)
    assert (
        "should not specify both 'property-allowlist:' and 'property-blocklist:'"
        in str(e.value))

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            edtlib.Binding(
                "test-bindings-include/allow-and-blocklist-child.yaml",
                fname2path)
    assert (
        "should not specify both 'property-allowlist:' and 'property-blocklist:'"
        in str(e.value))

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            edtlib.Binding("test-bindings-include/allow-not-list.yaml",
                           fname2path)
    value_str = str(e.value)
    assert value_str.startswith("'property-allowlist' value")
    assert value_str.endswith("should be a list")

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            edtlib.Binding("test-bindings-include/block-not-list.yaml",
                           fname2path)
    value_str = str(e.value)
    assert value_str.startswith("'property-blocklist' value")
    assert value_str.endswith("should be a list")

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            binding = edtlib.Binding(
                "test-bindings-include/include-invalid-keys.yaml", fname2path)
    value_str = str(e.value)
    assert value_str.startswith(
        "'include:' in test-bindings-include/include-invalid-keys.yaml should not have these "
        "unexpected contents: ")
    assert 'bad-key-1' in value_str
    assert 'bad-key-2' in value_str

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            binding = edtlib.Binding(
                "test-bindings-include/include-invalid-type.yaml", fname2path)
    value_str = str(e.value)
    assert value_str.startswith(
        "'include:' in test-bindings-include/include-invalid-type.yaml "
        "should be a string or list, but has type ")

    with pytest.raises(edtlib.EDTError) as e:
        with from_here():
            binding = edtlib.Binding(
                "test-bindings-include/include-no-name.yaml", fname2path)
    value_str = str(e.value)
    assert value_str.startswith("'include:' element")
    assert value_str.endswith(
        "in test-bindings-include/include-no-name.yaml should have a 'name' key"
    )

    with from_here():
        binding = edtlib.Binding("test-bindings-include/allowlist.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == {'x'}  # 'x' is allowed

        binding = edtlib.Binding("test-bindings-include/empty-allowlist.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == set()  # nothing is allowed

        binding = edtlib.Binding("test-bindings-include/blocklist.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == {'y', 'z'}  # 'x' is blocked

        binding = edtlib.Binding("test-bindings-include/empty-blocklist.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == {'x', 'y',
                                                  'z'}  # nothing is blocked

        binding = edtlib.Binding("test-bindings-include/intermixed.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == {'x', 'a'}

        binding = edtlib.Binding("test-bindings-include/include-no-list.yaml",
                                 fname2path)
        assert set(binding.prop2specs.keys()) == {'x', 'y', 'z'}

        binding = edtlib.Binding(
            "test-bindings-include/filter-child-bindings.yaml", fname2path)
        child = binding.child_binding
        grandchild = child.child_binding
        assert set(binding.prop2specs.keys()) == {'x'}
        assert set(child.prop2specs.keys()) == {'child-prop-2'}
        assert set(grandchild.prop2specs.keys()) == {'grandchild-prop-1'}