Skip to content

Commit

Permalink
fix #559 Refactoring UT_SetForceFail to UT_SetDefaultReturnValue
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Nov 13, 2020
1 parent 1a82657 commit 52ee871
Show file tree
Hide file tree
Showing 39 changed files with 193 additions and 168 deletions.
6 changes: 3 additions & 3 deletions src/unit-test-coverage/portable/src/coveragetest-bsd-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Test_OS_SelectSingle_Impl(void)
SelectFlags = 0;
OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS);

UT_SetForceFail(UT_KEY(OCS_select), 0);
UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0);
SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE;
nowtime.tv_sec = 1;
nowtime.tv_nsec = 500000000;
Expand All @@ -60,7 +60,7 @@ void Test_OS_SelectSingle_Impl(void)
UT_SetDataBuffer(UT_KEY(OCS_clock_gettime), &latertime, sizeof(latertime), false);
OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 999), OS_ERROR_TIMEOUT);

UT_SetForceFail(UT_KEY(OCS_select), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_select), -1);
SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE;
nowtime.tv_sec = 1;
nowtime.tv_nsec = 0;
Expand All @@ -84,7 +84,7 @@ void Test_OS_SelectMultiple_Impl(void)
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_SUCCESS);
memset(&ReadSet, 0xff, sizeof(ReadSet));
memset(&WriteSet, 0, sizeof(WriteSet));
UT_SetForceFail(UT_KEY(OCS_select), 0);
UT_SetDefaultReturnValue(UT_KEY(OCS_select), 0);
OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 1), OS_ERROR_TIMEOUT);
} /* end OS_SelectMultiple_Impl */

Expand Down
14 changes: 7 additions & 7 deletions src/unit-test-coverage/portable/src/coveragetest-posix-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Test_OS_FileOpen_Impl(void)
OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", 0, -1234), OS_ERROR);

/* failure mode */
UT_SetForceFail(UT_KEY(OCS_open), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0, "local", 0, OS_READ_ONLY), OS_ERROR);
}

Expand All @@ -61,7 +61,7 @@ void Test_OS_FileStat_Impl(void)
struct OCS_stat RefStat;

/* failure mode */
UT_SetForceFail(UT_KEY(OCS_stat), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_stat), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local", &FileStats), OS_ERROR);
UT_ClearForceFail(UT_KEY(OCS_stat));

Expand Down Expand Up @@ -97,17 +97,17 @@ void Test_OS_FileChmod_Impl(void)
struct OCS_stat RefStat;

/* failure mode 0 (open) */
UT_SetForceFail(UT_KEY(OCS_open), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR);
UT_ClearForceFail(UT_KEY(OCS_open));

/* failure mode 1 (fstat) */
UT_SetForceFail(UT_KEY(OCS_fstat), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_fstat), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR);
UT_ClearForceFail(UT_KEY(OCS_fstat));

/* failure mode 2 (fchmod) */
UT_SetForceFail(UT_KEY(OCS_fchmod), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_fchmod), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR);
UT_ClearForceFail(UT_KEY(OCS_fchmod));

Expand Down Expand Up @@ -142,7 +142,7 @@ void Test_OS_FileRemove_Impl(void)
OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_SUCCESS);

/* failure mode */
UT_SetForceFail(UT_KEY(OCS_remove), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_remove), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_ERROR);
}

Expand All @@ -155,7 +155,7 @@ void Test_OS_FileRename_Impl(void)
OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old", "new"), OS_SUCCESS);

/* failure mode */
UT_SetForceFail(UT_KEY(OCS_rename), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_rename), -1);
OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old", "new"), OS_ERROR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void Test_OS_GetLocalTime_Impl(void)
timeval.microsecs = 1;
OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_SUCCESS);

UT_SetForceFail(UT_KEY(OCS_clock_gettime), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_clock_gettime), -1);
OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_ERROR);
}

Expand All @@ -55,7 +55,7 @@ void Test_OS_SetLocalTime_Impl(void)
timeval.microsecs = 1;
OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_SUCCESS);

UT_SetForceFail(UT_KEY(OCS_clock_settime), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_clock_settime), -1);
OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_ERROR);
}

