diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..598968e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS +# +# SPDX-License-Identifier: Apache-2.0 + +# flake8: noqa + +import pathlib +import dts_utils +import pytest + + +class Dts: + def __init__(self): + self.dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts") + + +@pytest.fixture(scope="module") +def dts_file(): + return Dts() diff --git a/tests/test_dump.py b/tests/test_dump.py new file mode 100644 index 0000000..a65e708 --- /dev/null +++ b/tests/test_dump.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS +# +# SPDX-License-Identifier: Apache-2.0 + +# flake8: noqa + +import dts_utils +import dts_utils.dump + + +def test_dump(dts_file): + usart1_info = dts_utils.dump.dump(dts_file.dts, "usart1", True) diff --git a/tests/test_filters.py b/tests/test_filters.py new file mode 100644 index 0000000..4c49afc --- /dev/null +++ b/tests/test_filters.py @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS +# +# SPDX-License-Identifier: Apache-2.0 + +# flake8: noqa + +import dts_utils +import dts_utils.filters + + +def test_filter_enabled(dts_file): + pinctrl_list = dts_utils.filters.f_peripherals(dts_file.dts.soc.pinctrl) + enabled_gpios = dts_utils.filters.f_enabled(pinctrl_list) + assert len(enabled_gpios) == 7 + + +def test_filter_enabled_exceptions(dts_file): + try: + enabled_gpios = dts_utils.filters.f_enabled(dts_file.dts) + assert False + except dts_utils.exceptions.InvalidTemplateValueType: + assert True + + +def test_filter_owner(dts_file): + i2c1 = dts_file.dts.i2c1 + assert dts_utils.filters.f_owner(i2c1) == 0xBABE + + +def test_filter_owner_exceptions(dts_file): + try: + enabled_gpios = dts_utils.filters.f_owner(dts_file.dts) + assert False + except dts_utils.exceptions.InvalidTemplateValueType: + assert True + + +def test_filter_has_property(dts_file): + i2c1 = dts_file.dts.i2c1 + assert dts_utils.filters.f_has_property(i2c1, "outpost,owner") + + +def test_filter_has_property_exception(dts_file): + try: + dts_utils.filters.f_has_property(dts_file.dts, "outpost,owner") + assert False + except dts_utils.exceptions.InvalidTemplateValueType: + assert True + + +def test_filter_with_property(dts_file): + dev_list = dts_utils.filters.f_peripherals(dts_file.dts.root) + assert len(dts_utils.filters.f_with_property(dev_list, "outpost,owner")) == 1 + + +def test_filter_with_property_exception(dts_file): + try: + dts_utils.filters.f_with_property(dts_file.dts, "outpost,owner") + assert False + except dts_utils.exceptions.InvalidTemplateValueType: + assert True + try: + dts_utils.filters.f_with_property(dts_file.dts.usart1, "outpost,owner") + assert False + except dts_utils.exceptions.InvalidTemplateValueType: + assert True diff --git a/tests/test_load.py b/tests/test_load.py index c23f2ef..0c5404f 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -4,14 +4,9 @@ # flake8: noqa -import pathlib import dts_utils -def test_dtsload(): - dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts") - - -def test_socload(): - dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts") - soc = dts.soc +def test_socload(dts_file): + soc = dts_file.dts.soc + assert soc != None diff --git a/tests/test_node.py b/tests/test_node.py new file mode 100644 index 0000000..23618b2 --- /dev/null +++ b/tests/test_node.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS +# +# SPDX-License-Identifier: Apache-2.0 + +# flake8: noqa + +import dts_utils + + +def test_node_id(dts_file): + usart1 = dts_file.dts.usart1 + assert usart1.label == "usart1" + assert usart1.name == "serial@40013800"