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 <freey7955@gmail.com>
This commit is contained in:
parent
b0dbbb7782
commit
7d4e31a1f0
4 changed files with 91 additions and 43 deletions
|
|
@ -7,9 +7,7 @@
|
|||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/adc.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/mbox.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ADC=y
|
||||
CONFIG_MBOX=y
|
||||
|
|
|
|||
|
|
@ -8,11 +8,15 @@
|
|||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/adc.h>
|
||||
#include <zephyr/drivers/mbox.h>
|
||||
|
||||
#include <zephyr/linker/devicetree_regions.h>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue