Skip to content

Commit

Permalink
devicetree: Fix Device tree tests cannot be built with coverage enabled
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Freey0 authored and kartben committed Jan 22, 2025
1 parent b0dbbb7 commit 7d4e31a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 43 deletions.
41 changes: 0 additions & 41 deletions tests/lib/devicetree/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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, "");

Expand All @@ -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),
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/devicetree/api_ext/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};
};
2 changes: 2 additions & 0 deletions tests/lib/devicetree/api_ext/prj.conf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CONFIG_ZTEST=y
CONFIG_ADC=y
CONFIG_MBOX=y
43 changes: 41 additions & 2 deletions tests/lib/devicetree/api_ext/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,55 @@
#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)
{
zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM1), "SRAM_REGION"), "");
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);

0 comments on commit 7d4e31a

Please sign in to comment.