Skip to content

Commit a9811ae

Browse files
hcodinageertu
authored andcommitted
of: unittest: Add a test case for for_each_of_imap_item iterator
Recently for_each_of_imap_item iterator has been introduce to help drivers in parsing the interrupt-map property. Add a test case for this iterator. Signed-off-by: Herve Codina (Schneider Electric) <herve.codina@bootlin.com> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Link: https://patch.msgid.link/20260114093938.1089936-3-herve.codina@bootlin.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent 49d2cda commit a9811ae

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

drivers/of/unittest-data/tests-interrupts.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
interrupt-map = <0x5000 1 2 &test_intc0 15>;
5151
};
5252

53+
intmap2 {
54+
#interrupt-cells = <2>;
55+
#address-cells = <0>;
56+
interrupt-map = <1 11 &test_intc0 100>,
57+
<2 22 &test_intc1 200 201 202>,
58+
<3 33 &test_intc2 300 301>,
59+
<4 44 &test_intc2 400 401>;
60+
};
61+
5362
test_intc_intmap0: intc-intmap0 {
5463
#interrupt-cells = <1>;
5564
#address-cells = <1>;

drivers/of/unittest.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,121 @@ static void __init of_unittest_parse_interrupts_extended(void)
16541654
of_node_put(np);
16551655
}
16561656

1657+
struct of_unittest_expected_imap_item {
1658+
u32 child_imap_count;
1659+
u32 child_imap[2];
1660+
const char *parent_path;
1661+
int parent_args_count;
1662+
u32 parent_args[3];
1663+
};
1664+
1665+
static const struct of_unittest_expected_imap_item of_unittest_expected_imap_items[] = {
1666+
{
1667+
.child_imap_count = 2,
1668+
.child_imap = {1, 11},
1669+
.parent_path = "/testcase-data/interrupts/intc0",
1670+
.parent_args_count = 1,
1671+
.parent_args = {100},
1672+
}, {
1673+
.child_imap_count = 2,
1674+
.child_imap = {2, 22},
1675+
.parent_path = "/testcase-data/interrupts/intc1",
1676+
.parent_args_count = 3,
1677+
.parent_args = {200, 201, 202},
1678+
}, {
1679+
.child_imap_count = 2,
1680+
.child_imap = {3, 33},
1681+
.parent_path = "/testcase-data/interrupts/intc2",
1682+
.parent_args_count = 2,
1683+
.parent_args = {300, 301},
1684+
}, {
1685+
.child_imap_count = 2,
1686+
.child_imap = {4, 44},
1687+
.parent_path = "/testcase-data/interrupts/intc2",
1688+
.parent_args_count = 2,
1689+
.parent_args = {400, 401},
1690+
}
1691+
};
1692+
1693+
static void __init of_unittest_parse_interrupt_map(void)
1694+
{
1695+
const struct of_unittest_expected_imap_item *expected_item;
1696+
struct device_node *imap_np, *expected_parent_np;
1697+
struct of_imap_parser imap_parser;
1698+
struct of_imap_item imap_item;
1699+
int count, ret, i;
1700+
1701+
if (of_irq_workarounds & (OF_IMAP_NO_PHANDLE | OF_IMAP_OLDWORLD_MAC))
1702+
return;
1703+
1704+
imap_np = of_find_node_by_path("/testcase-data/interrupts/intmap2");
1705+
if (!imap_np) {
1706+
pr_err("missing testcase data\n");
1707+
return;
1708+
}
1709+
1710+
ret = of_imap_parser_init(&imap_parser, imap_np, &imap_item);
1711+
if (unittest(!ret, "of_imap_parser_init(%pOF) returned error %d\n",
1712+
imap_np, ret))
1713+
goto end;
1714+
1715+
expected_item = of_unittest_expected_imap_items;
1716+
count = 0;
1717+
1718+
for_each_of_imap_item(&imap_parser, &imap_item) {
1719+
if (unittest(count < ARRAY_SIZE(of_unittest_expected_imap_items),
1720+
"imap item number %d not expected. Max number %zu\n",
1721+
count, ARRAY_SIZE(of_unittest_expected_imap_items) - 1)) {
1722+
of_node_put(imap_item.parent_args.np);
1723+
goto end;
1724+
}
1725+
1726+
expected_parent_np = of_find_node_by_path(expected_item->parent_path);
1727+
if (unittest(expected_parent_np,
1728+
"missing dependent testcase data (%s)\n",
1729+
expected_item->parent_path)) {
1730+
of_node_put(imap_item.parent_args.np);
1731+
goto end;
1732+
}
1733+
1734+
unittest(imap_item.child_imap_count == expected_item->child_imap_count,
1735+
"imap[%d] child_imap_count = %u, expected %u\n",
1736+
count, imap_item.child_imap_count,
1737+
expected_item->child_imap_count);
1738+
1739+
for (i = 0; i < expected_item->child_imap_count; i++)
1740+
unittest(imap_item.child_imap[i] == expected_item->child_imap[i],
1741+
"imap[%d] child_imap[%d] = %u, expected %u\n",
1742+
count, i, imap_item.child_imap[i],
1743+
expected_item->child_imap[i]);
1744+
1745+
unittest(imap_item.parent_args.np == expected_parent_np,
1746+
"imap[%d] parent np = %pOF, expected %pOF\n",
1747+
count, imap_item.parent_args.np, expected_parent_np);
1748+
1749+
unittest(imap_item.parent_args.args_count == expected_item->parent_args_count,
1750+
"imap[%d] parent param_count = %d, expected %d\n",
1751+
count, imap_item.parent_args.args_count,
1752+
expected_item->parent_args_count);
1753+
1754+
for (i = 0; i < expected_item->parent_args_count; i++)
1755+
unittest(imap_item.parent_args.args[i] == expected_item->parent_args[i],
1756+
"imap[%d] parent param[%d] = %u, expected %u\n",
1757+
count, i, imap_item.parent_args.args[i],
1758+
expected_item->parent_args[i]);
1759+
1760+
of_node_put(expected_parent_np);
1761+
count++;
1762+
expected_item++;
1763+
}
1764+
1765+
unittest(count == ARRAY_SIZE(of_unittest_expected_imap_items),
1766+
"Missing items. %d parsed, expected %zu\n",
1767+
count, ARRAY_SIZE(of_unittest_expected_imap_items));
1768+
end:
1769+
of_node_put(imap_np);
1770+
}
1771+
16571772
#if IS_ENABLED(CONFIG_OF_DYNAMIC)
16581773
static void __init of_unittest_irq_refcount(void)
16591774
{
@@ -4395,6 +4510,7 @@ static int __init of_unittest(void)
43954510
of_unittest_changeset_prop();
43964511
of_unittest_parse_interrupts();
43974512
of_unittest_parse_interrupts_extended();
4513+
of_unittest_parse_interrupt_map();
43984514
of_unittest_irq_refcount();
43994515
of_unittest_dma_get_max_cpu_address();
44004516
of_unittest_parse_dma_ranges();

0 commit comments

Comments
 (0)