|
| 1 | +# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +# flake8: noqa |
| 6 | + |
| 7 | +import pathlib |
| 8 | +import dts_utils |
| 9 | +import dts_utils.filters |
| 10 | + |
| 11 | + |
| 12 | +def _get_dtsload() -> dts_utils.Dts: |
| 13 | + return dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts") |
| 14 | + |
| 15 | + |
| 16 | +def test_filter_enabled(): |
| 17 | + dts = _get_dtsload() |
| 18 | + pinctrl_list = dts_utils.filters.f_peripherals(dts.soc.pinctrl) |
| 19 | + enabled_gpios = dts_utils.filters.f_enabled(pinctrl_list) |
| 20 | + assert len(enabled_gpios) == 7 |
| 21 | + |
| 22 | + |
| 23 | +def test_filter_enabled_exceptions(): |
| 24 | + dts = _get_dtsload() |
| 25 | + try: |
| 26 | + enabled_gpios = dts_utils.filters.f_enabled(dts) |
| 27 | + assert False |
| 28 | + except dts_utils.exceptions.InvalidTemplateValueType: |
| 29 | + assert True |
| 30 | + |
| 31 | + |
| 32 | +def test_filter_owner(): |
| 33 | + dts = _get_dtsload() |
| 34 | + i2c1 = dts.i2c1 |
| 35 | + assert dts_utils.filters.f_owner(i2c1) == 0xBABE |
| 36 | + |
| 37 | + |
| 38 | +def test_filter_owner_exceptions(): |
| 39 | + dts = _get_dtsload() |
| 40 | + try: |
| 41 | + enabled_gpios = dts_utils.filters.f_owner(dts) |
| 42 | + assert False |
| 43 | + except dts_utils.exceptions.InvalidTemplateValueType: |
| 44 | + assert True |
| 45 | + |
| 46 | + |
| 47 | +def test_filter_has_property(): |
| 48 | + dts = _get_dtsload() |
| 49 | + i2c1 = dts.i2c1 |
| 50 | + assert dts_utils.filters.f_has_property(i2c1, "outpost,owner") |
| 51 | + |
| 52 | + |
| 53 | +def test_filter_has_property_exception(): |
| 54 | + dts = _get_dtsload() |
| 55 | + try: |
| 56 | + dts_utils.filters.f_has_property(dts, "outpost,owner") |
| 57 | + assert False |
| 58 | + except dts_utils.exceptions.InvalidTemplateValueType: |
| 59 | + assert True |
| 60 | + |
| 61 | + |
| 62 | +def test_filter_with_property(): |
| 63 | + dts = _get_dtsload() |
| 64 | + dev_list = dts_utils.filters.f_peripherals(dts.root) |
| 65 | + assert len(dts_utils.filters.f_with_property(dev_list, "outpost,owner")) == 1 |
| 66 | + |
| 67 | + |
| 68 | +def test_filter_with_property_exception(): |
| 69 | + dts = _get_dtsload() |
| 70 | + try: |
| 71 | + dts_utils.filters.f_with_property(dts, "outpost,owner") |
| 72 | + assert False |
| 73 | + except dts_utils.exceptions.InvalidTemplateValueType: |
| 74 | + assert True |
| 75 | + try: |
| 76 | + dts_utils.filters.f_with_property(dts.usart1, "outpost,owner") |
| 77 | + assert False |
| 78 | + except dts_utils.exceptions.InvalidTemplateValueType: |
| 79 | + assert True |
0 commit comments