Skip to content

Covered zero-event suspension and SMP lower priority inheritance change - #847

Open
Dev10-sys wants to merge 2 commits into
eclipse-threadx:devfrom
Dev10-sys:test/event-flags-zero-and-smp-priority-inheritance
Open

Dev10-sys wants to merge 2 commits into
eclipse-threadx:devfrom
Dev10-sys:test/event-flags-zero-and-smp-priority-inheritance

Conversation

@Dev10-sys

Copy link
Copy Markdown

PR checklist

  • Updated function header with a short description and version number
  • Added test case for bug fix or new feature
  • Validated on real hardware

Description

While checking the regression test suites with code coverage enabled, I noticed a couple of real branches in the kernel that were never hit by existing tests. I added targeted test cases to cover both paths and protect against regression.

The first gap was in tx_event_flags_get. The kernel includes a safeguard where requesting zero event flags (requested_flags == 0) with suspension (wait_option != TX_NO_WAIT) immediately returns TX_NO_EVENTS instead of suspending the thread. Without this safeguard, a thread asking for zero events would suspend and deadlock waiting on nothing. The existing test suite only checked zero flags with TX_NO_WAIT, leaving the suspension branch unverified. I added test cases in both the standard (test/tx) and SMP (test/smp) regression tests to make sure requesting zero flags with a timeout returns TX_NO_EVENTS immediately and prevents accidental deadlocks.

The second gap was in SMP priority inheritance inside _tx_thread_smp_simple_priority_change (common_smp/src/tx_thread_smp_utilities.c). When a thread inherits a higher priority from a mutex and its base priority is changed to a lower priority (new_priority >= inherit_priority), the kernel must keep the running priority and preempt threshold at the inherited priority to prevent priority inversion. This branch had zero test coverage. I added a test case in threadx_thread_priority_change.c to verify that the inherited priority is properly preserved when the new priority is lower, and that thread priority lists are cleanly restored.

Local Testing

  • Ran both threadx_event_flag_basic_test (standard and SMP) and threadx_thread_priority_change (SMP) locally with coverage enabled.
  • All test suites passed with 0 errors and 0 system errors.
  • Gcov confirms the zero-flag suspension branches in tx_event_flags_get.c and lines 1074–1075 of tx_thread_smp_utilities.c are now covered, bringing tx_thread_smp_utilities.c to 100% line coverage.

In tx_event_flags_get, calling the function with requested_flags set to 0 and wait_option != TX_NO_WAIT enters the early return branch setting status = TX_NO_EVENTS, preventing suspension on zero events. Tests previously only covered this with TX_NO_WAIT. Added regression cases in both standard and SMP suites to verify immediate return when suspension is requested on zero event flags.

In common_smp/src/tx_thread_smp_utilities.c, the simple priority change helper handles cases where the new priority is lower (numerically greater) than the thread's inherited priority by maintaining the thread's active priority and preempt threshold at the inherited priority. Added a test case in threadx_thread_priority_change.c to exercise this branch and properly restore thread priority state afterwards.

Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
…and FreeRTOS wrapper

Add unit and regression tests to close remaining execution and coverage
gaps across the ThreadX core scheduler, SMP time-slicing, module manager
host suite, low-power and execution profile utilities, and the FreeRTOS
compatibility layer:

- test/tx/regression/threadx_thread_basic_execution_test.c: Exercise
  deferred _tx_thread_system_resume preemption handoff when
  _tx_thread_preempt_disable > 0 and higher- then lower-priority
  threads are resumed.
- test/smp/regression/threadx_smp_time_slice_test.c: Exercise the SMP
  time-slice ready-list scan wraparound path when all ready equal-priority
  threads are currently executing on cores.
- test/freertos/regression/: Add runtime tests covering queues, queue
  sets, semaphores, mutexes, task lifecycle, notifications, event
  groups, and software timers.
- test/tx/low_power/ and test/tx/execution_profile/: Add standalone
  host tests for low-power enter/exit/next-timer helpers and execution
  profile tick/ISR/thread/idle counters.
- test/tx/module_manager/: Add host tests covering module callback
  notification trampolines and queue deduplication, full module
  manager lifecycle and cleanup paths, and dispatcher parameter, range,
  and ownership validation.

Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
@fdesbiens

Copy link
Copy Markdown
Contributor

Hi @Dev10-sys, thanks for adding these coverage tests. Could you cherry-pick dfac3661 onto a fresh branch from dev, resolve the conflict in test/tx/cmake/module_manager/CMakeLists.txt, and open a follow-up PR from your fork? That keeps the broader tests under your authorship and gives us room to review them on their own.

Once the follow-up is open, I can revert that commit on #847 so this PR stays focused on the zero-event wait and SMP priority-inheritance tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants