Skip to content

Commit 7d4e31a

Browse files
Freey0kartben
authored andcommitted
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 zephyrproject-rtos#77205 Signed-off-by: Wenbin Zhang <[email protected]>
1 parent b0dbbb7 commit 7d4e31a

File tree

4 files changed

+91
-43
lines changed

4 files changed

+91
-43
lines changed

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include <zephyr/ztest.h>
88
#include <zephyr/devicetree.h>
99
#include <zephyr/device.h>
10-
#include <zephyr/drivers/adc.h>
1110
#include <zephyr/drivers/gpio.h>
12-
#include <zephyr/drivers/mbox.h>
1311

1412
#include <stdlib.h>
1513

@@ -1257,27 +1255,6 @@ ZTEST(devicetree_api, test_io_channels)
12571255
zassert_equal(DT_INST_IO_CHANNELS_INPUT(0), 10, "");
12581256
}
12591257

1260-
#undef DT_DRV_COMPAT
1261-
#define DT_DRV_COMPAT vnd_adc_temp_sensor
1262-
ZTEST(devicetree_api, test_io_channel_names)
1263-
{
1264-
struct adc_dt_spec adc_spec;
1265-
1266-
/* ADC_DT_SPEC_GET_BY_NAME */
1267-
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch1);
1268-
zassert_equal(adc_spec.channel_id, 10, "");
1269-
1270-
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch2);
1271-
zassert_equal(adc_spec.channel_id, 20, "");
1272-
1273-
/* ADC_DT_SPEC_INST_GET_BY_NAME */
1274-
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch1);
1275-
zassert_equal(adc_spec.channel_id, 10, "");
1276-
1277-
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch2);
1278-
zassert_equal(adc_spec.channel_id, 20, "");
1279-
}
1280-
12811258
#undef DT_DRV_COMPAT
12821259
#define DT_DRV_COMPAT vnd_adc_temp_sensor
12831260
ZTEST(devicetree_api, test_dma)
@@ -3095,22 +3072,8 @@ ZTEST(devicetree_api, test_pinctrl)
30953072
zassert_equal(DT_INST_PINCTRL_HAS_NAME(0, f_o_o2), 0, "");
30963073
}
30973074

3098-
DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL,
3099-
90, NULL);
3100-
DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox_zero_cell), NULL, NULL, NULL, NULL,
3101-
POST_KERNEL, 90, NULL);
3102-
31033075
ZTEST(devicetree_api, test_mbox)
31043076
{
3105-
#undef DT_DRV_COMPAT
3106-
#define DT_DRV_COMPAT vnd_adc_temp_sensor
3107-
3108-
const struct mbox_dt_spec channel_tx = MBOX_DT_SPEC_GET(TEST_TEMP, tx);
3109-
const struct mbox_dt_spec channel_rx = MBOX_DT_SPEC_GET(TEST_TEMP, rx);
3110-
3111-
zassert_equal(channel_tx.channel_id, 1, "");
3112-
zassert_equal(channel_rx.channel_id, 2, "");
3113-
31143077
zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, tx), 1, "");
31153078
zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, rx), 2, "");
31163079

@@ -3122,10 +3085,6 @@ ZTEST(devicetree_api, test_mbox)
31223085
zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, tx), 1, "");
31233086
zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, rx), 2, "");
31243087

3125-
const struct mbox_dt_spec channel_zero = MBOX_DT_SPEC_GET(TEST_TEMP, zero);
3126-
3127-
zassert_equal(channel_zero.channel_id, 0, "");
3128-
31293088
zassert_equal(DT_MBOX_CHANNEL_BY_NAME(TEST_TEMP, zero), 0, "");
31303089

