tests: devicetree: add test for devicetree node data
Verify that device dependencies are encoded into and retrievable from the device structure. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
d554d34137
commit
9ef62d564d
6 changed files with 85 additions and 5 deletions
9
tests/lib/devicetree/devices/CMakeLists.txt
Normal file
9
tests/lib/devicetree/devices/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
|
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(devicetree_devices)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
1
tests/lib/devicetree/devices/README
Normal file
1
tests/lib/devicetree/devices/README
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Test cases for the device API devicetree data.
|
62
tests/lib/devicetree/devices/app.overlay
Normal file
62
tests/lib/devicetree/devices/app.overlay
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* 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@0 {
|
||||||
|
gpio-controller;
|
||||||
|
#gpio-cells = <0x2>;
|
||||||
|
compatible = "vnd,gpio";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x0 0x1000>;
|
||||||
|
label = "TEST_GPIO_0";
|
||||||
|
};
|
||||||
|
|
||||||
|
test_i2c: i2c@11112222 {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
compatible = "vnd,i2c";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x11112222 0x1000>;
|
||||||
|
clock-frequency = <100000>;
|
||||||
|
label = "TEST_I2C_CTLR";
|
||||||
|
|
||||||
|
test_dev_a: test-i2c-dev@10 {
|
||||||
|
compatible = "vnd,i2c-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x10>;
|
||||||
|
supply-gpios = <&test_gpio_0 1 0>;
|
||||||
|
label = "TEST_I2C_DEV_10";
|
||||||
|
};
|
||||||
|
|
||||||
|
test_gpiox: test-i2c-dev@11 {
|
||||||
|
gpio-controller;
|
||||||
|
#gpio-cells = <2>;
|
||||||
|
compatible = "vnd,gpio-expander";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x11>;
|
||||||
|
label = "TEST_I2C_GPIO";
|
||||||
|
};
|
||||||
|
|
||||||
|
test_dev_b: test-i2c-dev@12 {
|
||||||
|
compatible = "vnd,i2c-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x12>;
|
||||||
|
supply-gpios = <&test_gpiox 2 0>;
|
||||||
|
label = "TEST_I2C_DEV_12";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
1
tests/lib/devicetree/devices/prj.conf
Normal file
1
tests/lib/devicetree/devices/prj.conf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_ZTEST=y
|
|
@ -83,19 +83,19 @@ static void test_requires(void)
|
||||||
/* TEST_GPIO: no req */
|
/* TEST_GPIO: no req */
|
||||||
dev = device_get_binding(DT_LABEL(TEST_GPIO));
|
dev = device_get_binding(DT_LABEL(TEST_GPIO));
|
||||||
zassert_equal(dev, DEVICE_DT_GET(TEST_GPIO), NULL);
|
zassert_equal(dev, DEVICE_DT_GET(TEST_GPIO), NULL);
|
||||||
hdls = device_get_requires_handles(dev, &nhdls);
|
hdls = device_required_handles_get(dev, &nhdls);
|
||||||
zassert_equal(nhdls, 0, NULL);
|
zassert_equal(nhdls, 0, NULL);
|
||||||
|
|
||||||
/* TEST_I2C: no req */
|
/* TEST_I2C: no req */
|
||||||
dev = device_get_binding(DT_LABEL(TEST_I2C));
|
dev = device_get_binding(DT_LABEL(TEST_I2C));
|
||||||
zassert_equal(dev, DEVICE_DT_GET(TEST_I2C), NULL);
|
zassert_equal(dev, DEVICE_DT_GET(TEST_I2C), NULL);
|
||||||
hdls = device_get_requires_handles(dev, &nhdls);
|
hdls = device_required_handles_get(dev, &nhdls);
|
||||||
zassert_equal(nhdls, 0, NULL);
|
zassert_equal(nhdls, 0, NULL);
|
||||||
|
|
||||||
/* TEST_DEVA: TEST_I2C GPIO */
|
/* TEST_DEVA: TEST_I2C GPIO */
|
||||||
dev = device_get_binding(DT_LABEL(TEST_DEVA));
|
dev = device_get_binding(DT_LABEL(TEST_DEVA));
|
||||||
zassert_equal(dev, DEVICE_DT_GET(TEST_DEVA), NULL);
|
zassert_equal(dev, DEVICE_DT_GET(TEST_DEVA), NULL);
|
||||||
hdls = device_get_requires_handles(dev, &nhdls);
|
hdls = device_required_handles_get(dev, &nhdls);
|
||||||
zassert_equal(nhdls, 2, NULL);
|
zassert_equal(nhdls, 2, NULL);
|
||||||
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
||||||
zassert_true(check_handle(DEV_HDL(TEST_GPIO), hdls, nhdls), NULL);
|
zassert_true(check_handle(DEV_HDL(TEST_GPIO), hdls, nhdls), NULL);
|
||||||
|
@ -103,14 +103,14 @@ static void test_requires(void)
|
||||||
/* TEST_GPIOX: TEST_I2C */
|
/* TEST_GPIOX: TEST_I2C */
|
||||||
dev = device_get_binding(DT_LABEL(TEST_GPIOX));
|
dev = device_get_binding(DT_LABEL(TEST_GPIOX));
|
||||||
zassert_equal(dev, DEVICE_DT_GET(TEST_GPIOX), NULL);
|
zassert_equal(dev, DEVICE_DT_GET(TEST_GPIOX), NULL);
|
||||||
hdls = device_get_requires_handles(dev, &nhdls);
|
hdls = device_required_handles_get(dev, &nhdls);
|
||||||
zassert_equal(nhdls, 1, NULL);
|
zassert_equal(nhdls, 1, NULL);
|
||||||
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
||||||
|
|
||||||
/* TEST_DEVB: TEST_I2C TEST_GPIOX */
|
/* TEST_DEVB: TEST_I2C TEST_GPIOX */
|
||||||
dev = device_get_binding(DT_LABEL(TEST_DEVB));
|
dev = device_get_binding(DT_LABEL(TEST_DEVB));
|
||||||
zassert_equal(dev, DEVICE_DT_GET(TEST_DEVB), NULL);
|
zassert_equal(dev, DEVICE_DT_GET(TEST_DEVB), NULL);
|
||||||
hdls = device_get_requires_handles(dev, &nhdls);
|
hdls = device_required_handles_get(dev, &nhdls);
|
||||||
zassert_equal(nhdls, 2, NULL);
|
zassert_equal(nhdls, 2, NULL);
|
||||||
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
|
||||||
zassert_true(check_handle(DEV_HDL(TEST_GPIOX), hdls, nhdls), NULL);
|
zassert_true(check_handle(DEV_HDL(TEST_GPIOX), hdls, nhdls), NULL);
|
||||||
|
|
7
tests/lib/devicetree/devices/testcase.yaml
Normal file
7
tests/lib/devicetree/devices/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
tests:
|
||||||
|
libraries.devicetree:
|
||||||
|
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:
|
||||||
|
- native_posix
|
Loading…
Add table
Add a link
Reference in a new issue