Skip to content

Commit f65f8a8

Browse files
committed
tests: lib: devicetree: api_ext: Add ADC_DT_SPEC with fallback tests
Add tests for the _OR variant sf the different ADC_DT_SPEC_GET macros. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 7e8504e commit f65f8a8

File tree

1 file changed

+53
-0
lines changed
  • tests/lib/devicetree/api_ext/src

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define TEST_SRAM1 DT_NODELABEL(test_sram1)
1818
#define TEST_SRAM2 DT_NODELABEL(test_sram2)
1919
#define TEST_TEMP DT_NODELABEL(test_temp_sensor)
20+
#define TEST_MISSING DT_NODELABEL(test_non_existing)
2021

2122
ZTEST(devicetree_api_ext, test_linker_regions)
2223
{
@@ -56,6 +57,58 @@ ZTEST(devicetree_api_ext, test_adc_dt_spec)
5657

5758
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX(0, 1);
5859
zassert_equal(adc_spec.channel_id, 20, "");
60+
61+
/* ADC_DT_SPEC_GET_BY_NAME_OR */
62+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME_OR(TEST_TEMP, ch1, {0});
63+
zassert_equal(adc_spec.channel_id, 10, "");
64+
65+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME_OR(TEST_TEMP, ch2, {0});
66+
zassert_equal(adc_spec.channel_id, 20, "");
67+
68+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME_OR(TEST_TEMP, ch3, {0});
69+
zassert_equal(adc_spec.channel_id, 0, "");
70+
71+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_NAME_OR(TEST_MISSING, ch1, {0});
72+
zassert_equal(adc_spec.channel_id, 0, "");
73+
74+
/* ADC_DT_SPEC_INST_GET_BY_NAME_OR */
75+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME_OR(0, ch1, {0});
76+
zassert_equal(adc_spec.channel_id, 10, "");
77+
78+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME_OR(0, ch2, {0});
79+
zassert_equal(adc_spec.channel_id, 20, "");
80+
81+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME_OR(0, ch3, {0});
82+
zassert_equal(adc_spec.channel_id, 0, "");
83+
84+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_NAME_OR(100, ch1, {0});
85+
zassert_equal(adc_spec.channel_id, 0, "");
86+
87+
/* ADC_DT_SPEC_GET_BY_IDX_OR */
88+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_IDX_OR(TEST_TEMP, 0, {0});
89+
zassert_equal(adc_spec.channel_id, 10, "");
90+
91+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_IDX_OR(TEST_TEMP, 1, {0});
92+
zassert_equal(adc_spec.channel_id, 20, "");
93+
94+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_IDX_OR(TEST_TEMP, 2, {0});
95+
zassert_equal(adc_spec.channel_id, 0, "");
96+
97+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_GET_BY_IDX_OR(TEST_MISSING, 0, {0});
98+
zassert_equal(adc_spec.channel_id, 0, "");
99+
100+
/* ADC_DT_SPEC_INST_GET_BY_IDX_OR */
101+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX_OR(0, 0, {0});
102+
zassert_equal(adc_spec.channel_id, 10, "");
103+
104+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX_OR(0, 1, {0});
105+
zassert_equal(adc_spec.channel_id, 20, "");
106+
107+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX_OR(0, 2, {0});
108+
zassert_equal(adc_spec.channel_id, 0, "");
109+
110+
adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX_OR(100, 0, {0});
111+
zassert_equal(adc_spec.channel_id, 0, "");
59112
}
60113

61114
DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL);

0 commit comments

Comments
 (0)