Skip to content

Commit f5830f3

Browse files
fabiobaltierinashif
authored andcommitted
ztest: error out when building tests with no compiler optimizations
Many tests are known to fail when built and no compiler optimizations. Add a CMake check to error out when building a ztest based test with no optimization, ask not file issues about it but also adds an opt-out option to bypass the error for tests are actually designed to work in this setup. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 243a9df commit f5830f3

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,14 @@ endif()
704704

705705
if(CONFIG_ZTEST)
706706
list(APPEND SYSCALL_INCLUDE_DIRS ${ZEPHYR_BASE}/subsys/testsuite/ztest/include)
707+
708+
if(CONFIG_NO_OPTIMIZATIONS AND NOT CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS)
709+
message(FATAL_ERROR "Running tests with CONFIG_NO_OPTIMIZATIONS is not "
710+
"supported and known to break many tests, please do not file issues about "
711+
"it. If you really mean to do this also enable "
712+
"CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS.")
713+
endif()
714+
707715
endif()
708716

709717
foreach(d ${SYSCALL_INCLUDE_DIRS})

subsys/testsuite/ztest/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ config ZTEST_NO_YIELD
103103
yielding to the idle thread may put the board into a low power state
104104
where a debugger cannot connect to it.
105105

106+
config ZTEST_ALLOW_NO_OPTIMIZATIONS
107+
bool "Allow running tests with CONFIG_NO_OPTIMIZATIONS"
108+
depends on NO_OPTIMIZATIONS
109+
help
110+
Do not error out when building a test without compiler optimization.
111+
This is normally not supported, please don't file issues when running
112+
tests that are not explicitly tuned to work in this configuration.
113+
106114
if ZTEST_NEW_API
107115

108116
menu "ztest provided rules"

tests/arch/arm/arm_interrupt/testcase.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests:
1313
filter: not CONFIG_TRUSTED_EXECUTION_NONSECURE
1414
extra_configs:
1515
- CONFIG_NO_OPTIMIZATIONS=y
16+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
1617
- CONFIG_IDLE_STACK_SIZE=512
1718
- CONFIG_MAIN_STACK_SIZE=2048
1819
arch.interrupt.extra_exception_info:

tests/arch/arm/arm_thread_swap/testcase.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tests:
1111
filter: not CONFIG_TRUSTED_EXECUTION_NONSECURE
1212
extra_configs:
1313
- CONFIG_NO_OPTIMIZATIONS=y
14+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
1415
- CONFIG_IDLE_STACK_SIZE=512
1516
- CONFIG_MAIN_STACK_SIZE=2048
1617
min_flash: 192
@@ -25,6 +26,7 @@ tests:
2526
- CONFIG_FPU=y
2627
- CONFIG_FPU_SHARING=y
2728
- CONFIG_NO_OPTIMIZATIONS=y
29+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
2830
- CONFIG_IDLE_STACK_SIZE=512
2931
- CONFIG_MAIN_STACK_SIZE=2048
3032
min_flash: 192

tests/boards/nrf52_bsim/egu/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ CONFIG_ZTEST=y
22
CONFIG_ZTEST_NEW_API=y
33
CONFIG_GEN_IRQ_VECTOR_TABLE=y
44
CONFIG_DYNAMIC_INTERRUPTS=y
5+
CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y

tests/subsys/logging/log_stack/testcase.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tests:
1616
extra_configs:
1717
- CONFIG_LOG_MODE_DEFERRED=y
1818
- CONFIG_NO_OPTIMIZATIONS=y
19+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
1920
- CONFIG_IDLE_STACK_SIZE=2048
2021
logging.log_stack_immediate:
2122
extra_configs:
@@ -25,6 +26,7 @@ tests:
2526
extra_configs:
2627
- CONFIG_LOG_MODE_IMMEDIATE=y
2728
- CONFIG_NO_OPTIMIZATIONS=y
29+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
2830
- CONFIG_IDLE_STACK_SIZE=2048
2931
logging.log_stack_deferred_cpp:
3032
extra_configs:
@@ -35,6 +37,7 @@ tests:
3537
extra_configs:
3638
- CONFIG_LOG_MODE_DEFERRED=y
3739
- CONFIG_NO_OPTIMIZATIONS=y
40+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
3841
- CONFIG_CPP=y
3942
logging.log_stack_immediate_cpp:
4043
extra_configs:
@@ -45,4 +48,5 @@ tests:
4548
extra_configs:
4649
- CONFIG_LOG_MODE_IMMEDIATE=y
4750
- CONFIG_NO_OPTIMIZATIONS=y
51+
- CONFIG_ZTEST_ALLOW_NO_OPTIMIZATIONS=y
4852
- CONFIG_CPP=y

0 commit comments

Comments
 (0)