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
3 changes: 2 additions & 1 deletion fsw/src/cf_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ void CF_InsertSortPrio(CF_Transaction_t *txn, CF_QueueIdx_t queue)
}
else
{
insert_back = true;
/* every queued transaction has a lower priority (higher number), so this one goes first */
CF_CList_InsertFront_Ex(chan, queue, &txn->cl_node);
}
}

Expand Down
6 changes: 6 additions & 0 deletions fsw/src/cf_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ static inline void CF_CList_InsertBack_Ex(CF_Channel_t *chan, CF_QueueIdx_t queu
++chan->stat.q_size[queueidx];
}

static inline void CF_CList_InsertFront_Ex(CF_Channel_t *chan, CF_QueueIdx_t queueidx, CF_CListNode_t *node)
{
CF_CList_InsertFront(&chan->qs[queueidx], node);
++chan->stat.q_size[queueidx];
}

/************************************************************************/
/** @brief Find an unused transaction on a channel.
*
Expand Down
41 changes: 23 additions & 18 deletions unit-test/cf_utils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ void Test_CF_InsertSortPrio_Call_CF_CList_InsertAfter_Ex_AndSet_q_index_To_q(voi
arg_q);
}

void Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex(void)
void Test_CF_InsertSortPrio_When_No_Equal_Or_Higher_Priority_Found_Call_CF_CList_InsertFront_Ex(void)
{
/* Arrange */
CF_Transaction_t txn;
Expand All @@ -832,11 +832,11 @@ void Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex(void)
CF_Channel_t *chan = CF_GetChannelPtr(chan_num);
CF_CListNode_t *expected_end;
CF_CListFn_t expected_fn;
CF_CListNode_t **expected_insert_back_head;
CF_CListNode_t *expected_insert_back_node;
CF_CListNode_t **expected_insert_front_head;
CF_CListNode_t *expected_insert_front_node;

CF_CList_Traverse_R_context_t context_cf_clist_traverse_r;
CF_CList_InsertBack_context_t context_clist_insert_back;
CF_CList_Traverse_R_context_t context_cf_clist_traverse_r;
CF_CList_InsertFront_context_t context_clist_insert_front;

UT_SetDataBuffer(UT_KEY(CF_CList_Traverse_R),
&context_cf_clist_traverse_r,
Expand All @@ -851,17 +851,21 @@ void Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex(void)
* &qs makes the list NOT empty */
chan->qs[arg_q] = (CF_CListNode_t *)&qs;

/* setup CF_Traverse_PriorityArg_t altered value */
/* No queued transaction has an equal or higher priority (lower or equal number), so the
* search finds nothing and the new transaction must go to the front of the queue (#442) */
context_cf_clist_traverse_r.context_t = NULL;

/* set expected values */
expected_end = chan->qs[arg_q];
expected_fn = CF_PrioSearch;
expected_insert_back_head = &chan->qs[arg_q];
expected_insert_back_node = &arg_t->cl_node;

/* Arrange for CF_CList_InsertBack_Ex */
UT_SetDataBuffer(UT_KEY(CF_CList_InsertBack), &context_clist_insert_back, sizeof(context_clist_insert_back), false);
expected_end = chan->qs[arg_q];
expected_fn = CF_PrioSearch;
expected_insert_front_head = &chan->qs[arg_q];
expected_insert_front_node = &arg_t->cl_node;

/* Arrange for CF_CList_InsertFront_Ex */
UT_SetDataBuffer(UT_KEY(CF_CList_InsertFront),
&context_clist_insert_front,
sizeof(context_clist_insert_front),
false);

/* Act */
CF_InsertSortPrio(arg_t, arg_q);
Expand All @@ -871,9 +875,10 @@ void Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex(void)
UtAssert_ADDRESS_EQ(context_cf_clist_traverse_r.end, expected_end);
UtAssert_True(context_cf_clist_traverse_r.fn == expected_fn, "context_cf_clist_traverse_r.fn == expected_fn");
UtAssert_STUB_COUNT(CF_CList_InsertAfter, 0);
UtAssert_STUB_COUNT(CF_CList_InsertBack, 1);
UtAssert_ADDRESS_EQ(context_clist_insert_back.head, expected_insert_back_head);
UtAssert_ADDRESS_EQ(context_clist_insert_back.node, expected_insert_back_node);
UtAssert_STUB_COUNT(CF_CList_InsertBack, 0);
UtAssert_STUB_COUNT(CF_CList_InsertFront, 1);
UtAssert_ADDRESS_EQ(context_clist_insert_front.head, expected_insert_front_head);
UtAssert_ADDRESS_EQ(context_clist_insert_front.node, expected_insert_front_node);
UtAssert_True(arg_t->flags.com.q_index == arg_q,
"txn->flags.com.q_index is %u and should be %u (q)",
arg_t->flags.com.q_index,
Expand Down Expand Up @@ -1331,10 +1336,10 @@ void add_CF_InsertSortPrio_tests(void)
cf_utils_tests_Setup,
cf_utils_tests_Teardown,
"Test_CF_InsertSortPrio_Call_CF_CList_InsertAfter_Ex_AndSet_q_index_To_q");
UtTest_Add(Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex,
UtTest_Add(Test_CF_InsertSortPrio_When_No_Equal_Or_Higher_Priority_Found_Call_CF_CList_InsertFront_Ex,
cf_utils_tests_Setup,
cf_utils_tests_Teardown,
"Test_CF_InsertSortPrio_When_p_t_Is_NULL_Call_CF_CList_InsertBack_Ex");
"Test_CF_InsertSortPrio_When_No_Equal_Or_Higher_Priority_Found_Call_CF_CList_InsertFront_Ex");
}

