tests: devicetree: check L2 interrupt encoding

Add some assert statements meant to check if L2 interrupts
are encoded right when dealing with nodes that consume interrupts
from multiple aggregators. For this to work, also add another
interrupt controller node which extends a different L1 interrupt
from `test_intc`.

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
(cherry picked from commit 8fec5f361ca73d9877300d3e81f13353c0a7deff)
diff --git a/tests/lib/devicetree/api/app.overlay b/tests/lib/devicetree/api/app.overlay
index a870eea..643bb09 100644
--- a/tests/lib/devicetree/api/app.overlay
+++ b/tests/lib/devicetree/api/app.overlay
@@ -430,6 +430,19 @@
 			interrupt-parent = <&test_cpu_intc>;
 		};
 
+		/* same as `test_intc` but extends a different L1 interrupt.
+		 * Required for testing if interrupts are encoded properly for
+		 * nodes consuming interrupts from different aggregators.
+		 */
+		test_intc2: interrupt-controller@bbbbdccc {
+			compatible = "vnd,intc";
+			reg = <0xbbbbdccc 0x1000>;
+			interrupt-controller;
+			#interrupt-cells = <2>;
+			interrupts = <12 0>;
+			interrupt-parent = <&test_cpu_intc>;
+		};
+
 		/* there should only be one of these */
 		test_irq: interrupt-holder {
 			compatible = "vnd,interrupt-holder";
@@ -444,8 +457,9 @@
 			compatible = "vnd,interrupt-holder-extended";
 			status = "okay";
 			interrupts-extended = <&test_intc 70 7>,
-					      <&test_gpio_4 30 3>;
-			interrupt-names = "int1", "int2";
+					      <&test_gpio_4 30 3>,
+					      <&test_intc2 42 7>;
+			interrupt-names = "int1", "int2", "int3";
 		};
 
 		test_fixed_clk: test-fixed-clock {
diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c
index c9a1d66..250c340 100644
--- a/tests/lib/devicetree/api/src/main.c
+++ b/tests/lib/devicetree/api/src/main.c
@@ -750,6 +750,20 @@
 	zassert_true(DT_INST_IRQ_HAS_NAME(0, stat), "");
 	zassert_true(DT_INST_IRQ_HAS_NAME(0, done), "");
 	zassert_false(DT_INST_IRQ_HAS_NAME(0, alpha), "");
+
+#ifdef CONFIG_MULTI_LEVEL_INTERRUPTS
+	/* the following asserts check if interrupt IDs are encoded
+	 * properly when dealing with a node that consumes interrupts
+	 * from L2 aggregators extending different L1 interrupts.
+	 */
+	zassert_equal(DT_IRQN_BY_IDX(TEST_IRQ_EXT, 0),
+		      ((70 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
+	zassert_equal(DT_IRQN_BY_IDX(TEST_IRQ_EXT, 2),
+		      ((42 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 12, "");
+#else
+	zassert_equal(DT_IRQN_BY_IDX(TEST_IRQ_EXT, 0), 70, "");
+	zassert_equal(DT_IRQN_BY_IDX(TEST_IRQ_EXT, 2), 42, "");
+#endif /* CONFIG_MULTI_LEVEL_INTERRUPTS */
 }
 
 ZTEST(devicetree_api, test_irq_level)