Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #958, Convert some UT_GetStubCount to UtAssert_STUB_COUNT #1377

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/unit-test-coverage/portable/src/coveragetest-posix-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Test_OS_GenericRead_Impl(void)
UT_SetDataBuffer(UT_KEY(OCS_read), SrcData, sizeof(SrcData), false);
UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true);
OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, sizeof(DestData), 0), sizeof(DestData));
UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called");
UtAssert_STUB_COUNT(OS_SelectSingle_Impl, 1);

/* Read 0 bytes */
OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (&token, DestData, 0, 0), OS_SUCCESS);
Expand Down Expand Up @@ -164,7 +164,7 @@ void Test_OS_GenericWrite_Impl(void)
UT_SetDataBuffer(UT_KEY(OCS_write), DestData, sizeof(DestData), false);
UT_PortablePosixIOTest_Set_Selectable(UT_INDEX_0, true);
OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (&token, SrcData, sizeof(SrcData), 0), sizeof(SrcData));
UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called");
UtAssert_STUB_COUNT(OS_SelectSingle_Impl, 1);

/* Fail select */
UT_SetDeferredRetcode(UT_KEY(OS_SelectSingle_Impl), 1, OS_ERROR_TIMEOUT);
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/vxworks/src/coveragetest-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void Test_OS_ConsoleWakeup_Impl(void)

/* this just gives the sem, only called in async mode */
OS_ConsoleWakeup_Impl(&token);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode");
UtAssert_STUB_COUNT(OCS_semGive, 1);

/* Failure only causes a debug message to be generated, no error handling here */
UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1);
Expand Down
6 changes: 3 additions & 3 deletions src/unit-test-coverage/vxworks/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ void Test_OS_FileSysStopVolume_Impl(void)
UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 4);
token = UT_TOKEN_1;
OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 1, "xbdBlkDevDelete() called");
UtAssert_STUB_COUNT(OCS_xbdBlkDevDelete, 1);

/* Test alternative branches */
UT_ResetState(UT_KEY(OCS_xbdBlkDevDelete));
UT_FileSysTest_SetupFileSysEntry(1, NULL, OCS_NULLDEV, 4);
OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 0, "xbdBlkDevDelete() not called");
UtAssert_STUB_COUNT(OCS_xbdBlkDevDelete, 0);

UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 0);
OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 0, "xbdBlkDevDelete() not called");
UtAssert_STUB_COUNT(OCS_xbdBlkDevDelete, 0);
}

void Test_OS_FileSysFormatVolume_Impl(void)
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/vxworks/src/coveragetest-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void Test_OS_ShellOutputToFile_Impl(void)
*/
UT_SetDeferredRetcode(UT_KEY(OCS_taskNameToId), 2, -1);
OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called");
UtAssert_STUB_COUNT(OCS_shellGenericInit, 1);

/* failure to open the output file */
UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, OS_ERROR);
Expand Down
28 changes: 14 additions & 14 deletions src/unit-test-coverage/vxworks/src/coveragetest-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Test_OS_VxWorksEntry(void)
* static int OS_VxWorksEntry(int arg)
*/
OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(OS_OBJECT_ID_UNDEFINED), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OS_TaskEntryPoint)) == 1, "OS_TaskEntryPoint() called");
UtAssert_STUB_COUNT(OS_TaskEntryPoint, 1);
}

void Test_OS_TaskCreate_Impl(void)
Expand All @@ -76,32 +76,32 @@ void Test_OS_TaskCreate_Impl(void)

UT_ClearDefaultReturnValue(UT_KEY(OCS_malloc));
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 1, "taskInit() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 1, "taskActivate() called");
UtAssert_STUB_COUNT(OCS_malloc, 2);
UtAssert_STUB_COUNT(OCS_free, 0);
UtAssert_STUB_COUNT(OCS_taskInit, 1);
UtAssert_STUB_COUNT(OCS_taskActivate, 1);

/* create again with smaller stack - this should re-use existing buffer */
OS_task_table[0].stack_size = 100;
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() not called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 2, "taskInit() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 2, "taskActivate() called");
UtAssert_STUB_COUNT(OCS_malloc, 2);
UtAssert_STUB_COUNT(OCS_free, 0);
UtAssert_STUB_COUNT(OCS_taskInit, 2);
UtAssert_STUB_COUNT(OCS_taskActivate, 2);

/* create again with larger stack - this should free existing and malloc() new buffer */
OS_task_table[0].stack_size = 400;
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 1, "free() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 3, "taskInit() called");
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 3, "taskActivate() called");
UtAssert_STUB_COUNT(OCS_malloc, 3);
UtAssert_STUB_COUNT(OCS_free, 1);
UtAssert_STUB_COUNT(OCS_taskInit, 3);
UtAssert_STUB_COUNT(OCS_taskActivate, 3);

/* create again with nonzero userstackbase */
OS_task_table[0].stack_pointer = userstack;
OS_task_table[0].stack_size = sizeof(userstack);
OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS);
UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() not called");
UtAssert_STUB_COUNT(OCS_malloc, 3);

/* other failure modes */
UT_SetDefaultReturnValue(UT_KEY(OCS_taskInit), -1);
Expand Down