test: misc: add a test application for check_init_priorities
Add a test specifically for the check_init_priorities scripts. The test creates a set of fake devices to exercise the three possible conditions, run a build, run the check script and validate the script output. The check is meant to fail the build on error but that's bypassed in this case as that would fail the twister run. That specific bit is covered in unit tests anyway. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
c1c06207a6
commit
2354cc9e25
24
tests/misc/check_init_priorities/CMakeLists.txt
Normal file
24
tests/misc/check_init_priorities/CMakeLists.txt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
|
||||||
|
set(output_file ${PROJECT_BINARY_DIR}/check_init_priorities_output.txt)
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
check_init_priorities_output
|
||||||
|
COMMENT "Running check_init_priorities.py"
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/check_init_priorities.py
|
||||||
|
--verbose
|
||||||
|
--build-dir ${PROJECT_BINARY_DIR}/..
|
||||||
|
--output ${output_file}
|
||||||
|
--always-succeed
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} ${APPLICATION_SOURCE_DIR}/validate_check_init_priorities_output.py
|
||||||
|
${output_file}
|
||||||
|
DEPENDS zephyr_pre0
|
||||||
|
)
|
||||||
|
add_dependencies(zephyr_pre1 check_init_priorities_output)
|
||||||
|
|
||||||
|
project(check_init_priorities)
|
||||||
|
|
||||||
|
target_sources(app PRIVATE src/main.c)
|
45
tests/misc/check_init_priorities/boards/native_posix.overlay
Normal file
45
tests/misc/check_init_priorities/boards/native_posix.overlay
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Google LLC
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
test_gpio_0: gpio@ffff {
|
||||||
|
gpio-controller;
|
||||||
|
#gpio-cells = <0x2>;
|
||||||
|
compatible = "vnd,gpio-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0xffff 0x1000>;
|
||||||
|
};
|
||||||
|
|
||||||
|
test_i2c: i2c@11112222 {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
compatible = "vnd,i2c";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x11112222 0x1000>;
|
||||||
|
clock-frequency = <100000>;
|
||||||
|
|
||||||
|
test_dev_a: test-i2c-dev@10 {
|
||||||
|
compatible = "vnd,i2c-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x10>;
|
||||||
|
supply-gpios = <&test_gpio_0 1 0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
test_dev_b: test-i2c-dev@11 {
|
||||||
|
compatible = "vnd,i2c-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x11>;
|
||||||
|
supply-gpios = <&test_gpio_0 2 0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
test_dev_c: test-i2c-dev@12 {
|
||||||
|
compatible = "vnd,i2c-device";
|
||||||
|
status = "okay";
|
||||||
|
reg = <0x12>;
|
||||||
|
supply-gpios = <&test_gpio_0 3 0>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Google LLC
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#include "native_posix.overlay"
|
1
tests/misc/check_init_priorities/prj.conf
Normal file
1
tests/misc/check_init_priorities/prj.conf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# Empty
|
24
tests/misc/check_init_priorities/src/main.c
Normal file
24
tests/misc/check_init_priorities/src/main.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Google LLC
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
|
||||||
|
static int device_init(const struct device *dev)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEVICE_DT_DEFINE(DT_INST(0, vnd_gpio_device), device_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, 50, NULL);
|
||||||
|
DEVICE_DT_DEFINE(DT_INST(0, vnd_i2c), device_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, 50, NULL);
|
||||||
|
|
||||||
|
DEVICE_DT_DEFINE(DT_INST(0, vnd_i2c_device), device_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, 49, NULL);
|
||||||
|
DEVICE_DT_DEFINE(DT_INST(1, vnd_i2c_device), device_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, 50, NULL);
|
||||||
|
DEVICE_DT_DEFINE(DT_INST(2, vnd_i2c_device), device_init, NULL, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, 51, NULL);
|
8
tests/misc/check_init_priorities/testcase.yaml
Normal file
8
tests/misc/check_init_priorities/testcase.yaml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
tests:
|
||||||
|
misc.check_init_priorities:
|
||||||
|
build_only: true
|
||||||
|
platform_allow: native_posix native_posix_64
|
||||||
|
integration_platforms:
|
||||||
|
- native_posix
|
40
tests/misc/check_init_priorities/validate_check_init_priorities_output.py
Executable file
40
tests/misc/check_init_priorities/validate_check_init_priorities_output.py
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright 2023 Google LLC
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
"""Validate the output of check_init_priorities against a test reference."""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
REFERENCE_OUTPUT = [
|
||||||
|
"INFO: /i2c@11112222/test-i2c-dev@12 PRE_KERNEL_1 51 > /gpio@ffff PRE_KERNEL_1 50",
|
||||||
|
"INFO: /i2c@11112222/test-i2c-dev@12 PRE_KERNEL_1 51 > /i2c@11112222 PRE_KERNEL_1 50",
|
||||||
|
"ERROR: /i2c@11112222/test-i2c-dev@10 PRE_KERNEL_1 49 < /gpio@ffff PRE_KERNEL_1 50",
|
||||||
|
"ERROR: /i2c@11112222/test-i2c-dev@10 PRE_KERNEL_1 49 < /i2c@11112222 PRE_KERNEL_1 50",
|
||||||
|
"WARNING: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1 50 == /gpio@ffff PRE_KERNEL_1 50",
|
||||||
|
"WARNING: /i2c@11112222/test-i2c-dev@11 PRE_KERNEL_1 50 == /i2c@11112222 PRE_KERNEL_1 50",
|
||||||
|
]
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print(f"usage: {sys.argv[0]} FILE_PATH")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
output = []
|
||||||
|
with open(sys.argv[1], "r") as file:
|
||||||
|
for line in file:
|
||||||
|
if line.startswith("INFO: check_init_priorities build_dir:"):
|
||||||
|
continue
|
||||||
|
output.append(line.strip())
|
||||||
|
|
||||||
|
if sorted(REFERENCE_OUTPUT) != sorted(output):
|
||||||
|
print("Mismatched otuput")
|
||||||
|
print()
|
||||||
|
print("expected:")
|
||||||
|
print("\n".join(sorted(REFERENCE_OUTPUT)))
|
||||||
|
print()
|
||||||
|
print("got:")
|
||||||
|
print("\n".join(sorted(output)))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
Loading…
Reference in a new issue