@@ -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 )
16581773static 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