-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: lib: devicetree: add test app for dts base init priority
add test app for dts base device initialization priority Signed-off-by: Najumon B.A <najumon.ba@intel.com>
- Loading branch information
1 parent
a46a45a
commit 4b1de33
Showing
7 changed files
with
204 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(devicetree_devices) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test cases for the device API devicetree data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2020 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Application overlay for testing the devicetree.h API. | ||
* | ||
* Names in this file should be chosen in a way that won't conflict | ||
* with real-world devicetree nodes, to allow these tests to run on | ||
* (and be extended to test) real hardware. | ||
*/ | ||
|
||
/ { | ||
test { | ||
#address-cells = <0x1>; | ||
#size-cells = <0x1>; | ||
|
||
test_gpio_0: gpio@ffff { | ||
gpio-controller; | ||
#gpio-cells = <0x2>; | ||
compatible = "vnd,gpio-device"; | ||
status = "okay"; | ||
reg = <0xffff 0x1000>; | ||
}; | ||
|
||
i2c: i2c@11112222 { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
compatible = "vnd,i2c"; | ||
status = "okay"; | ||
reg = <0x11112222 0x1000>; | ||
|
||
test_i2c_dev_a: test-i2c-dev@10 { | ||
compatible = "vnd,i2c-device"; | ||
status = "okay"; | ||
reg = <0x10>; | ||
supply-gpios = <&test_gpio_0 1 0>; | ||
}; | ||
|
||
test_i2c_dev_b: test-i2c-dev@12 { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
compatible = "vnd,i2c-device"; | ||
status = "okay"; | ||
reg = <0x12>; | ||
}; | ||
|
||
test_i2c_dev_c: test-i2c-dev@13 { | ||
compatible = "vnd,i2c-device"; | ||
reg = <0x13>; | ||
status = "okay"; | ||
}; | ||
|
||
test-i2c-dev@14 { | ||
compatible = "vnd,i2c-device"; | ||
status = "okay"; | ||
reg = <0x14>; | ||
}; | ||
}; | ||
|
||
spi: spi@44442222 { | ||
compatible = "vnd,spi"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
reg = <0x44442222 0x1000>; | ||
status = "okay"; | ||
|
||
test_spi_dev_a: test-spi-dev@1 { | ||
compatible = "vnd,spi-device"; | ||
status = "okay"; | ||
reg = <0x1>; | ||
spi-max-frequency = <50000000>; | ||
supply-gpios = <&test_gpio_0 1 0>; | ||
}; | ||
|
||
test_spi_dev_b: test-spi-dev@2 { | ||
compatible = "vnd,spi-device"; | ||
status = "okay"; | ||
spi-max-frequency = <50000000>; | ||
reg = <0x2>; | ||
}; | ||
|
||
test_spi_dev_c: test-spi-dev@3 { | ||
compatible = "vnd,spi-device"; | ||
reg = <0x3>; | ||
spi-max-frequency = <50000000>; | ||
status = "okay"; | ||
}; | ||
|
||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_I2C=n | ||
CONFIG_SPI=n | ||
CONFIG_ZTEST_NEW_API=y | ||
CONFIG_DTS_BOOT_PRIORITY=y | ||
CONFIG_I2C_STATS=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2020 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <zephyr/devicetree.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/gpio.h> | ||
#include <zephyr/drivers/i2c.h> | ||
#include <zephyr/drivers/spi.h> | ||
|
||
#define TEST_GPIO DT_NODELABEL(test_gpio_0) | ||
#define TEST_I2C DT_NODELABEL(i2c) | ||
#define TEST_I2C_DEVA DT_NODELABEL(test_i2c_dev_a) | ||
#define TEST_I2C_DEVB DT_NODELABEL(test_i2c_dev_b) | ||
#define TEST_I2C_DEVC DT_NODELABEL(test_i2c_dev_c) | ||
#define TEST_I2C_NOLABEL DT_PATH(test, i2c_11112222, test_i2c_dev_14) | ||
#define TEST_SPI DT_NODELABEL(spi) | ||
#define TEST_SPI_DEVA DT_NODELABEL(test_spi_dev_a) | ||
#define TEST_SPI_DEVB DT_NODELABEL(test_spi_dev_b) | ||
#define TEST_SPI_DEVC DT_NODELABEL(test_spi_dev_c) | ||
|
||
static const struct device *init_order[20]; | ||
static uint8_t init_idx; | ||
|
||
#define DEF_DRV_INIT(node_id) \ | ||
static int DEV_INIT_##node_id(const struct device *dev) \ | ||
{ \ | ||
printk("%s %d\n", __func__, init_idx); \ | ||
__ASSERT_NO_MSG(init_idx < ARRAY_SIZE(init_order)); \ | ||
init_order[init_idx++] = dev; \ | ||
return 0; \ | ||
} | ||
|
||
#define DEFINE_DRV(node_id, level) \ | ||
DEVICE_DT_DEFINE(node_id, DEV_INIT_##node_id, NULL, NULL, NULL, level, 0, NULL) | ||
|
||
DEF_DRV_INIT(TEST_GPIO) | ||
DEF_DRV_INIT(TEST_I2C) | ||
DEF_DRV_INIT(TEST_I2C_DEVA) | ||
DEF_DRV_INIT(TEST_I2C_DEVB) | ||
DEF_DRV_INIT(TEST_I2C_DEVC) | ||
DEF_DRV_INIT(TEST_I2C_NOLABEL) | ||
DEF_DRV_INIT(TEST_SPI) | ||
DEF_DRV_INIT(TEST_SPI_DEVA) | ||
DEF_DRV_INIT(TEST_SPI_DEVB) | ||
DEF_DRV_INIT(TEST_SPI_DEVC) | ||
|
||
DEFINE_DRV(TEST_GPIO, PRE_KERNEL_2); | ||
DEFINE_DRV(TEST_I2C, POST_KERNEL); | ||
DEFINE_DRV(TEST_I2C_DEVB, APPLICATION); | ||
DEFINE_DRV(TEST_I2C_DEVC, POST_KERNEL); | ||
DEFINE_DRV(TEST_I2C_DEVA, POST_KERNEL); | ||
DEFINE_DRV(TEST_I2C_NOLABEL, PRE_KERNEL_1); | ||
DEFINE_DRV(TEST_SPI, PRE_KERNEL_2); | ||
DEFINE_DRV(TEST_SPI_DEVB, PRE_KERNEL_1); | ||
DEFINE_DRV(TEST_SPI_DEVA, APPLICATION); | ||
DEFINE_DRV(TEST_SPI_DEVC, PRE_KERNEL_1); | ||
|
||
#define DEV_HDL(node_id) DEVICE_DT_GET(node_id) | ||
#define DEV_HDL_NAME(name) DEVICE_GET(name) | ||
|
||
ZTEST(devicetree_devices, test_init_order) | ||
{ | ||
zassert_equal(init_order[0], DEV_HDL(TEST_GPIO)); | ||
zassert_equal(init_order[1], DEV_HDL(TEST_SPI)); | ||
zassert_equal(init_order[2], DEV_HDL(TEST_SPI_DEVB)); | ||
zassert_equal(init_order[3], DEV_HDL(TEST_SPI_DEVC)); | ||
zassert_equal(init_order[4], DEV_HDL(TEST_I2C)); | ||
zassert_equal(init_order[5], DEV_HDL(TEST_I2C_DEVA)); | ||
zassert_equal(init_order[6], DEV_HDL(TEST_I2C_DEVC)); | ||
zassert_equal(init_order[7], DEV_HDL(TEST_I2C_NOLABEL)); | ||
zassert_equal(init_order[8], DEV_HDL(TEST_I2C_DEVB)); | ||
zassert_equal(init_order[9], DEV_HDL(TEST_SPI_DEVA)); | ||
} | ||
|
||
ZTEST(devicetree_devices, test_get_or_null) | ||
{ | ||
const struct device *dev; | ||
|
||
dev = DEVICE_DT_GET_OR_NULL(TEST_I2C_DEVA); | ||
zassert_not_equal(dev, NULL, NULL); | ||
|
||
dev = DEVICE_DT_GET_OR_NULL(non_existing_node); | ||
zassert_is_null(dev); | ||
} | ||
|
||
ZTEST_SUITE(devicetree_devices, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests: | ||
|
||
libraries.devicetree.boot_order: | ||
platform_allow: native_posix | ||
tags: devicetree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,5 @@ | ||
tests: | ||
libraries.devicetree.devices: | ||
tags: devicetree | ||
# We only need this to run on one platform so use native_posix as it | ||
# will mostly likely be the fastest. | ||
integration_platforms: | ||
platform_allow: | ||
- native_posix | ||
platform_exclude: | ||
- hsdk | ||
- hsdk_2cores | ||
- thingy52_nrf52832 | ||
- bbc_microbit | ||
- bbc_microbit_v2 | ||
- bt610 | ||
- bl5340_dvk_cpuapp | ||
- bl5340_dvk_cpuapp_ns | ||
- mimxrt595_evk_cm33 |