tests: drivers: spi: Add test for the SPI_DT_SPEC initializer macro

Adds a new test for the SPI_DT_SPEC initializer macro to reproduce the
XCC build failure reported in #43745 on the intel_adsp_cavs15 board.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
This commit is contained in:
Maureen Helm 2022-03-18 11:00:15 -05:00 committed by Marti Bolivar
commit e7a010de4e
5 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spi_dt_spec)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2022 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
*/
/ {
test {
#address-cells = <0x1>;
#size-cells = <0x1>;
test_gpio: gpio@deadbeef {
compatible = "vnd,gpio";
gpio-controller;
reg = <0xdeadbeef 0x1000>;
#gpio-cells = <0x2>;
label = "TEST_GPIO";
status = "okay";
};
test_spi_cs: spi@33334444 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "vnd,spi";
reg = <0x33334444 0x1000>;
label = "TEST_SPI_CTLR_CS";
status = "okay";
clock-frequency = <2000000>;
cs-gpios = <&test_gpio 0x10 0x20>;
test_spi_dev_cs: test-spi-dev@0 {
compatible = "vnd,spi-device";
label = "TEST_SPI_DEV_0";
reg = <0>;
spi-max-frequency = <2000000>;
};
};
test_spi_no_cs: spi@55556666 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "vnd,spi";
reg = <0x55556666 0x1000>;
label = "TEST_SPI_CTLR_NO_CS";
status = "okay";
clock-frequency = <2000000>;
test_spi_dev_no_cs: test-spi-dev@0 {
compatible = "vnd,spi-device";
label = "TEST_SPI_DEV_NO_CS";
reg = <0>;
spi-max-frequency = <2000000>;
};
};
};
};

View file

@ -0,0 +1,3 @@
CONFIG_ZTEST=y
CONFIG_SPI=y
CONFIG_GPIO=y

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
#include <devicetree.h>
#include <device.h>
#include <drivers/spi.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(test, CONFIG_LOG_DEFAULT_LEVEL);
static void test_dt_spec(void)
{
const struct spi_dt_spec spi_cs =
SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_cs), 0, 0);
LOG_DBG("spi_cs.bus = %p", spi_cs.bus);
LOG_DBG("spi_cs.config.cs->gpio_dev = %p", spi_cs.config.cs->gpio_dev);
LOG_DBG("spi_cs.config.cs->gpio.port = %p", spi_cs.config.cs->gpio.port);
zassert_equal(spi_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_cs)), "");
zassert_equal(spi_cs.config.cs->gpio_dev, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), "");
zassert_equal(spi_cs.config.cs->gpio.port, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), "");
const struct spi_dt_spec spi_no_cs =
SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_no_cs), 0, 0);
LOG_DBG("spi_no_cs.bus = %p", spi_no_cs.bus);
LOG_DBG("spi_no_cs.config.cs = %p", spi_no_cs.config.cs);
zassert_equal(spi_no_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_no_cs)), "");
zassert_is_null(spi_no_cs.config.cs, "");
}
void test_main(void)
{
ztest_test_suite(spi_dt_spec,
ztest_unit_test(test_dt_spec)
);
ztest_run_test_suite(spi_dt_spec);
}

View file

@ -0,0 +1,4 @@
tests:
drivers.spi.dt_spec:
tags: drivers spi devicetree
depends_on: spi gpio