From 25f56342dac88f8adcf1f3e7b2f682a4bb25de89 Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 29 Nov 2024 16:58:57 +0000 Subject: [PATCH] tests: lib: devicetree: Add tests for endpoint DT macros Add tests for the new port / endpoint DT macros Signed-off-by: Josuah Demangeon Signed-off-by: Phi Bang Nguyen --- dts/bindings/test/vnd,video-multi-port.yaml | 14 ++++ dts/bindings/test/vnd,video-single-port.yaml | 13 +++ tests/lib/devicetree/api/app.overlay | 65 +++++++++++++++ tests/lib/devicetree/api/src/main.c | 86 ++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 dts/bindings/test/vnd,video-multi-port.yaml create mode 100644 dts/bindings/test/vnd,video-single-port.yaml diff --git a/dts/bindings/test/vnd,video-multi-port.yaml b/dts/bindings/test/vnd,video-multi-port.yaml new file mode 100644 index 00000000000000..dc459b03f0c42e --- /dev/null +++ b/dts/bindings/test/vnd,video-multi-port.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2024 tinyVision.ai Inc. +# SPDX-License-Identifier: Apache-2.0 + +description: Test Video device + +compatible: "vnd,video-multi-port" + +child-binding: + child-binding: + child-binding: + include: video-interfaces.yaml + properties: + reg: + type: array diff --git a/dts/bindings/test/vnd,video-single-port.yaml b/dts/bindings/test/vnd,video-single-port.yaml new file mode 100644 index 00000000000000..2c0df5bb34a9ce --- /dev/null +++ b/dts/bindings/test/vnd,video-single-port.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2024 tinyVision.ai Inc. +# SPDX-License-Identifier: Apache-2.0 + +description: Test Video device + +compatible: "vnd,video-single-port" + +child-binding: + child-binding: + include: video-interfaces.yaml + properties: + reg: + type: array diff --git a/tests/lib/devicetree/api/app.overlay b/tests/lib/devicetree/api/app.overlay index ba3af8b7650856..f5f643dcb08528 100644 --- a/tests/lib/devicetree/api/app.overlay +++ b/tests/lib/devicetree/api/app.overlay @@ -506,6 +506,71 @@ status = "okay"; }; + test_video0: video@10010000 { + compatible = "vnd,video-single-port"; + reg = <0x10010000 0x1000>; + + test_video0_port: port { + test_video0_out: endpoint { + remote-endpoint-label = "test_video2_port0_in0"; + }; + }; + }; + + test_video1: video@10011000 { + compatible = "vnd,video-single-port"; + reg = <0x10011000 0x1000>; + + test_video1_port: port { + #address-cells = <1>; + #size-cells = <0>; + + test_video1_out0: endpoint@0 { + reg = <0x0>; + remote-endpoint-label = "test_video2_port0_in1"; + }; + + test_video1_out1: endpoint@1 { + reg = <0x1>; + remote-endpoint-label = "test_video2_port1_in"; + }; + }; + }; + + test_video2: video@10012000 { + compatible = "vnd,video-multi-port"; + reg = <0x10012000 0x1000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + test_video2_port0: port@0 { + reg = <0x0>; + #address-cells = <1>; + #size-cells = <0>; + + test_video2_port0_in0: endpoint@0 { + reg = <0x0>; + remote-endpoint-label = "test_video0_out"; + }; + + test_video2_port0_in1: endpoint@1 { + reg = <0x1>; + remote-endpoint-label = "test_video1_out0"; + }; + }; + + test_video2_port1: port@1 { + reg = <0x1>; + + test_video2_port1_in: endpoint { + remote-endpoint-label = "test_video1_out1"; + }; + }; + }; + }; + test_pwm1: pwm@55551111 { compatible = "vnd,pwm"; #pwm-cells = <3>; diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 3c114d8df9181e..55337e7cf3cd1e 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -76,6 +76,20 @@ #define TEST_DMA_CTLR_1 DT_NODELABEL(test_dma1) #define TEST_DMA_CTLR_2 DT_NODELABEL(test_dma2) +#define TEST_VIDEO2 DT_NODELABEL(test_video2) +#define TEST_VIDEO2_PORT0 DT_NODELABEL(test_video2_port0) +#define TEST_VIDEO2_PORT0_IN0 DT_NODELABEL(test_video2_port0_in0) +#define TEST_VIDEO2_PORT0_IN1 DT_NODELABEL(test_video2_port0_in1) +#define TEST_VIDEO2_PORT1 DT_NODELABEL(test_video2_port1) +#define TEST_VIDEO2_PORT1_IN DT_NODELABEL(test_video2_port1_in) +#define TEST_VIDEO0 DT_NODELABEL(test_video0) +#define TEST_VIDEO0_OUT DT_NODELABEL(test_video0_out) +#define TEST_VIDEO0_PORT DT_NODELABEL(test_video0_port) +#define TEST_VIDEO1 DT_NODELABEL(test_video1) +#define TEST_VIDEO1_OUT0 DT_NODELABEL(test_video1_out0) +#define TEST_VIDEO1_OUT1 DT_NODELABEL(test_video1_out1) +#define TEST_VIDEO1_PORT DT_NODELABEL(test_video1_port) + #define TEST_IO_CHANNEL_CTLR_1 DT_NODELABEL(test_adc_1) #define TEST_IO_CHANNEL_CTLR_2 DT_NODELABEL(test_adc_2) @@ -1309,6 +1323,78 @@ ZTEST(devicetree_api, test_dma) zassert_false(DT_INST_DMAS_HAS_IDX(0, 2), ""); } +#undef DT_DRV_COMPAT +DT_FOREACH_STATUS_OKAY_VARGS(vnd_video_single_port, DEVICE_DT_DEFINE, NULL, NULL, NULL, NULL, + POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL); +DT_FOREACH_STATUS_OKAY_VARGS(vnd_video_multi_port, DEVICE_DT_DEFINE, NULL, NULL, NULL, NULL, + POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL); +ZTEST(devicetree_api, test_video) +{ + /* DT_INST_PORT_BY_ID */ +#define DT_DRV_COMPAT vnd_video_single_port + zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 0), + TEST_VIDEO0_PORT), "get port node of video0"); + zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(1, 0), TEST_VIDEO1_PORT), + "get port node of video1"); +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_video_multi_port + zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 0), TEST_VIDEO2_PORT0), + "get port@0 node of video2"); + zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 1), TEST_VIDEO2_PORT1), + "get port@1 node of video2"); +#undef DT_DRV_COMPAT + + /* DT_INST_ENDPOINT_BY_ID */ +#define DT_DRV_COMPAT vnd_video_single_port + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 0), TEST_VIDEO0_OUT), + "get endpoint node of port node of video0"); + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(1, 0, 0), TEST_VIDEO1_OUT0), + "get endpoint@0 node of port node of video1"); + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(1, 0, 1), TEST_VIDEO1_OUT1), + "get endpoint@1 node of port node of video1"); +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_video_multi_port + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 0), TEST_VIDEO2_PORT0_IN0), + "get endpoint@0 node of port@0 node of video2"); + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 1), TEST_VIDEO2_PORT0_IN1), + "get endpoint@1 node of port@0 node of video2"); + zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 1, 0), TEST_VIDEO2_PORT1_IN), + "get endpoint node of port@1 node of video2"); +#undef DT_DRV_COMPAT + + /* DT_NODE_BY_ENDPOINT */ + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO0_OUT), + TEST_VIDEO0), "get video0 node from its endpoint"); + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO1_OUT0), TEST_VIDEO1), + "get video1 node from its endpoint@0"); + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO1_OUT1), TEST_VIDEO1), + "get video1 node from its endpoint@1"); + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT0_IN0), TEST_VIDEO2), + "get video2 node from its endpoint@0 at port@0"); + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT0_IN1), TEST_VIDEO2), + "get video2 node from its endpoint@1 at port@0"); + zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT1_IN), TEST_VIDEO2), + "get video2 node from its endpoint at port@1"); + + /* DT_NODE_REMOTE_DEVICE */ +#define DT_DRV_COMPAT vnd_video_single_port + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO0_OUT), TEST_VIDEO2), + "get remote device node of video0's endpoint"); + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO1_OUT0), TEST_VIDEO2), + "get remote device node of video1's endpoint@0"); + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO1_OUT1), TEST_VIDEO2), + "get remote device node of video1's endpoint@1"); +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_video_multi_port + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT0_IN0), TEST_VIDEO0), + "get remote device node of video2's port@0 endpoint@0"); + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT0_IN1), TEST_VIDEO1), + "get remote device node of video2's port@0 endpoint@1"); + zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT1_IN), TEST_VIDEO1), + "get remote device node of video2's port@1 endpoint"); +#undef DT_DRV_COMPAT +} + #undef DT_DRV_COMPAT #define DT_DRV_COMPAT vnd_phandle_holder ZTEST(devicetree_api, test_pwms)