31313090
zassert_true(DT_SAME_NODE(DT_MBOX_CTLR_BY_NAME(TEST_TEMP, zero),

tests/lib/devicetree/api_ext/app.overlay

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,53 @@
2626
reg = < 0x20001000 0x1000 >;
2727
zephyr,memory-region = "SRAM@REGION#2";
2828
};
29+
30+
test_fixed_clk: test-fixed-clock {
31+
compatible = "fixed-clock";
32+
clock-frequency = <25000000>;
33+
#clock-cells = <0>;
34+
};
35+
36+
test_clk: test-clock {
37+
compatible = "vnd,clock";
38+
#clock-cells = <2>;
39+
};
40+
41+
test_adc_1: adc@10002000 {
42+
reg = <0x10002000 0x1000>;
43+
compatible = "vnd,adc";
44+
status = "okay";
45+
#io-channel-cells = <1>;
46+
};
47+
48+
test_adc_2: adc@10003000 {
49+
reg = <0x10003000 0x1000>;
50+
compatible = "vnd,adc";
51+
status = "okay";
52+
#io-channel-cells = <1>;
53+
};
54+
55+
test_mbox: mbox {
56+
compatible = "vnd,mbox";
57+
#mbox-cells = <1>;
58+
status = "okay";
59+
};
60+
61+
test_mbox_zero_cell: mbox_zero_cell {
62+
compatible = "vnd,mbox-zero-cell";
63+
#mbox-cells = <0>;
64+
status = "okay";
65+
};
66+
67+
/* there should only be one of these */
68+
test_temp_sensor: temperature-sensor {
69+
compatible = "vnd,adc-temp-sensor";
70+
clocks = <&test_clk 3 7>, <&test_fixed_clk>, <&test_clk 8 2>;
71+
clock-names = "clk-a", "clk-fixed", "clk-b";
72+
io-channels = <&test_adc_1 10>, <&test_adc_2 20>;
73+
io-channel-names = "ch1", "ch2";
74+
mboxes = <&test_mbox 1>, <&test_mbox 2>, <&test_mbox_zero_cell>;
75+
mbox-names = "tx", "rx", "zero";
76+
};
2977
};
3078
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
CONFIG_ZTEST=y
2+
CONFIG_ADC=y
3+
CONFIG_MBOX=y

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,55 @@
88
#include <zephyr/ztest.h>
99
#include <zephyr/devicetree.h>
1010
#include <zephyr/device.h>
11+
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/drivers/adc.h>
13+
#include <zephyr/drivers/mbox.h>
1114

1215
#include <zephyr/linker/devicetree_regions.h>
1316

14-
#define TEST_SRAM1 DT_NODELABEL(test_sram1)
15-
#define TEST_SRAM2 DT_NODELABEL(test_sram2)
17+
#define TEST_SRAM1 DT_NODELABEL(test_sram1)
18+
#define TEST_SRAM2 DT_NODELABEL(test_sram2)
19+
#define TEST_TEMP DT_NODELABEL(test_temp_sensor)
1620

1721
ZTEST(devicetree_api_ext, test_linker_regions)
1822
{
1923
zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM1), "SRAM_REGION"), "");
2024
zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM2), "SRAM_REGION_2"), "");
2125
}
2226

27+
#define DT_DRV_COMPAT vnd_adc_temp_sensor
28+
ZTEST(devicetree_api_ext, test_adc_dt_spec)
29+
{
30+
struct adc_dt_spec adc_spec;
31+
32+
/* ADC_DT_SPEC_GET_BY_NAME */
33+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch1);
34+
zassert_equal(adc_spec.channel_id, 10, "");
35+
36+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME(TEST_TEMP, ch2);
37+
zassert_equal(adc_spec.channel_id, 20, "");
38+
39+
/* ADC_DT_SPEC_INST_GET_BY_NAME */
40+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch1);
41+
zassert_equal(adc_spec.channel_id, 10, "");
42+
43+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME(0, ch2);
44+
zassert_equal(adc_spec.channel_id, 20, "");
45+
}
46+
47+
DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL);
48+
DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox_zero_cell), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL);
49+
ZTEST(devicetree_api_ext, test_mbox_dt_spec)
50+
{
51+
const struct mbox_dt_spec channel_tx = MBOX_DT_SPEC_GET(TEST_TEMP, tx);
52+
const struct mbox_dt_spec channel_rx = MBOX_DT_SPEC_GET(TEST_TEMP, rx);
53+
54+
zassert_equal(channel_tx.channel_id, 1, "");
55+
zassert_equal(channel_rx.channel_id, 2, "");
56+
57+
const struct mbox_dt_spec channel_zero = MBOX_DT_SPEC_GET(TEST_TEMP, zero);
58+
59+
zassert_equal(channel_zero.channel_id, 0, "");
60+
}
61+
2362
ZTEST_SUITE(devicetree_api_ext, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)