devicetree: add tests for devicetree ranges API macros
Test cases for new APIs. Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
This commit is contained in:
parent
da512fd4d4
commit
2825481747
10
dts/bindings/test/vnd,pcie.yaml
Normal file
10
dts/bindings/test/vnd,pcie.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: Test PCIe bus controller
|
||||
|
||||
compatible: vnd,pcie
|
||||
|
||||
include: base.yaml
|
||||
|
||||
bus: pcie
|
|
@ -441,5 +441,30 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
test-ranges {
|
||||
#address-cells = <2>;
|
||||
#size-cells = <1>;
|
||||
|
||||
test_ranges_pcie: pcie@0 {
|
||||
compatible = "vnd,pcie";
|
||||
reg = <0 0 1>;
|
||||
#address-cells = <3>;
|
||||
#size-cells = <2>;
|
||||
|
||||
ranges = <0x1000000 0 0 0 0x3eff0000 0 0x10000>,
|
||||
<0x2000000 0 0x10000000 0 0x10000000 0 0x2eff0000>,
|
||||
<0x3000000 0x80 0 0x80 0 0x80 0>;
|
||||
};
|
||||
|
||||
test_ranges_other: other@1 {
|
||||
reg = <0 1 1>;
|
||||
#address-cells = <2>;
|
||||
#size-cells = <1>;
|
||||
|
||||
ranges = <0x0 0x0 0x0 0x3eff0000 0x10000>,
|
||||
<0x0 0x10000000 0x0 0x10000000 0x2eff0000>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
#define TEST_IO_CHANNEL_CTLR_1 DT_NODELABEL(test_adc_1)
|
||||
#define TEST_IO_CHANNEL_CTLR_2 DT_NODELABEL(test_adc_2)
|
||||
|
||||
#define TEST_RANGES_PCIE DT_NODELABEL(test_ranges_pcie)
|
||||
#define TEST_RANGES_OTHER DT_NODELABEL(test_ranges_other)
|
||||
|
||||
#define TA_HAS_COMPAT(compat) DT_NODE_HAS_COMPAT(TEST_ARRAYS, compat)
|
||||
|
||||
#define TO_STRING(x) TO_STRING_(x)
|
||||
|
@ -1723,6 +1726,123 @@ static void test_great_grandchild(void)
|
|||
zassert_equal(DT_PROP(DT_NODELABEL(test_ggc), ggc_prop), 42, "");
|
||||
}
|
||||
|
||||
#undef DT_DRV_COMPAT
|
||||
#define DT_DRV_COMPAT vnd_test_ranges_pcie
|
||||
static void test_ranges_pcie(void)
|
||||
{
|
||||
#define FLAGS(node_id, idx) \
|
||||
DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx),
|
||||
#define CHILD_BUS_ADDR(node_id, idx) \
|
||||
DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx),
|
||||
#define PARENT_BUS_ADDR(node_id, idx) \
|
||||
DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx),
|
||||
#define LENGTH(node_id, idx) DT_RANGES_LENGTH_BY_IDX(node_id, idx),
|
||||
|
||||
unsigned int count = DT_NUM_RANGES(TEST_RANGES_PCIE);
|
||||
|
||||
const uint64_t ranges_pcie_flags[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_PCIE, FLAGS)
|
||||
};
|
||||
|
||||
const uint64_t ranges_child_bus_addr[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_PCIE, CHILD_BUS_ADDR)
|
||||
};
|
||||
|
||||
const uint64_t ranges_parent_bus_addr[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_PCIE, PARENT_BUS_ADDR)
|
||||
};
|
||||
|
||||
const uint64_t ranges_length[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_PCIE, LENGTH)
|
||||
};
|
||||
|
||||
zassert_equal(count, 3, "");
|
||||
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_PCIE, 0), 1, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_PCIE, 1), 1, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_PCIE, 2), 1, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_PCIE, 3), 0, "");
|
||||
|
||||
zassert_equal(DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(TEST_RANGES_PCIE, 0),
|
||||
1, "");
|
||||
zassert_equal(DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(TEST_RANGES_PCIE, 1),
|
||||
1, "");
|
||||
zassert_equal(DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(TEST_RANGES_PCIE, 2),
|
||||
1, "");
|
||||
zassert_equal(DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(TEST_RANGES_PCIE, 3),
|
||||
0, "");
|
||||
|
||||
zassert_equal(ranges_pcie_flags[0], 0x1000000, "");
|
||||
zassert_equal(ranges_pcie_flags[1], 0x2000000, "");
|
||||
zassert_equal(ranges_pcie_flags[2], 0x3000000, "");
|
||||
zassert_equal(ranges_child_bus_addr[0], 0, "");
|
||||
zassert_equal(ranges_child_bus_addr[1], 0x10000000, "");
|
||||
zassert_equal(ranges_child_bus_addr[2], 0x8000000000, "");
|
||||
zassert_equal(ranges_parent_bus_addr[0], 0x3eff0000, "");
|
||||
zassert_equal(ranges_parent_bus_addr[1], 0x10000000, "");
|
||||
zassert_equal(ranges_parent_bus_addr[2], 0x8000000000, "");
|
||||
zassert_equal(ranges_length[0], 0x10000, "");
|
||||
zassert_equal(ranges_length[1], 0x2eff0000, "");
|
||||
zassert_equal(ranges_length[2], 0x8000000000, "");
|
||||
|
||||
#undef FLAGS
|
||||
#undef CHILD_BUS_ADDR
|
||||
#undef PARENT_BUS_ADDR
|
||||
#undef LENGTH
|
||||
}
|
||||
|
||||
static void test_ranges_other(void)
|
||||
{
|
||||
#define HAS_FLAGS(node_id, idx) \
|
||||
DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(node_id, idx)
|
||||
#define FLAGS(node_id, idx) \
|
||||
DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx),
|
||||
#define CHILD_BUS_ADDR(node_id, idx) \
|
||||
DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx),
|
||||
#define PARENT_BUS_ADDR(node_id, idx) \
|
||||
DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx),
|
||||
#define LENGTH(node_id, idx) DT_RANGES_LENGTH_BY_IDX(node_id, idx),
|
||||
|
||||
unsigned int count = DT_NUM_RANGES(TEST_RANGES_OTHER);
|
||||
|
||||
const uint32_t ranges_child_bus_addr[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_OTHER, CHILD_BUS_ADDR)
|
||||
};
|
||||
|
||||
const uint32_t ranges_parent_bus_addr[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_OTHER, PARENT_BUS_ADDR)
|
||||
};
|
||||
|
||||
const uint32_t ranges_length[] = {
|
||||
DT_FOREACH_RANGE(TEST_RANGES_OTHER, LENGTH)
|
||||
};
|
||||
|
||||
zassert_equal(count, 2, "");
|
||||
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_OTHER, 0), 1, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_OTHER, 1), 1, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_OTHER, 2), 0, "");
|
||||
zassert_equal(DT_RANGES_HAS_IDX(TEST_RANGES_OTHER, 3), 0, "");
|
||||
|
||||
zassert_equal(HAS_FLAGS(TEST_RANGES_OTHER, 0), 0, "");
|
||||
zassert_equal(HAS_FLAGS(TEST_RANGES_OTHER, 1), 0, "");
|
||||
zassert_equal(HAS_FLAGS(TEST_RANGES_OTHER, 2), 0, "");
|
||||
zassert_equal(HAS_FLAGS(TEST_RANGES_OTHER, 3), 0, "");
|
||||
|
||||
zassert_equal(ranges_child_bus_addr[0], 0, "");
|
||||
zassert_equal(ranges_child_bus_addr[1], 0x10000000, "");
|
||||
zassert_equal(ranges_parent_bus_addr[0], 0x3eff0000, "");
|
||||
zassert_equal(ranges_parent_bus_addr[1], 0x10000000, "");
|
||||
zassert_equal(ranges_length[0], 0x10000, "");
|
||||
zassert_equal(ranges_length[1], 0x2eff0000, "");
|
||||
|
||||
#undef HAS_FLAGS
|
||||
#undef FLAGS
|
||||
#undef CHILD_BUS_ADDR
|
||||
#undef PARENT_BUS_ADDR
|
||||
#undef LENGTH
|
||||
}
|
||||
|
||||
static void test_compat_get_any_status_okay(void)
|
||||
{
|
||||
zassert_true(
|
||||
|
@ -2148,6 +2268,8 @@ void test_main(void)
|
|||
ztest_unit_test(test_child_nodes_list),
|
||||
ztest_unit_test(test_child_nodes_list_varg),
|
||||
ztest_unit_test(test_great_grandchild),
|
||||
ztest_unit_test(test_ranges_pcie),
|
||||
ztest_unit_test(test_ranges_other),
|
||||
ztest_unit_test(test_compat_get_any_status_okay),
|
||||
ztest_unit_test(test_dep_ord),
|
||||
ztest_unit_test(test_path),
|
||||
|
|
Loading…
Reference in a new issue