Skip to content

Commit 6c08072

Browse files
josuahngphibang
authored andcommitted
tests: lib: devicetree: Add tests for endpoint DT macros
Add tests for the new port / endpoint DT macros Signed-off-by: Josuah Demangeon <[email protected]> Signed-off-by: Phi Bang Nguyen <[email protected]>
1 parent 0c68dfd commit 6c08072

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024 tinyVision.ai Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Test Video device
5+
6+
compatible: "vnd,video-multi-port"
7+
8+
child-binding:
9+
child-binding:
10+
child-binding:
11+
include: video-interfaces.yaml
12+
properties:
13+
reg:
14+
type: array
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2024 tinyVision.ai Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Test Video device
5+
6+
compatible: "vnd,video-single-port"
7+
8+
child-binding:
9+
child-binding:
10+
include: video-interfaces.yaml
11+
properties:
12+
reg:
13+
type: array

tests/lib/devicetree/api/app.overlay

+65
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,71 @@
506506
status = "okay";
507507
};
508508

509+
test_video0: video@10010000 {
510+
compatible = "vnd,video-single-port";
511+
reg = <0x10010000 0x1000>;
512+
513+
test_video0_port: port {
514+
test_video0_out: endpoint {
515+
remote-endpoint-label = "test_video2_port0_in0";
516+
};
517+
};
518+
};
519+
520+
test_video1: video@10011000 {
521+
compatible = "vnd,video-single-port";
522+
reg = <0x10011000 0x1000>;
523+
524+
test_video1_port: port {
525+
#address-cells = <1>;
526+
#size-cells = <0>;
527+
528+
test_video1_out0: endpoint@0 {
529+
reg = <0x0>;
530+
remote-endpoint-label = "test_video2_port0_in1";
531+
};
532+
533+
test_video1_out1: endpoint@1 {
534+
reg = <0x1>;
535+
remote-endpoint-label = "test_video2_port1_in";
536+
};
537+
};
538+
};
539+
540+
test_video2: video@10012000 {
541+
compatible = "vnd,video-multi-port";
542+
reg = <0x10012000 0x1000>;
543+
544+
ports {
545+
#address-cells = <1>;
546+
#size-cells = <0>;
547+
548+
test_video2_port0: port@0 {
549+
reg = <0x0>;
550+
#address-cells = <1>;
551+
#size-cells = <0>;
552+
553+
test_video2_port0_in0: endpoint@0 {
554+
reg = <0x0>;
555+
remote-endpoint-label = "test_video0_out";
556+
};
557+
558+
test_video2_port0_in1: endpoint@1 {
559+
reg = <0x1>;
560+
remote-endpoint-label = "test_video1_out0";
561+
};
562+
};
563+
564+
test_video2_port1: port@1 {
565+
reg = <0x1>;
566+
567+
test_video2_port1_in: endpoint {
568+
remote-endpoint-label = "test_video1_out1";
569+
};
570+
};
571+
};
572+
};
573+
509574
test_pwm1: pwm@55551111 {
510575
compatible = "vnd,pwm";
511576
#pwm-cells = <3>;

tests/lib/devicetree/api/src/main.c

+86
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@
7676
#define TEST_DMA_CTLR_1 DT_NODELABEL(test_dma1)
7777
#define TEST_DMA_CTLR_2 DT_NODELABEL(test_dma2)
7878

79+
#define TEST_VIDEO2 DT_NODELABEL(test_video2)
80+
#define TEST_VIDEO2_PORT0 DT_NODELABEL(test_video2_port0)
81+
#define TEST_VIDEO2_PORT0_IN0 DT_NODELABEL(test_video2_port0_in0)
82+
#define TEST_VIDEO2_PORT0_IN1 DT_NODELABEL(test_video2_port0_in1)
83+
#define TEST_VIDEO2_PORT1 DT_NODELABEL(test_video2_port1)
84+
#define TEST_VIDEO2_PORT1_IN DT_NODELABEL(test_video2_port1_in)
85+
#define TEST_VIDEO0 DT_NODELABEL(test_video0)
86+
#define TEST_VIDEO0_OUT DT_NODELABEL(test_video0_out)
87+
#define TEST_VIDEO0_PORT DT_NODELABEL(test_video0_port)
88+
#define TEST_VIDEO1 DT_NODELABEL(test_video1)
89+
#define TEST_VIDEO1_OUT0 DT_NODELABEL(test_video1_out0)
90+
#define TEST_VIDEO1_OUT1 DT_NODELABEL(test_video1_out1)
91+
#define TEST_VIDEO1_PORT DT_NODELABEL(test_video1_port)
92+
7993
#define TEST_IO_CHANNEL_CTLR_1 DT_NODELABEL(test_adc_1)
8094
#define TEST_IO_CHANNEL_CTLR_2 DT_NODELABEL(test_adc_2)
8195

@@ -1309,6 +1323,78 @@ ZTEST(devicetree_api, test_dma)
13091323
zassert_false(DT_INST_DMAS_HAS_IDX(0, 2), "");
13101324
}
13111325