void add_CF_TraverseAllTransactions_Impl_tests(void)
Expand Down
17 changes: 17 additions & 0 deletions unit-test/stubs/cf_clist_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ void UT_DefaultHandler_CF_CList_InsertBack(void *UserObj, UT_EntryKey_t FuncKey,
}
}

/*----------------------------------------------------------------
*
* For compatibility with other tests, this has a mechanism to save its
* arguments to a test-provided context capture buffer.
*
*-----------------------------------------------------------------*/
void UT_DefaultHandler_CF_CList_InsertFront(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
CF_CList_InsertFront_context_t *ctxt = UT_CF_GetContextBuffer(FuncKey, CF_CList_InsertFront_context_t);

if (ctxt)
{
ctxt->head = UT_Hook_GetArgValueByName(Context, "head", CF_CListNode_t **);
ctxt->node = UT_Hook_GetArgValueByName(Context, "node", CF_CListNode_t *);
}
}

/*----------------------------------------------------------------
*
* For compatibility with other tests, this has a mechanism to save its
Expand Down
3 changes: 2 additions & 1 deletion unit-test/stubs/cf_clist_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
void UT_DefaultHandler_CF_CList_InitNode(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_InsertAfter(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_InsertBack(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_InsertFront(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_Remove(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_Traverse(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_CList_Traverse_R(void *, UT_EntryKey_t, const UT_StubContext_t *);
Expand Down Expand Up @@ -82,7 +83,7 @@ void CF_CList_InsertFront(CF_CListNode_t **head, CF_CListNode_t *node)
UT_GenStub_AddParam(CF_CList_InsertFront, CF_CListNode_t **, head);
UT_GenStub_AddParam(CF_CList_InsertFront, CF_CListNode_t *, node);

UT_GenStub_Execute(CF_CList_InsertFront, Basic, NULL);
UT_GenStub_Execute(CF_CList_InsertFront, Basic, UT_DefaultHandler_CF_CList_InsertFront);
}

/*
Expand Down
6 changes: 6 additions & 0 deletions unit-test/utilities/cf_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ typedef struct
CF_CListNode_t *node;
} CF_CList_InsertBack_context_t;

typedef struct
{
CF_CListNode_t **head;
CF_CListNode_t *node;
} CF_CList_InsertFront_context_t;

typedef struct
{
CF_CListNode_t **head;
Expand Down
Loading