Skip to content

Commit

Permalink
tests: lib: devicetree: api: Add tests for IRQ_INTC_* macros
Browse files Browse the repository at this point in the history
Extend api test suite to cover the new devicetree macros. This
includes extending the devicetree overlay with two new bindings:

- GPIO device which is also an interrupt controller
- interrupt holder using interrupts-extended to point to both
  existing interrupt controller test_intc, and the newly added
  GPIO device

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
  • Loading branch information
bjarki-andreasen committed Dec 27, 2023
1 parent 6a2cd57 commit 451f810
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dts/bindings/test/vnd,gpio-intc-device.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2023 Bjarki Arge Andreasen
# SPDX-License-Identifier: Apache-2.0

description: Test GPIO with INTC node

compatible: "vnd,gpio-intc-device"

include:
- gpio-controller.yaml
- interrupt-controller.yaml
- base.yaml

properties:
reg:
required: true

"#gpio-cells":
const: 2

"#interrupt-cells":
const: 2

gpio-cells:
- pin
- flags

interrupt-cells:
- pin
- flags
15 changes: 15 additions & 0 deletions dts/bindings/test/vnd,interrupt-holder-extended.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2023 Bjarki Arge Andreasen
# SPDX-License-Identifier: Apache-2.0

description: Test Interrupt Controller with extended interrupts

compatible: "vnd,interrupt-holder-extended"

include: [base.yaml]

properties:
interrupts-extended:
required: true

interrupt-names:
required: true
19 changes: 19 additions & 0 deletions tests/lib/devicetree/api/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@
status = "okay";
};

test_gpio_4: gpio@1234abcd {
compatible = "vnd,gpio-intc-device";
reg = <0x1234abcd 0x500>;
gpio-controller;
#gpio-cells = <0x2>;
interrupt-controller;
#interrupt-cells = <0x2>;
status = "okay";
};

test_i2c: i2c@11112222 {
#address-cells = < 1 >;
#size-cells = < 0 >;
Expand Down Expand Up @@ -431,6 +441,15 @@
interrupt-names = "err", "stat", "done";
};

/* there should only be one of these */
test_irq_extended: interrupt-holder-extended {
compatible = "vnd,interrupt-holder-extended";
status = "okay";
interrupts-extended = <&test_intc 70 7>,
<&test_gpio_4 30 3>;
interrupt-names = "int1", "int2";
};

test_fixed_clk: test-fixed-clock {
compatible = "fixed-clock";
clock-frequency = <25000000>;
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/devicetree/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#define TEST_ARRAYS DT_NODELABEL(test_arrays)
#define TEST_PH DT_NODELABEL(test_phandles)
#define TEST_IRQ DT_NODELABEL(test_irq)
#define TEST_IRQ_EXT DT_NODELABEL(test_irq_extended)
#define TEST_TEMP DT_NODELABEL(test_temp_sensor)
#define TEST_REG DT_NODELABEL(test_reg)
#define TEST_VENDOR DT_NODELABEL(test_vendor)
#define TEST_MODEL DT_NODELABEL(test_vendor)
#define TEST_ENUM_0 DT_NODELABEL(test_enum_0)
#define TEST_64BIT DT_NODELABEL(test_reg_64)
#define TEST_INTC DT_NODELABEL(test_intc)

#define TEST_I2C DT_NODELABEL(test_i2c)
#define TEST_I2C_DEV DT_PATH(test, i2c_11112222, test_i2c_dev_10)
Expand All @@ -44,6 +46,7 @@

#define TEST_GPIO_1 DT_NODELABEL(test_gpio_1)
#define TEST_GPIO_2 DT_NODELABEL(test_gpio_2)
#define TEST_GPIO_4 DT_NODELABEL(test_gpio_4)

#define TEST_GPIO_HOG_1 DT_PATH(test, gpio_deadbeef, test_gpio_hog_1)
#define TEST_GPIO_HOG_2 DT_PATH(test, gpio_deadbeef, test_gpio_hog_2)
Expand Down Expand Up @@ -3149,4 +3152,31 @@ ZTEST(devicetree_api, test_reset)
zassert_equal(DT_INST_RESET_ID(0), 10, "");
}

#undef DT_DRV_COMPAT
#define DT_DRV_COMPAT vnd_interrupt_holder_extended
ZTEST(devicetree_api, test_interrupt_controller)
{
/* DT_IRQ_INTC_BY_IDX */
zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_IDX(TEST_IRQ_EXT, 0), TEST_INTC), "");
zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_IDX(TEST_IRQ_EXT, 1), TEST_GPIO_4), "");

/* DT_IRQ_INTC_BY_NAME */
zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_NAME(TEST_IRQ_EXT, int1), TEST_INTC), "");
zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_NAME(TEST_IRQ_EXT, int2), TEST_GPIO_4), "");

/* DT_IRQ_INTC */
zassert_true(DT_SAME_NODE(DT_IRQ_INTC(TEST_IRQ_EXT), TEST_INTC), "");

/* DT_INST_IRQ_INTC_BY_IDX */
zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_IDX(0, 0), TEST_INTC), "");
zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_IDX(0, 1), TEST_GPIO_4), "");

/* DT_INST_IRQ_INTC_BY_NAME */
zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_NAME(0, int1), TEST_INTC), "");
zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_NAME(0, int2), TEST_GPIO_4), "");

/* DT_INST_IRQ_INTC */
zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC(0), TEST_INTC), "");
}

ZTEST_SUITE(devicetree_api, NULL, NULL, NULL, NULL, NULL);

0 comments on commit 451f810

Please sign in to comment.