Expand Down
14 changes: 7 additions & 7 deletions src/unit-test-coverage/portable/src/coveragetest-posix-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Test_OS_GenericClose_Impl(void)
* Test path where underlying close() fails.
* Should still return success.
*/
UT_SetForceFail(UT_KEY(OCS_close), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_close), -1);
OSAPI_TEST_FUNCTION_RC(OS_GenericClose_Impl, (0), OS_SUCCESS);
}

Expand All @@ -61,18 +61,18 @@ void Test_OS_GenericSeek_Impl(void)
*/

/* note on success this wrapper returns the result of lseek(), not OS_SUCCESS */
UT_SetForceFail(UT_KEY(OCS_lseek), 111);
UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 111);
OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_CUR), 111);
UT_SetForceFail(UT_KEY(OCS_lseek), 222);
UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 222);
OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_SET), 222);
UT_SetForceFail(UT_KEY(OCS_lseek), 333);
UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), 333);
OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_END), 333);

/* bad whence */
OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, -1234), OS_ERROR);

/* generic failure of lseek() */
UT_SetForceFail(UT_KEY(OCS_lseek), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_lseek), -1);
OSAPI_TEST_FUNCTION_RC(OS_GenericSeek_Impl, (0, 0, OS_SEEK_END), OS_ERROR);

/* The seek implementation also checks for this specific pipe errno */
Expand Down Expand Up @@ -102,7 +102,7 @@ void Test_OS_GenericRead_Impl(void)
UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called");

/* read() failure */
UT_SetForceFail(UT_KEY(OCS_read), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_read), -1);
OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl, (0, DestData, sizeof(DestData), 0), OS_ERROR);
}

Expand All @@ -128,7 +128,7 @@ void Test_OS_GenericWrite_Impl(void)
UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called");

/* write() failure */
UT_SetForceFail(UT_KEY(OCS_write), -1);
UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1);
OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl, (0, DestData, sizeof(DestData), 0), OS_ERROR);
}

Expand Down
4 changes: 2 additions & 2 deletions src/unit-test-coverage/shared/src/coveragetest-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Test_OS_BinSemCreate(void)
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);

OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER);
UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
UT_SetDefaultReturnValue(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ void Test_OS_BinSemGetIdByName(void)
int32 actual = ~OS_SUCCESS;
osal_id_t objid;

UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
actual = OS_BinSemGetIdByName(&objid, "UT");
UtAssert_True(actual == expected, "OS_BinSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual);
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
Expand Down
10 changes: 5 additions & 5 deletions src/unit-test-coverage/shared/src/coveragetest-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ void Test_OS_API_Init(void)

/* other error paths */
OS_SharedGlobalVars.Initialized = false;
UT_SetForceFail(UT_KEY(OS_ObjectIdInit), -222);
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdInit), -222);
OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -222);
UT_ResetState(UT_KEY(OS_ObjectIdInit));

OS_SharedGlobalVars.Initialized = false;
UT_SetForceFail(UT_KEY(OS_API_Impl_Init), -333);
UT_SetDefaultReturnValue(UT_KEY(OS_API_Impl_Init), -333);
OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -333);
UT_ResetState(UT_KEY(OS_API_Impl_Init));

OS_SharedGlobalVars.Initialized = false;
UT_SetForceFail(UT_KEY(OS_TaskAPI_Init), -444);
UT_SetDefaultReturnValue(UT_KEY(OS_TaskAPI_Init), -444);
OSAPI_TEST_FUNCTION_RC(OS_API_Init(), -444);
UT_ResetState(UT_KEY(OS_TaskAPI_Init));
}
Expand Down Expand Up @@ -151,7 +151,7 @@ void Test_OS_CleanUpObject(void)
while (objtype < OS_OBJECT_TYPE_USER)
{
UT_ResetState(0);
UT_SetForceFail(UT_KEY(OS_IdentifyObject), objtype);
UT_SetDefaultReturnValue(UT_KEY(OS_IdentifyObject), objtype);

switch (objtype)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ void Test_OS_CleanUpObject(void)
/* note the return code here is ignored -
* the goal is simply to defeat the default
* check that the objid was valid (it isn't) */
UT_SetForceFail(delhandler, OS_ERROR);
UT_SetDefaultReturnValue(delhandler, OS_ERROR);
OS_CleanUpObject(OS_OBJECT_ID_UNDEFINED, &ActualObjs);

CallCount = UT_GetStubCount(delhandler);
Expand Down
4 changes: 2 additions & 2 deletions src/unit-test-coverage/shared/src/coveragetest-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void Test_OS_CountSemCreate(void)
#endif

OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER);
UT_SetForceFail(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
UT_SetDefaultReturnValue(UT_KEY(OCS_strlen), 10 + OS_MAX_API_NAME);
OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG);
}

