From 7d4e31a1f03b0df864d95d1059ade513278dde3e Mon Sep 17 00:00:00 2001 From: Wenbin Zhang Date: Sun, 18 Aug 2024 23:21:18 +0800 Subject: [PATCH] devicetree: Fix Device tree tests cannot be built with coverage enabled DT_SPEC related macro tests (ADC_DT_SPEC_GET_BY_NAME, MBOX_DT_SPEC_GET) should not appear in this test because the configuration does not turn on any devices Move DP_SPEC-related tests to api_ext and enable the related device in the configuration fix #77205 Signed-off-by: Wenbin Zhang --- tests/lib/devicetree/api/src/main.c | 41 -------------------- tests/lib/devicetree/api_ext/app.overlay | 48 ++++++++++++++++++++++++ tests/lib/devicetree/api_ext/prj.conf | 2 + tests/lib/devicetree/api_ext/src/main.c | 43 ++++++++++++++++++++- 4 files changed, 91 insertions(+), 43 deletions(-) diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index ae87818b4e7..5b671a70fc2 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -7,9 +7,7 @@ #include #include #include -#include #include -#include #include @@ -1257,27 +1255,6 @@ ZTEST(devicetree_api, test_io_channels) zassert_equal(DT_INST_IO_CHANNELS_INPUT(0), 10, ""); } -#undef DT_DRV_COMPAT -#define DT_DRV_COMPAT vnd_adc_temp_sensor -ZTEST(devicetree_api, test_io_channel_names) -{ - struct adc_dt_spec adc_spec; - - /* ADC_DT_SPEC_GET_BY_NAME */ - adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch1); - zassert_equal(adc_spec.channel_id, 10, ""); - - adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch2); - zassert_equal(adc_spec.channel_id, 20, ""); - - /* ADC_DT_SPEC_INST_GET_BY_NAME */ - adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch1); - zassert_equal(adc_spec.channel_id, 10, ""); - - adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch2); - zassert_equal(adc_spec.channel_id, 20, ""); -} - #undef DT_DRV_COMPAT #define DT_DRV_COMPAT vnd_adc_temp_sensor ZTEST(devicetree_api, test_dma) @@ -3095,22 +3072,8 @@ ZTEST(devicetree_api, test_pinctrl) zassert_equal(DT_INST_PINCTRL_HAS_NAME(0, f_o_o2), 0, ""); } -DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL, - 90, NULL); -DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox_zero_cell), NULL, NULL, NULL, NULL, - POST_KERNEL, 90, NULL); - ZTEST(devicetree_api, test_mbox) { -#undef DT_DRV_COMPAT -#define DT_DRV_COMPAT vnd_adc_temp_sensor - - const struct mbox_dt_spec channel_tx = MBOX_DT_SPEC_GET(TEST_TEMP, tx); - const struct mbox_dt_spec channel_rx = MBOX_DT_SPEC_GET(TEST_TEMP, rx); - - zassert_equal(channel_tx.channel_id, 1, ""); - zassert_equal(channel_rx.channel_id, 2, ""); - zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, tx), 1, ""); zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, rx), 2, ""); @@ -3122,10 +3085,6 @@ ZTEST(devicetree_api, test_mbox) zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, tx), 1, ""); zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, rx), 2, ""); - const struct mbox_dt_spec channel_zero = MBOX_DT_SPEC_GET(TEST_TEMP, zero); - - zassert_equal(channel_zero.channel_id, 0, ""); - zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, zero), 0, ""); zassert_true(DT_SAME_NODE(DT_MBOX_CTLR_BY_NAME(TEST_TEMP, zero), diff --git a/tests/lib/devicetree/api_ext/app.overlay b/tests/lib/devicetree/api_ext/app.overlay index 22a6e9ee8c5..5f20b5cbbf9 100644 --- a/tests/lib/devicetree/api_ext/app.overlay +++ b/tests/lib/devicetree/api_ext/app.overlay @@ -26,5 +26,53 @@ reg = < 0x20001000 0x1000 >; zephyr,memory-region = "SRAM@REGION#2"; }; + + test_fixed_clk: test-fixed-clock { + compatible = "fixed-clock"; + clock-frequency = <25000000>; + #clock-cells = <0>; + }; + + test_clk: test-clock { + compatible = "vnd,clock"; + #clock-cells = <2>; + }; + + test_adc_1: adc@10002000 { + reg = <0x10002000 0x1000>; + compatible = "vnd,adc"; + status = "okay"; + #io-channel-cells = <1>; + }; + + test_adc_2: adc@10003000 { + reg = <0x10003000 0x1000>; + compatible = "vnd,adc"; + status = "okay"; + #io-channel-cells = <1>; + }; + + test_mbox: mbox { + compatible = "vnd,mbox"; + #mbox-cells = <1>; + status = "okay"; + }; + + test_mbox_zero_cell: mbox_zero_cell { + compatible = "vnd,mbox-zero-cell"; + #mbox-cells = <0>; + status = "okay"; + }; + + /* there should only be one of these */ + test_temp_sensor: temperature-sensor { + compatible = "vnd,adc-temp-sensor"; + clocks = <&test_clk 3 7>, <&test_fixed_clk>, <&test_clk 8 2>; + clock-names = "clk-a", "clk-fixed", "clk-b"; + io-channels = <&test_adc_1 10>, <&test_adc_2 20>; + io-channel-names = "ch1", "ch2"; + mboxes = <&test_mbox 1>, <&test_mbox 2>, <&test_mbox_zero_cell>; + mbox-names = "tx", "rx", "zero"; + }; }; }; diff --git a/tests/lib/devicetree/api_ext/prj.conf b/tests/lib/devicetree/api_ext/prj.conf index 9467c292689..80789f1bf70 100644 --- a/tests/lib/devicetree/api_ext/prj.conf +++ b/tests/lib/devicetree/api_ext/prj.conf @@ -1 +1,3 @@ CONFIG_ZTEST=y +CONFIG_ADC=y +CONFIG_MBOX=y diff --git a/tests/lib/devicetree/api_ext/src/main.c b/tests/lib/devicetree/api_ext/src/main.c index f865cd268db..d3f742990d5 100644 --- a/tests/lib/devicetree/api_ext/src/main.c +++ b/tests/lib/devicetree/api_ext/src/main.c @@ -8,11 +8,15 @@ #include #include #include +#include +#include +#include #include -#define TEST_SRAM1 DT_NODELABEL(test_sram1) -#define TEST_SRAM2 DT_NODELABEL(test_sram2) +#define TEST_SRAM1 DT_NODELABEL(test_sram1) +#define TEST_SRAM2 DT_NODELABEL(test_sram2) +#define TEST_TEMP DT_NODELABEL(test_temp_sensor) ZTEST(devicetree_api_ext, test_linker_regions) { @@ -20,4 +24,39 @@ ZTEST(devicetree_api_ext, test_linker_regions) zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM2), "SRAM_REGION_2"), ""); } +#define DT_DRV_COMPAT vnd_adc_temp_sensor +ZTEST(devicetree_api_ext, test_adc_dt_spec) +{ + struct adc_dt_spec adc_spec; + + /* ADC_DT_SPEC_GET_BY_NAME */ + adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch1); + zassert_equal(adc_spec.channel_id, 10, ""); + + adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch2); + zassert_equal(adc_spec.channel_id, 20, ""); + + /* ADC_DT_SPEC_INST_GET_BY_NAME */ + adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch1); + zassert_equal(adc_spec.channel_id, 10, ""); + + adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch2); + zassert_equal(adc_spec.channel_id, 20, ""); +} + +DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL); +DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox_zero_cell), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL); +ZTEST(devicetree_api_ext, test_mbox_dt_spec) +{ + const struct mbox_dt_spec channel_tx = MBOX_DT_SPEC_GET(TEST_TEMP, tx); + const struct mbox_dt_spec channel_rx = MBOX_DT_SPEC_GET(TEST_TEMP, rx); + + zassert_equal(channel_tx.channel_id, 1, ""); + zassert_equal(channel_rx.channel_id, 2, ""); + + const struct mbox_dt_spec channel_zero = MBOX_DT_SPEC_GET(TEST_TEMP, zero); + + zassert_equal(channel_zero.channel_id, 0, ""); +} + ZTEST_SUITE(devicetree_api_ext, NULL, NULL, NULL, NULL, NULL);