Skip to content

Commit de0f2db

Browse files
committed
Fixed RISC-V regression portability failures
RISC-V regression builds ran only at -O0, leaving a timer callback counter that spins forever at -O2. The trace regression was excluded because it referenced a port-specific interrupt-save variable, and its adjacent pools could start misaligned on RV64. Made the timer counter volatile, gave the trace test aligned pool storage and a portable saved-interrupt value, and enabled it on RISC-V. Added an -O2 QEMU configuration to keep the optimized failure covered. CMake/Ninja/QEMU: RV64 default, optimized and trace suites passed 97/97 each; RV32 passed 96/96 each. Two ISR event tests passed 30 repeats each at -O2. The Linux/GCC 14 trace test passed. The reported timing resonance did not recur. Assisted-by: Codex (GPT-6) <noreply@openai.com>
1 parent 70a5300 commit de0f2db

4 files changed

Lines changed: 40 additions & 24 deletions

File tree

‎test/tx/cmake/riscv/CMakeLists.txt‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_policy(SET CMP0057 NEW)
55
project(threadx_riscv_test LANGUAGES C ASM)
66

77
# Build configurations (same defines as Linux tests, minus coverage instrumentation)
8-
set(BUILD_CONFIGURATIONS default_build disable_notify_callbacks_build
8+
set(BUILD_CONFIGURATIONS default_build optimized_build disable_notify_callbacks_build
99
stack_checking_build stack_checking_rand_fill_build trace_build)
1010
set(CMAKE_CONFIGURATION_TYPES
1111
${BUILD_CONFIGURATIONS}
@@ -26,14 +26,21 @@ message(STATUS "THREADX_ARCH: ${THREADX_ARCH}")
2626

2727
# Per-configuration compile definitions
2828
set(default_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32)
29+
set(optimized_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32)
2930
set(disable_notify_callbacks_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_DISABLE_NOTIFY_CALLBACKS)
3031
set(stack_checking_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_STACK_CHECKING)
3132
set(stack_checking_rand_fill_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_STACK_CHECKING -DTX_ENABLE_RANDOM_NUMBER_STACK_FILLING)
3233
set(trace_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_EVENT_TRACE)
3334

35+
if(CMAKE_BUILD_TYPE STREQUAL "optimized_build")
36+
set(REGRESSION_OPTIMIZATION -O2)
37+
else()
38+
set(REGRESSION_OPTIMIZATION -O0)
39+
endif()
40+
3441
add_compile_options(
3542
-std=c99
36-
-O0
43+
${REGRESSION_OPTIMIZATION}
3744
-g3
3845
-fdiagnostics-color
3946
-Werror

‎test/tx/cmake/riscv/regression/CMakeLists.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ set(regression_test_cases
110110
${SOURCE_DIR}/threadx_timer_multiple_accuracy_test.c
111111
${SOURCE_DIR}/threadx_timer_multiple_test.c
112112
${SOURCE_DIR}/threadx_timer_simple_test.c
113-
# threadx_trace_basic_test.c excluded: references tx_saved_posture
114-
# (the Linux port's interrupt save variable) which is named
115-
# interrupt_save on RISC-V.
113+
${SOURCE_DIR}/threadx_trace_basic_test.c
116114
)
117115

118116
# Architecture specific tests living next to this file. The RV32 stack

‎test/tx/regression/threadx_thread_multi_level_preemption_threshold_test.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* SPDX-License-Identifier: MIT */
1010
/***************************************************************************/
1111

12+
/* Portions of this file were generated with AI assistance. */
13+
1214
/* This test is designed to test multi-level preemption threshold. The protection placed
1315
by a thread must be preserved after higher-priority thread preemption that is above the threshold. */
1416

@@ -74,7 +76,7 @@ static TX_TIMER timer_0;
7476

7577
/* Define counters. */
7678

77-
static unsigned long timer_0_counter = 0;
79+
static volatile unsigned long timer_0_counter = 0;
7880
static unsigned long thread_1_0_counter = 0;
7981
static unsigned long thread_2_1_counter = 0;
8082
static unsigned long thread_3_2_counter = 0;

‎test/tx/regression/threadx_trace_basic_test.c‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* SPDX-License-Identifier: MIT */
1010
/***************************************************************************/
1111

12+
/* Portions of this file were generated with AI assistance. */
13+
1214
/* This test is designed to test trace functionality in ThreadX. */
1315

1416

@@ -66,6 +68,16 @@ static unsigned long error = 0;
6668
static unsigned long full_buffer = 0;
6769
static void *save_pointer;
6870

71+
#define TRACE_BLOCK_POOL_SIZE ((ULONG) (((100U + sizeof(ALIGN_TYPE) - 1U) / sizeof(ALIGN_TYPE)) * sizeof(ALIGN_TYPE)))
72+
#define TRACE_BYTE_POOL_SIZE ((ULONG) (((1000U + sizeof(ALIGN_TYPE) - 1U) / sizeof(ALIGN_TYPE)) * sizeof(ALIGN_TYPE)))
73+
74+
/* Keep pool storage aligned for ports with pointer-wide metadata. */
75+
static struct
76+
{
77+
ALIGN_TYPE alignment;
78+
CHAR bytes[TRACE_BLOCK_POOL_SIZE + TRACE_BYTE_POOL_SIZE + 400U];
79+
} object_memory;
80+
6981
#if defined(TX_WIN32_MEMORY_SIZE) || defined(TX_LINUX_MEMORY_SIZE)
7082

7183
static FILE *trace_dump_file;
@@ -185,25 +197,21 @@ INT status;
185197
CHAR *pointer;
186198

187199

188-
/* Setup a pointer. */
189-
pointer = (CHAR *) first_unused_memory;
190-
191-
/* Adjust it forward just to make sure there is some space for the test below. */
192-
pointer = pointer + 200;
200+
/* Setup aligned object storage. */
201+
pointer = object_memory.bytes;
193202

194203
/* Create a bunch of objects before being enabled. */
195204

196205
/* Create a timer for the test. */
197206
save_pointer = (void *) pointer;
198207
tx_timer_create(&timer_0, "timer 0", timer_entry, 0, 2, 2, TX_AUTO_ACTIVATE);
199-
tx_block_pool_create(&block_pool_0, "block pool 0", 20, pointer, 100);
200-
pointer = pointer + 100;
201-
tx_byte_pool_create(&byte_pool_0, "byte pool 0", pointer, 1000);
202-
pointer = pointer + 1000;
208+
tx_block_pool_create(&block_pool_0, "block pool 0", 20, pointer, TRACE_BLOCK_POOL_SIZE);
209+
pointer = pointer + TRACE_BLOCK_POOL_SIZE;
210+
tx_byte_pool_create(&byte_pool_0, "byte pool 0", pointer, TRACE_BYTE_POOL_SIZE);
211+
pointer = pointer + TRACE_BYTE_POOL_SIZE;
203212
tx_event_flags_create(&group_0, "event flags group 0");
204213
tx_mutex_create(&mutex_0, "mutex 0", TX_NO_INHERIT);
205214
tx_queue_create(&queue_0, "queue 0", 16, pointer, 400);
206-
pointer = pointer + 400;
207215
tx_semaphore_create(&semaphore_0, "semaphore 0", 1);
208216

209217
/* Enable event tracing. */
@@ -230,6 +238,9 @@ CHAR *pointer;
230238
}
231239
#endif
232240

241+
pointer = (CHAR *) first_unused_memory;
242+
pointer = pointer + 200;
243+
233244
/* Put system definition stuff in here, e.g. thread creates and other assorted
234245
create information. */
235246

@@ -281,12 +292,11 @@ static void thread_0_entry(ULONG thread_input)
281292
UINT status;
282293
UINT old_interrupt;
283294
CHAR *pointer;
284-
TX_INTERRUPT_SAVE_AREA
285295
ULONG object;
286296

287297
/* Coverage for build without TraceX enabled. */
288-
tx_saved_posture = _tx_trace_interrupt_control(TX_INT_DISABLE);
289-
_tx_trace_interrupt_control(tx_saved_posture);
298+
old_interrupt = _tx_trace_interrupt_control(TX_INT_DISABLE);
299+
_tx_trace_interrupt_control(old_interrupt);
290300
#ifndef TX_ENABLE_EVENT_TRACE
291301
_tx_trace_object_register(0, TX_NULL, TX_NULL, 0, 0);
292302
_tx_trace_object_register(1, TX_NULL, TX_NULL, 0, 0);
@@ -354,14 +364,13 @@ ULONG object;
354364

355365
/* Now, create them all again. */
356366
pointer = (CHAR *) save_pointer;
357-
tx_block_pool_create(&block_pool_0, "block pool 0", 20, pointer, 100);
358-
pointer = pointer + 100;
359-
tx_byte_pool_create(&byte_pool_0, "byte pool 0", pointer, 1000);
360-
pointer = pointer + 1000;
367+
tx_block_pool_create(&block_pool_0, "block pool 0", 20, pointer, TRACE_BLOCK_POOL_SIZE);
368+
pointer = pointer + TRACE_BLOCK_POOL_SIZE;
369+
tx_byte_pool_create(&byte_pool_0, "byte pool 0", pointer, TRACE_BYTE_POOL_SIZE);
370+
pointer = pointer + TRACE_BYTE_POOL_SIZE;
361371
tx_event_flags_create(&group_0, "event flags group 0");
362372
tx_mutex_create(&mutex_0, "mutex 0", TX_NO_INHERIT);
363373
tx_queue_create(&queue_0, "queue 0", 16, pointer, 400);
364-
pointer = pointer + 400;
365374
tx_semaphore_create(&semaphore_0, "semaphore 0", 1);
366375

367376
/* Attempt to enable event tracing again. */

0 commit comments

Comments
 (0)