Expand Down Expand Up @@ -134,7 +134,7 @@ void Test_OS_CountSemGetIdByName(void)
int32 actual = ~OS_SUCCESS;
osal_id_t objid;

UT_SetForceFail(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
actual = OS_CountSemGetIdByName(&objid, "UT");
UtAssert_True(actual == expected, "OS_CountSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual);
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
Expand Down
14 changes: 7 additions & 7 deletions src/unit-test-coverage/shared/src/coveragetest-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Test_OS_OpenCreate(void)
UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_ERROR (bad flags)", (long)actual);

/* Test failure to convert path */
UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
expected = OS_ERROR;
actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE);
UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual);
Expand Down Expand Up @@ -267,19 +267,19 @@ void Test_OS_cp(void)

UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_SUCCESS", (long)actual);

UT_SetForceFail(UT_KEY(OS_GenericRead_Impl), -444);
UT_SetDefaultReturnValue(UT_KEY(OS_GenericRead_Impl), -444);
expected = -444;
actual = OS_cp("/cf/file1", "/cf/file2");
UtAssert_True(actual == expected, "OS_cp() (%ld) == -444", (long)actual);
UT_ClearForceFail(UT_KEY(OS_GenericRead_Impl));

UT_SetDataBuffer(UT_KEY(OS_GenericRead_Impl), ReadBuf, sizeof(ReadBuf), false);
UT_SetForceFail(UT_KEY(OS_GenericWrite_Impl), -555);
UT_SetDefaultReturnValue(UT_KEY(OS_GenericWrite_Impl), -555);
expected = -555;
actual = OS_cp("/cf/file1", "/cf/file2");
UtAssert_True(actual == expected, "OS_cp() (%ld) == -555", (long)actual);

UT_SetForceFail(UT_KEY(OS_TranslatePath), OS_INVALID_POINTER);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_INVALID_POINTER);
expected = OS_INVALID_POINTER;
actual = OS_cp("/cf/file1", "/cf/file2");
UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_INVALID_POINTER", (long)actual);
Expand All @@ -299,7 +299,7 @@ void Test_OS_mv(void)

/* In the default case, the implementation tries to rename first.
* Force rename to fail so it does a full copy and remove */
UT_SetForceFail(UT_KEY(OS_FileRename_Impl), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_FileRename_Impl), OS_ERROR);
actual = OS_mv("/cf/file1", "/cf/file2");
UtAssert_True(actual == expected, "OS_mv() (%ld) == OS_SUCCESS", (long)actual);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ void Test_OS_FileOpenCheck(void)
UtAssert_True(actual == expected, "OS_FileOpenCheck() (%ld) == OS_ERROR", (long)actual);

OS_global_stream_table[0].active_id = UT_OBJID_1;
UT_SetForceFail(UT_KEY(OCS_strcmp), 0);
UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0);
expected = OS_SUCCESS;
actual = OS_FileOpenCheck("/cf/file");

Expand All @@ -369,7 +369,7 @@ void Test_OS_CloseFileByName(void)
/* setup for success */
expected = OS_SUCCESS;
OS_global_stream_table[0].active_id = UT_OBJID_1;
UT_SetForceFail(UT_KEY(OCS_strcmp), 0);
UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0);
actual = OS_CloseFileByName("/cf/file");
UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_SUCCESS", (long)actual);

Expand Down
Loading

0 comments on commit 52ee871

Please sign in to comment.