Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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. */

Expand All @@ -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) \
{ \
} \
Expand Down
3 changes: 2 additions & 1 deletion common/src/tx_initialize_kernel_enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* SPDX-License-Identifier: MIT
**************************************************************************/
// Portions of this file were generated with AI assistance.


/**************************************************************************/
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion common/src/tx_timer_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions common_smp/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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. */

Expand All @@ -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) \
{ \
} \
Expand Down
3 changes: 2 additions & 1 deletion common_smp/src/tx_initialize_kernel_enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* SPDX-License-Identifier: MIT
**************************************************************************/
// Portions of this file were generated with AI assistance.


/**************************************************************************/
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/smp/regression/testcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion test/smp/regression/threadx_timer_activate_deactivate_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/smp/regression/threadx_timer_simple_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/tx/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions test/tx/cmake/safety_critical/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_OBJECTS:safety_critical_exceptions_only_${kernel}>)
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()
27 changes: 27 additions & 0 deletions test/tx/cmake/safety_critical/configuration.c
Original file line number Diff line number Diff line change
@@ -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
Loading