Skip to content

Fix #442, insert a transaction that outranks every queued one at the front - #538

Open
SpaceOceanCorp wants to merge 1 commit into
nasa:devfrom
SpaceOceanCorp:fix-442-priority-insert-front
Open

SpaceOceanCorp wants to merge 1 commit into
nasa:devfrom
SpaceOceanCorp:fix-442-priority-insert-front

Conversation

@SpaceOceanCorp

Copy link
Copy Markdown

Description of Change

CF_InsertSortPrio searches the queue from the back for the last transaction whose priority is equal or higher (a lower or equal number) and inserts the new one after it. When there is no such transaction, the new one outranks everything queued, but it was inserted at the back, so it ran last. It is now inserted at the front.

This follows the fix suggested in the issue: a new CF_CList_InsertFront_Ex in cf_utils.h (the same pattern as CF_CList_InsertBack_Ex), used in that branch. An empty queue still uses CF_CList_InsertBack_Ex, which gives the same result.

Linked Issue

Closes #442

Requirements Impact

  • Requirement ID(s): none changed
  • Requirements updated as necessary
  • Existing requirements are still satisfied by this change

Testing Evidence

Unit Tests (UT Assert)

The existing test for this case, Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex, asserted the old behavior. It is now Test_CF_InsertSortPrio_When_No_Equal_Or_Higher_Priority_Found_Call_CF_CList_InsertFront_Ex and checks that CF_CList_InsertFront is called once, on the right queue head and node, and that CF_CList_InsertBack is not called. CF_CList_InsertFront gets a default stub handler and context type to capture its arguments, the same as CF_CList_InsertBack.

In the cFS bundle (029b3ab, native_std, unit tests enabled) with this branch, CF builds with no warnings and all 14 CF unit-test suites pass. With fsw/src/cf_utils.c and cf_utils.h reverted and the updated test kept, cf_utils fails. The changed files are clean under the cFS .clang-format (clang-format 19.1.7).

Randomized check on the real queue code

The unit tests stub out the list functions, so they cannot show the resulting order. As a further check outside the PR, we compiled CF's real cf_clist.c together with CF_PrioSearch, CF_InsertSortPrio and the CF_CList_*_Ex helpers, extracted verbatim from dev and from this branch, with minimal stand-in types. The check inserts 1 to 40 transactions with random priorities 0 to 5 into one queue, 200,000 times, and walks the queue from its head, the order in which CF_CFDP_StartFirstPending takes pending transactions. Built with ASan and UBSan:

Queues not sorted by priority Head is not the highest priority Equal priorities out of FIFO order q_size wrong
dev 154,965 (77.5%) 154,965 0 0
this branch 0 0 0 0

COSMOS Test Suite

N/A: no telemetry, command or table changes.

Areas of Expertise Touched

  • Unit Tests
  • Other: CFDP transaction queues

Author Checklist

  • Linked GitHub issue is referenced above
  • Code has been formatted with .clang-format
  • Static analysis workflows ran and passed
  • Unit tests (UT Assert) updated/added to cover code changes
  • Unit test workflows ran and passed
  • COSMOS test suite was run; tests updated/added if relevant changes were made
  • Requirements have been reviewed; updated or confirmed still satisfied (see above)
  • Testing evidence is included above
  • Self-review of the diff completed

F´'s CfdpManager, which was ported from CF v3.0.0, has the same logic (Channel::insertSortPrio), noted in nasa/fprime#6377.

CLA: cFS Apps corporate CLA filed by Space Ocean Corp.

…the front

CF_InsertSortPrio searches the queue from the back for the last transaction
whose priority is equal or higher (lower or equal number) and inserts after
it. When there is none, the new transaction outranks every queued one, but it
was inserted at the back. Insert it at the front instead.

Adds CF_CList_InsertFront_Ex and a UT handler for CF_CList_InsertFront; the
unit test for this case now expects the front insert.
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.

Transaction priority sorted incorrectly

1 participant