1326+
#undef DT_DRV_COMPAT
1327+
DT_FOREACH_STATUS_OKAY_VARGS(vnd_video_single_port, DEVICE_DT_DEFINE, NULL, NULL, NULL, NULL,
1328+
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL);
1329+
DT_FOREACH_STATUS_OKAY_VARGS(vnd_video_multi_port, DEVICE_DT_DEFINE, NULL, NULL, NULL, NULL,
1330+
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL);
1331+
ZTEST(devicetree_api, test_video)
1332+
{
1333+
/* DT_INST_PORT_BY_ID */
1334+
#define DT_DRV_COMPAT vnd_video_single_port
1335+
zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 0),
1336+
TEST_VIDEO0_PORT), "get port node of video0");
1337+
zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(1, 0), TEST_VIDEO1_PORT),
1338+
"get port node of video1");
1339+
#undef DT_DRV_COMPAT
1340+
#define DT_DRV_COMPAT vnd_video_multi_port
1341+
zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 0), TEST_VIDEO2_PORT0),
1342+
"get port@0 node of video2");
1343+
zassert_true(DT_SAME_NODE(DT_INST_PORT_BY_ID(0, 1), TEST_VIDEO2_PORT1),
1344+
"get port@1 node of video2");
1345+
#undef DT_DRV_COMPAT
1346+
1347+
/* DT_INST_ENDPOINT_BY_ID */
1348+
#define DT_DRV_COMPAT vnd_video_single_port
1349+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 0), TEST_VIDEO0_OUT),
1350+
"get endpoint node of port node of video0");
1351+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(1, 0, 0), TEST_VIDEO1_OUT0),
1352+
"get endpoint@0 node of port node of video1");
1353+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(1, 0, 1), TEST_VIDEO1_OUT1),
1354+
"get endpoint@1 node of port node of video1");
1355+
#undef DT_DRV_COMPAT
1356+
#define DT_DRV_COMPAT vnd_video_multi_port
1357+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 0), TEST_VIDEO2_PORT0_IN0),
1358+
"get endpoint@0 node of port@0 node of video2");
1359+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 0, 1), TEST_VIDEO2_PORT0_IN1),
1360+
"get endpoint@1 node of port@0 node of video2");
1361+
zassert_true(DT_SAME_NODE(DT_INST_ENDPOINT_BY_ID(0, 1, 0), TEST_VIDEO2_PORT1_IN),
1362+
"get endpoint node of port@1 node of video2");
1363+
#undef DT_DRV_COMPAT
1364+
1365+
/* DT_NODE_BY_ENDPOINT */
1366+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO0_OUT),
1367+
TEST_VIDEO0), "get video0 node from its endpoint");
1368+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO1_OUT0), TEST_VIDEO1),
1369+
"get video1 node from its endpoint@0");
1370+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO1_OUT1), TEST_VIDEO1),
1371+
"get video1 node from its endpoint@1");
1372+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT0_IN0), TEST_VIDEO2),
1373+
"get video2 node from its endpoint@0 at port@0");
1374+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT0_IN1), TEST_VIDEO2),
1375+
"get video2 node from its endpoint@1 at port@0");
1376+
zassert_true(DT_SAME_NODE(DT_NODE_BY_ENDPOINT(TEST_VIDEO2_PORT1_IN), TEST_VIDEO2),
1377+
"get video2 node from its endpoint at port@1");
1378+
1379+
/* DT_NODE_REMOTE_DEVICE */
1380+
#define DT_DRV_COMPAT vnd_video_single_port
1381+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO0_OUT), TEST_VIDEO2),
1382+
"get remote device node of video0's endpoint");
1383+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO1_OUT0), TEST_VIDEO2),
1384+
"get remote device node of video1's endpoint@0");
1385+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO1_OUT1), TEST_VIDEO2),
1386+
"get remote device node of video1's endpoint@1");
1387+
#undef DT_DRV_COMPAT
1388+
#define DT_DRV_COMPAT vnd_video_multi_port
1389+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT0_IN0), TEST_VIDEO0),
1390+
"get remote device node of video2's port@0 endpoint@0");
1391+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT0_IN1), TEST_VIDEO1),
1392+
"get remote device node of video2's port@0 endpoint@1");
1393+
zassert_true(DT_SAME_NODE(DT_NODE_REMOTE_DEVICE(TEST_VIDEO2_PORT1_IN), TEST_VIDEO1),
1394+
"get remote device node of video2's port@1 endpoint");
1395+
#undef DT_DRV_COMPAT
1396+
}
1397+
13121398
#undef DT_DRV_COMPAT
13131399
#define DT_DRV_COMPAT vnd_phandle_holder
13141400
ZTEST(devicetree_api, test_pwms)

0 commit comments

Comments
 (0)