diff --git a/common/inc/tx_api.h b/common/inc/tx_api.h index ed1f82918..bbb447ee5 100644 --- a/common/inc/tx_api.h +++ b/common/inc/tx_api.h @@ -2101,6 +2101,15 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa /* Define safety critical configuration and exception handling. */ #ifdef TX_SAFETY_CRITICAL +#ifndef TX_SAFETY_CRITICAL_BUILD_CHECK +#define TX_SAFETY_CRITICAL_BUILD_CHECK +#endif +#ifndef TX_SAFETY_CRITICAL_EXCEPTION_ENABLE +#define TX_SAFETY_CRITICAL_EXCEPTION_ENABLE +#endif +#endif + +#ifdef TX_SAFETY_CRITICAL_BUILD_CHECK /* Ensure the maximum number of priorities is defined in safety critical mode. */ #ifndef TX_MAX_PRIORITIES @@ -2132,11 +2141,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_DISABLE_STACK_FILLING must not be defined." #endif -/* Ensure enable stack checking is not defined. */ -#ifdef TX_ENABLE_STACK_CHECKING -#error "TX_ENABLE_STACK_CHECKING must not be defined." -#endif - /* Ensure disable preemption-threshold is not defined. */ #ifdef TX_DISABLE_PREEMPTION_THRESHOLD #error "TX_DISABLE_PREEMPTION_THRESHOLD must not be defined." @@ -2152,11 +2156,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_NO_TIMER must not be defined." #endif -/* Ensure disable notify callbacks is not defined. */ -#ifdef TX_DISABLE_NOTIFY_CALLBACKS -#error "TX_DISABLE_NOTIFY_CALLBACKS must not be defined." -#endif - /* Ensure in-line thread suspend/resume is not defined. */ #ifdef TX_INLINE_THREAD_RESUME_SUSPEND #error "TX_INLINE_THREAD_RESUME_SUSPEND must not be defined." @@ -2167,11 +2166,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_NOT_INTERRUPTABLE must not be defined." #endif -/* Ensure event trace enable is not defined. */ -#ifdef TX_ENABLE_EVENT_TRACE -#error "TX_ENABLE_EVENT_TRACE must not be defined." -#endif - /* Ensure block pool performance info enable is not defined. */ #ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO #error "TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO must not be defined." @@ -2212,6 +2206,10 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_TIMER_ENABLE_PERFORMANCE_INFO must not be defined." #endif +#endif + + +#if defined(TX_SAFETY_CRITICAL) || defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) /* Now define the safety critical exception handler. */ @@ -2225,6 +2223,9 @@ VOID _tx_safety_critical_exception_handler(CHAR *file_name, INT line_number, #ifndef TX_SAFETY_CRITICAL_EXCEPTION_HANDLER #define TX_SAFETY_CRITICAL_EXCEPTION_HANDLER VOID _tx_safety_critical_exception_handler(CHAR *file_name, INT line_number, UINT status) \ { \ + TX_PARAMETER_NOT_USED(file_name); \ + TX_PARAMETER_NOT_USED(line_number); \ + TX_PARAMETER_NOT_USED(status); \ while(1) \ { \ } \ diff --git a/common/src/tx_initialize_kernel_enter.c b/common/src/tx_initialize_kernel_enter.c index bbb073326..494c8632c 100644 --- a/common/src/tx_initialize_kernel_enter.c +++ b/common/src/tx_initialize_kernel_enter.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -39,7 +40,7 @@ extern VOID _tx_execution_initialize(VOID); TX_PORT_SPECIFIC_DATA -#ifdef TX_SAFETY_CRITICAL +#if defined(TX_SAFETY_CRITICAL) || defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) TX_SAFETY_CRITICAL_EXCEPTION_HANDLER #endif diff --git a/common/src/tx_timer_initialize.c b/common/src/tx_timer_initialize.c index 210888a1e..4f1badb23 100644 --- a/common/src/tx_timer_initialize.c +++ b/common/src/tx_timer_initialize.c @@ -255,7 +255,7 @@ UINT status; _tx_timer_priority, _tx_timer_priority, TX_NO_TIME_SLICE, TX_DONT_START); -#ifdef TX_SAFETY_CRITICAL +#if defined(TX_SAFETY_CRITICAL) || defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) /* Check return from thread create - if an error is detected throw an exception. */ if (status != TX_SUCCESS) diff --git a/common_smp/inc/tx_api.h b/common_smp/inc/tx_api.h index 77bd6218b..78b31a558 100644 --- a/common_smp/inc/tx_api.h +++ b/common_smp/inc/tx_api.h @@ -2110,6 +2110,15 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa /* Define safety critical configuration and exception handling. */ #ifdef TX_SAFETY_CRITICAL +#ifndef TX_SAFETY_CRITICAL_BUILD_CHECK +#define TX_SAFETY_CRITICAL_BUILD_CHECK +#endif +#ifndef TX_SAFETY_CRITICAL_EXCEPTION_ENABLE +#define TX_SAFETY_CRITICAL_EXCEPTION_ENABLE +#endif +#endif + +#ifdef TX_SAFETY_CRITICAL_BUILD_CHECK /* Ensure the maximum number of priorities is defined in safety critical mode. */ #ifndef TX_MAX_PRIORITIES @@ -2141,11 +2150,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_DISABLE_STACK_FILLING must not be defined." #endif -/* Ensure enable stack checking is not defined. */ -#ifdef TX_ENABLE_STACK_CHECKING -#error "TX_ENABLE_STACK_CHECKING must not be defined." -#endif - /* Ensure disable preemption-threshold is not defined. */ #ifdef TX_DISABLE_PREEMPTION_THRESHOLD #error "TX_DISABLE_PREEMPTION_THRESHOLD must not be defined." @@ -2161,11 +2165,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_NO_TIMER must not be defined." #endif -/* Ensure disable notify callbacks is not defined. */ -#ifdef TX_DISABLE_NOTIFY_CALLBACKS -#error "TX_DISABLE_NOTIFY_CALLBACKS must not be defined." -#endif - /* Ensure in-line thread suspend/resume is not defined. */ #ifdef TX_INLINE_THREAD_RESUME_SUSPEND #error "TX_INLINE_THREAD_RESUME_SUSPEND must not be defined." @@ -2176,11 +2175,6 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_NOT_INTERRUPTABLE must not be defined." #endif -/* Ensure event trace enable is not defined. */ -#ifdef TX_ENABLE_EVENT_TRACE -#error "TX_ENABLE_EVENT_TRACE must not be defined." -#endif - /* Ensure block pool performance info enable is not defined. */ #ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO #error "TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO must not be defined." @@ -2221,6 +2215,10 @@ VOID _tx_misra_thread_entry_exit_notify_not_used(VOID (*threa #error "TX_TIMER_ENABLE_PERFORMANCE_INFO must not be defined." #endif +#endif + + +#if defined(TX_SAFETY_CRITICAL) || defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) /* Now define the safety critical exception handler. */ @@ -2234,6 +2232,9 @@ VOID _tx_safety_critical_exception_handler(CHAR *file_name, INT line_number, #ifndef TX_SAFETY_CRITICAL_EXCEPTION_HANDLER #define TX_SAFETY_CRITICAL_EXCEPTION_HANDLER VOID _tx_safety_critical_exception_handler(CHAR *file_name, INT line_number, UINT status) \ { \ + TX_PARAMETER_NOT_USED(file_name); \ + TX_PARAMETER_NOT_USED(line_number); \ + TX_PARAMETER_NOT_USED(status); \ while(1) \ { \ } \ diff --git a/common_smp/src/tx_initialize_kernel_enter.c b/common_smp/src/tx_initialize_kernel_enter.c index 5fa71b8fa..6ab6576ab 100644 --- a/common_smp/src/tx_initialize_kernel_enter.c +++ b/common_smp/src/tx_initialize_kernel_enter.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -37,7 +38,7 @@ TX_PORT_SPECIFIC_DATA -#ifdef TX_SAFETY_CRITICAL +#if defined(TX_SAFETY_CRITICAL) || defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) TX_SAFETY_CRITICAL_EXCEPTION_HANDLER #endif diff --git a/test/smp/regression/testcontrol.c b/test/smp/regression/testcontrol.c index c964dc03a..cda2b58a0 100644 --- a/test/smp/regression/testcontrol.c +++ b/test/smp/regression/testcontrol.c @@ -545,7 +545,9 @@ void tx_application_define(void *first_unused_memory) { UCHAR *pointer; +#ifndef TX_SAFETY_CRITICAL VOID (*temp_mutex_release)(TX_THREAD *thread_ptr); +#endif TX_THREAD *temp_thread; UINT old_preemption; ULONG old_time_slice; @@ -738,6 +740,7 @@ TX_THREAD *thread_ptr; _tx_thread_time_slice(); _tx_thread_current_ptr[0] = TX_NULL; +#ifndef TX_SAFETY_CRITICAL /* Test to make sure _tx_thread_shell_entry can handle a NULL mutex release function pointer. */ temp_mutex_release = _tx_thread_mutex_release; temp_thread = _tx_thread_execute_ptr[0]; @@ -756,6 +759,7 @@ TX_THREAD *thread_ptr; _tx_thread_current_ptr[0] = TX_NULL; _tx_thread_execute_ptr[0] = temp_thread; _tx_thread_mutex_release = temp_mutex_release; /* Recover Mutex release pointer. */ +#endif /* Test _tx_thread_system_suspend when not current, preemption is needed but disabled. */ temp_thread = _tx_thread_execute_ptr[0]; diff --git a/test/smp/regression/threadx_timer_activate_deactivate_test.c b/test/smp/regression/threadx_timer_activate_deactivate_test.c index ceaf79bf7..ba31577d4 100644 --- a/test/smp/regression/threadx_timer_activate_deactivate_test.c +++ b/test/smp/regression/threadx_timer_activate_deactivate_test.c @@ -8,6 +8,7 @@ /* */ /* SPDX-License-Identifier: MIT */ /***************************************************************************/ +// Portions of this file were generated with AI assistance. /* This test is designed to test application timer activation/deactivation services from threads and the activation routines. */ @@ -96,7 +97,7 @@ TX_TIMER_INTERNAL **current_list_head; /* Inform user. */ printf("Running Timer Activate/Deactivate Test.............................. "); -#ifndef TX_TIMER_PROCESS_IN_ISR +#if !defined(TX_TIMER_PROCESS_IN_ISR) && !defined(TX_SAFETY_CRITICAL) /* Call the timer thread entry function with an invalid value to make sure the code simply returns. */ _tx_timer_thread_entry(0); diff --git a/test/smp/regression/threadx_timer_simple_test.c b/test/smp/regression/threadx_timer_simple_test.c index 5abd1d3c9..af3b156da 100644 --- a/test/smp/regression/threadx_timer_simple_test.c +++ b/test/smp/regression/threadx_timer_simple_test.c @@ -221,7 +221,7 @@ CHAR *pointer; test_control_return(1); } -#ifndef TX_TIMER_PROCESS_IN_ISR +#if !defined(TX_TIMER_PROCESS_IN_ISR) && !defined(TX_SAFETY_CRITICAL) /* Call the timer thread entry function with a bad ID to test another path. */ _tx_timer_thread_entry(0); diff --git a/test/tx/cmake/CMakeLists.txt b/test/tx/cmake/CMakeLists.txt index 7ed620d9c..c6c8eb1e2 100644 --- a/test/tx/cmake/CMakeLists.txt +++ b/test/tx/cmake/CMakeLists.txt @@ -114,6 +114,11 @@ if(NOT ("TX_MISRA_ENABLE" IN_LIST ${CMAKE_BUILD_TYPE})) add_subdirectory(module_manager) endif() +# The safety-critical tests build both kernels' configurations independently. +if(THREADX_ARCH STREQUAL "linux" AND CMAKE_BUILD_TYPE STREQUAL "default_build_coverage") + add_subdirectory(safety_critical) +endif() + # Coverage # # The gate here used to be the build type alone, and only one of the five diff --git a/test/tx/cmake/safety_critical/CMakeLists.txt b/test/tx/cmake/safety_critical/CMakeLists.txt new file mode 100644 index 000000000..1a52af092 --- /dev/null +++ b/test/tx/cmake/safety_critical/CMakeLists.txt @@ -0,0 +1,79 @@ +# Copyright (c) 2026 Eclipse ThreadX contributors +# SPDX-License-Identifier: MIT +# Portions of this file were generated with AI assistance. + +set(repository ${CMAKE_CURRENT_LIST_DIR}/../../../..) +set(common_includes ${repository}/common/inc ${repository}/ports/linux/gnu/inc) +set(common_smp_includes ${repository}/common_smp/inc ${repository}/ports_smp/linux/gnu/inc) + +# Each target supplies its own safety options and uses the normal timer creation path. +add_compile_options(-UTX_REGRESSION_TEST + -UTX_SAFETY_CRITICAL + -UTX_SAFETY_CRITICAL_BUILD_CHECK + -UTX_SAFETY_CRITICAL_EXCEPTION_ENABLE) + +function(add_safety_critical_configuration name option build_check exceptions) + if(build_check) + set(profile_options -DTX_ENABLE_STACK_CHECKING + -DTX_ENABLE_EVENT_TRACE + -DTX_DISABLE_NOTIFY_CALLBACKS) + else() + set(profile_options -DTX_DISABLE_ERROR_CHECKING) + endif() + + # Compile the real kernel entry point, including its default handler where enabled. + foreach(kernel IN ITEMS common common_smp) + set(target safety_critical_${name}_${kernel}) + add_library(${target} OBJECT + configuration.c + ${repository}/${kernel}/src/tx_initialize_kernel_enter.c) + target_include_directories(${target} PRIVATE ${${kernel}_includes}) + target_compile_options(${target} PRIVATE -D${option} ${profile_options} + -ffunction-sections -Werror=unused-parameter) + target_compile_definitions(${target} PRIVATE EXPECT_BUILD_CHECK=${build_check} + EXPECT_EXCEPTIONS=${exceptions}) + endforeach() + + # The single-core timer initializer has an error return to check and can retry + # if the application-supplied handler returns. + set(target safety_critical_${name}_timer) + add_executable(${target} timer_initialize.c ${repository}/common/src/tx_timer_initialize.c) + target_include_directories(${target} PRIVATE ${common_includes}) + target_compile_options(${target} PRIVATE -D${option}) + target_compile_definitions(${target} PRIVATE EXPECT_EXCEPTIONS=${exceptions}) + add_test(NAME ${target} COMMAND ${target}) + set_tests_properties(${target} PROPERTIES TIMEOUT 5) +endfunction() + +add_safety_critical_configuration(checks_only TX_SAFETY_CRITICAL_BUILD_CHECK 1 0) +add_safety_critical_configuration(exceptions_only TX_SAFETY_CRITICAL_EXCEPTION_ENABLE 0 1) +add_safety_critical_configuration(legacy TX_SAFETY_CRITICAL 1 1) + +# Link and exercise the default handler compiled from each kernel's entry point. +find_package(Threads REQUIRED) +foreach(kernel IN ITEMS common common_smp) + set(target safety_critical_default_${kernel}) + add_executable(${target} default_exception.c $) + target_include_directories(${target} PRIVATE ${${kernel}_includes}) + target_compile_options(${target} PRIVATE -DTX_SAFETY_CRITICAL_EXCEPTION_ENABLE -DTX_DISABLE_ERROR_CHECKING) + target_link_libraries(${target} PRIVATE Threads::Threads) + target_link_options(${target} PRIVATE -Wl,--gc-sections) + add_test(NAME ${target} COMMAND ${target}) + set_tests_properties(${target} PROPERTIES TIMEOUT 5) +endforeach() + +# Check that the header rejects disabled error checking for each guarded configuration. +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +foreach(kernel IN ITEMS common common_smp) + foreach(option IN ITEMS TX_SAFETY_CRITICAL_BUILD_CHECK TX_SAFETY_CRITICAL) + try_compile(accepted "${CMAKE_CURRENT_BINARY_DIR}/${kernel}-${option}" + "${CMAKE_CURRENT_LIST_DIR}/configuration.c" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${${kernel}_includes}" + COMPILE_DEFINITIONS -D${option} -DTX_DISABLE_ERROR_CHECKING + OUTPUT_VARIABLE diagnostic) + if(accepted OR NOT diagnostic MATCHES "TX_DISABLE_ERROR_CHECKING must not be defined") + message(FATAL_ERROR "${kernel}: ${option} must reject TX_DISABLE_ERROR_CHECKING\n${diagnostic}") + endif() + unset(accepted CACHE) + endforeach() +endforeach() diff --git a/test/tx/cmake/safety_critical/configuration.c b/test/tx/cmake/safety_critical/configuration.c new file mode 100644 index 000000000..e219ce502 --- /dev/null +++ b/test/tx/cmake/safety_critical/configuration.c @@ -0,0 +1,27 @@ +/*************************************************************************** + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * AI Disclosure: This file was largely AI-generated by Codex (GPT-6.2-Sol). + * The AI-generated portions may be considered public domain (CC0-1.0) + * and not subject to the project's licence. The human contributor has + * reviewed and verified that the code is correct. + * + * SPDX-License-Identifier: MIT and CC0-1.0 + **************************************************************************/ + +#include "tx_api.h" + +#ifdef EXPECT_BUILD_CHECK +#if defined(TX_SAFETY_CRITICAL_BUILD_CHECK) != EXPECT_BUILD_CHECK +#error "Unexpected safety-critical build-check setting." +#endif + +#if (defined(TX_SAFETY_CRITICAL_EXCEPTION_ENABLE) != EXPECT_EXCEPTIONS) || \ + (defined(TX_SAFETY_CRITICAL_EXCEPTION) != EXPECT_EXCEPTIONS) +#error "Unexpected safety-critical exception setting." +#endif +#endif diff --git a/test/tx/cmake/safety_critical/default_exception.c b/test/tx/cmake/safety_critical/default_exception.c new file mode 100644 index 000000000..bd1a26fa5 --- /dev/null +++ b/test/tx/cmake/safety_critical/default_exception.c @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * AI Disclosure: This file was largely AI-generated by Codex (GPT-6.2-Sol). + * The AI-generated portions may be considered public domain (CC0-1.0) + * and not subject to the project's licence. The human contributor has + * reviewed and verified that the code is correct. + * + * SPDX-License-Identifier: MIT and CC0-1.0 + **************************************************************************/ + +#define _POSIX_C_SOURCE 200809L + +#include +#include +#include + +#include "tx_api.h" + +/* MISRA C:2023 Rule 21.8 deviation: exit ends the Linux test process and + lets the coverage runtime write its counters while the handler is halted. */ + +/* End the test after giving an incorrectly returning handler time to fail. */ +static void *finish_test(void *argument) +{ +const struct timespec delay = {0, 100000000L}; + + TX_PARAMETER_NOT_USED(argument); + exit((nanosleep(&delay, NULL) == 0) ? EXIT_SUCCESS : EXIT_FAILURE); +} + +/* Invoke the kernel's real default handler. Returning here is a failure. */ +int main(void) +{ +pthread_t watchdog; + + if (pthread_create(&watchdog, NULL, finish_test, NULL) == 0) + { + TX_SAFETY_CRITICAL_EXCEPTION(__FILE__, __LINE__, TX_SUCCESS); + } + return(EXIT_FAILURE); +} diff --git a/test/tx/cmake/safety_critical/timer_initialize.c b/test/tx/cmake/safety_critical/timer_initialize.c new file mode 100644 index 000000000..23cf83999 --- /dev/null +++ b/test/tx/cmake/safety_critical/timer_initialize.c @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * AI Disclosure: This file was largely AI-generated by Codex (GPT-6.2-Sol). + * The AI-generated portions may be considered public domain (CC0-1.0) + * and not subject to the project's licence. The human contributor has + * reviewed and verified that the code is correct. + * + * SPDX-License-Identifier: MIT and CC0-1.0 + **************************************************************************/ + +/* MISRA C:2023 Rule 21.6 deviation: stderr identifies failed host assertions. */ + +#include +#include +#include + +#include "tx_api.h" +#include "tx_timer.h" + +static UINT create_status; +static UINT create_attempts; +static UINT exception_count; +static UINT exception_status; +static UINT timer_location_reported; + +/* Record the exception reported by the kernel timer initializer. */ +VOID _tx_safety_critical_exception_handler(CHAR *file_name, INT line_number, UINT status) +{ + exception_count++; + exception_status = status; + timer_location_reported = ((file_name != TX_NULL) && (line_number > 0) && + (strstr(file_name, "tx_timer_initialize.c") != TX_NULL)) ? TX_TRUE : TX_FALSE; +} + +/* Simulate one failed timer-thread creation and allow the next attempt. */ +UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG), ULONG entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) +{ +UINT status = create_status; + + TX_PARAMETER_NOT_USED(thread_ptr); + TX_PARAMETER_NOT_USED(name_ptr); + TX_PARAMETER_NOT_USED(entry_function); + TX_PARAMETER_NOT_USED(entry_input); + TX_PARAMETER_NOT_USED(stack_start); + TX_PARAMETER_NOT_USED(stack_size); + TX_PARAMETER_NOT_USED(priority); + TX_PARAMETER_NOT_USED(preempt_threshold); + TX_PARAMETER_NOT_USED(time_slice); + TX_PARAMETER_NOT_USED(auto_start); + + create_status = TX_SUCCESS; + create_attempts++; + return(status); +} + +/* Supply the entry address that the timer initializer passes to thread creation. */ +VOID _tx_timer_thread_entry(ULONG timer_thread_input) +{ + TX_PARAMETER_NOT_USED(timer_thread_input); +} + +/* A failed creation is retried, with a notification in exception-enabled builds. */ +int main(void) +{ +const UINT expected_exceptions = (UINT) EXPECT_EXCEPTIONS; +int result = EXIT_SUCCESS; + + _tx_timer_initialize(); + if ((create_attempts != 1U) || (exception_count != 0U)) + { + (void) fprintf(stderr, "Normal timer initialization failed.\n"); + result = EXIT_FAILURE; + } + + create_status = TX_THREAD_ERROR; + _tx_timer_initialize(); + if (create_attempts != 3U) + { + (void) fprintf(stderr, "Timer initialization did not retry after failure.\n"); + result = EXIT_FAILURE; + } + + if ((exception_count != expected_exceptions) || + ((expected_exceptions != 0U) && ((exception_status != TX_THREAD_ERROR) || (timer_location_reported == TX_FALSE)))) + { + (void) fprintf(stderr, "Unexpected timer initialization exception.\n"); + result = EXIT_FAILURE; + } + + return(result); +} diff --git a/test/tx/cmake/thread_transition/CMakeLists.txt b/test/tx/cmake/thread_transition/CMakeLists.txt index 342ca839c..6dc52dade 100644 --- a/test/tx/cmake/thread_transition/CMakeLists.txt +++ b/test/tx/cmake/thread_transition/CMakeLists.txt @@ -62,12 +62,16 @@ if(MSVC) set(transition_kernel_compile_options "/FI${SOURCE_DIR}/threadx_thread_transition_host_test_port.h") set(transition_undefine_options /UTX_ENABLE_EVENT_TRACE - /UTX_ENABLE_EVENT_LOG) + /UTX_ENABLE_EVENT_LOG + /UTX_SAFETY_CRITICAL + /UTX_SAFETY_CRITICAL_BUILD_CHECK) else() set(transition_kernel_compile_options "-include;${SOURCE_DIR}/threadx_thread_transition_host_test_port.h") set(transition_undefine_options -UTX_ENABLE_EVENT_TRACE - -UTX_ENABLE_EVENT_LOG) + -UTX_ENABLE_EVENT_LOG + -UTX_SAFETY_CRITICAL + -UTX_SAFETY_CRITICAL_BUILD_CHECK) endif() set_source_files_properties( @@ -111,8 +115,8 @@ foreach(configuration ${transition_configurations}) # This directory is configured once per build configuration of the tree, so # these executables inherit whichever feature macros that configuration sets -- # which is useful, since it means the two configurations above are also seen in - # combination with stack checking and with the other four. The one that cannot - # be inherited is event tracing: the trace macros in these sources reference the + # combination with stack checking and with the other four. Event tracing + # cannot be inherited: the trace macros in these sources reference the # trace component's buffer and registry, and this harness links four kernel # sources rather than the library, so the references would not resolve. The # trace insertions in these same sources are covered by the tree's own @@ -120,8 +124,12 @@ foreach(configuration ${transition_configurations}) # lost by turning tracing off here. Event logging is turned off for the same # reason; no configuration of the tree enables it. # + # Safety-critical build checks reject options these tests exercise. The + # kernel entry point that defines the exception handler is also outside + # this harness. + # # The undefine options have to reach the test source as well as the kernel sources, - # because TX_ENABLE_EVENT_TRACE is visible to tx_api.h and the two must agree on + # because these macros are visible to tx_api.h and the two must agree on # what the headers declare. Target compile options land after the directory's # definition flags on the command line, which is what makes them effective. target_compile_options(${test_target} PRIVATE ${transition_undefine_options}) diff --git a/test/tx/regression/testcontrol.c b/test/tx/regression/testcontrol.c index bec50ee76..3ef3991cd 100644 --- a/test/tx/regression/testcontrol.c +++ b/test/tx/regression/testcontrol.c @@ -488,7 +488,9 @@ void tx_application_define(void *first_unused_memory) { UCHAR *pointer; +#if !defined(TX_DISABLE_NOTIFY_CALLBACKS) && !defined(TX_SAFETY_CRITICAL) VOID (*temp_mutex_release)(TX_THREAD *thread_ptr); +#endif TX_THREAD *temp_thread; UINT old_preemption; UINT status; @@ -607,7 +609,7 @@ TX_THREAD *thread_ptr; init_test_thread.tx_thread_ready_previous = &init_test_thread; _tx_thread_time_slice(); _tx_thread_current_ptr = TX_NULL; -#ifndef TX_DISABLE_NOTIFY_CALLBACKS +#if !defined(TX_DISABLE_NOTIFY_CALLBACKS) && !defined(TX_SAFETY_CRITICAL) /* Test to make sure _tx_thread_shell_entry can handle a NULL mutex release function pointer. */ temp_mutex_release = _tx_thread_mutex_release; temp_thread = _tx_thread_execute_ptr; diff --git a/test/tx/regression/threadx_timer_activate_deactivate_test.c b/test/tx/regression/threadx_timer_activate_deactivate_test.c index ceaf79bf7..ba31577d4 100644 --- a/test/tx/regression/threadx_timer_activate_deactivate_test.c +++ b/test/tx/regression/threadx_timer_activate_deactivate_test.c @@ -8,6 +8,7 @@ /* */ /* SPDX-License-Identifier: MIT */ /***************************************************************************/ +// Portions of this file were generated with AI assistance. /* This test is designed to test application timer activation/deactivation services from threads and the activation routines. */ @@ -96,7 +97,7 @@ TX_TIMER_INTERNAL **current_list_head; /* Inform user. */ printf("Running Timer Activate/Deactivate Test.............................. "); -#ifndef TX_TIMER_PROCESS_IN_ISR +#if !defined(TX_TIMER_PROCESS_IN_ISR) && !defined(TX_SAFETY_CRITICAL) /* Call the timer thread entry function with an invalid value to make sure the code simply returns. */ _tx_timer_thread_entry(0); diff --git a/test/tx/regression/threadx_timer_simple_test.c b/test/tx/regression/threadx_timer_simple_test.c index f9c93ee42..f3fa8f22f 100644 --- a/test/tx/regression/threadx_timer_simple_test.c +++ b/test/tx/regression/threadx_timer_simple_test.c @@ -221,7 +221,7 @@ CHAR *pointer; test_control_return(1); } -#ifndef TX_TIMER_PROCESS_IN_ISR +#if !defined(TX_TIMER_PROCESS_IN_ISR) && !defined(TX_SAFETY_CRITICAL) /* Call the timer thread entry function with a bad ID to test another path. */ _tx_timer_thread_entry(0);