Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions tests/test_dump.py
Original file line number Diff line number Diff line change
@@ -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)
66 changes: 66 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 3 additions & 8 deletions tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
@@ -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"