Skip to content

Commit

Permalink
tests: devicetree: api: add tests for new DT APIs
Browse files Browse the repository at this point in the history
Add tests for new DT APIs added in the previous commit:
- `DT_IRQN_BY_IDX`
- `DT_INST_IRQN_BY_IDX`

Added additional tests for the following existing DT APIs when
`CONFIG_MULTI_LEVEL_INTERRUPTS` is enabled:
- `DT_IRQN`
- `DT_INST_IRQN`

Added `qemu_riscv32` for the multi-level interrupt tests.

Signed-off-by: Yong Cong Sin <[email protected]>
  • Loading branch information
ycsin authored and cfriedt committed Oct 30, 2023
1 parent df2c068 commit 1782011
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/lib/devicetree/api/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,15 @@
reg = <0xbbbbcccc 0x1000>;
interrupt-controller;
#interrupt-cells = <2>;
interrupts = <11 0>;
};

/* there should only be one of these */
test_irq: interrupt-holder {
compatible = "vnd,interrupt-holder";
status = "okay";
interrupts = <30 3 40 5 60 7>;
interrupt-parent = <&test_intc>;
interrupt-names = "err", "stat", "done";
};

Expand Down
38 changes: 38 additions & 0 deletions tests/lib/devicetree/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,26 @@ ZTEST(devicetree_api, test_irq)

/* DT_IRQN */
zassert_equal(DT_IRQN(TEST_I2C_BUS), 6, "");
#ifndef CONFIG_MULTI_LEVEL_INTERRUPTS
zassert_equal(DT_IRQN(DT_INST(0, DT_DRV_COMPAT)), 30, "");
#else
zassert_equal(DT_IRQN(DT_INST(0, DT_DRV_COMPAT)),
((30 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
#endif

/* DT_IRQN_BY_IDX */
#ifndef CONFIG_MULTI_LEVEL_INTERRUPTS
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 0), 30, "");
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 1), 40, "");
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 2), 60, "");
#else
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 0),
((30 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 1),
((40 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
zassert_equal(DT_IRQN_BY_IDX(DT_INST(0, DT_DRV_COMPAT), 2),
((60 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
#endif

/* DT_INST */
zassert_equal(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT), 1, "");
Expand Down Expand Up @@ -738,7 +758,25 @@ ZTEST(devicetree_api, test_irq)
zassert_equal(DT_INST_IRQ(0, priority), 3, "");

/* DT_INST_IRQN */
#ifndef CONFIG_MULTI_LEVEL_INTERRUPTS
zassert_equal(DT_INST_IRQN(0), 30, "");
#else
zassert_equal(DT_INST_IRQN(0), ((30 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
#endif

/* DT_INST_IRQN_BY_IDX */
#ifndef CONFIG_MULTI_LEVEL_INTERRUPTS
zassert_equal(DT_INST_IRQN_BY_IDX(0, 0), 30, "");
zassert_equal(DT_INST_IRQN_BY_IDX(0, 1), 40, "");
zassert_equal(DT_INST_IRQN_BY_IDX(0, 2), 60, "");
#else
zassert_equal(DT_INST_IRQN_BY_IDX(0, 0),
((30 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
zassert_equal(DT_INST_IRQN_BY_IDX(0, 1),
((40 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
zassert_equal(DT_INST_IRQN_BY_IDX(0, 2),
((60 + 1) << CONFIG_1ST_LEVEL_INTERRUPT_BITS) | 11, "");
#endif

/* DT_INST_IRQ_HAS_CELL_AT_IDX */
zassert_true(DT_INST_IRQ_HAS_CELL_AT_IDX(0, 0, irq), "");
Expand Down
1 change: 1 addition & 0 deletions tests/lib/devicetree/api/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ tests:
- qemu_x86
- qemu_x86_64
- qemu_cortex_m3
- qemu_riscv32
integration_platforms:
- native_posix

0 comments on commit 1782011

Please sign in to comment.