|
17 | 17 | #define TEST_SRAM1 DT_NODELABEL(test_sram1) |
18 | 18 | #define TEST_SRAM2 DT_NODELABEL(test_sram2) |
19 | 19 | #define TEST_TEMP DT_NODELABEL(test_temp_sensor) |
| 20 | +#define TEST_MISSING DT_NODELABEL(test_non_existing) |
20 | 21 |
|
21 | 22 | ZTEST(devicetree_api_ext, test_linker_regions) |
22 | 23 | { |
@@ -56,6 +57,58 @@ ZTEST(devicetree_api_ext, test_adc_dt_spec) |
56 | 57 |
|
57 | 58 | adc_spec = (struct adc_dt_spec)ADC_DT_SPEC_INST_GET_BY_IDX(0, 1); |
58 | 59 | 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, ""); |
59 | 112 | } |
60 | 113 |
|
61 | 114 | DEVICE_DT_DEFINE(DT_NODELABEL(test_mbox), NULL, NULL, NULL, NULL, POST_KERNEL, 90, NULL); |
|
0 commit comments