From d12ab620482e5b97e0ddf9563fae2b721529adfd Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 22 Jun 2021 09:05:02 -0400 Subject: [PATCH] Partial #596, UtAssert macros for FS test Update FS coverage test to use preferred macros. --- modules/fs/ut-coverage/fs_UT.c | 344 +++++++++++++-------------------- 1 file changed, 130 insertions(+), 214 deletions(-) diff --git a/modules/fs/ut-coverage/fs_UT.c b/modules/fs/ut-coverage/fs_UT.c index 6d138926b..dfdd0a753 100644 --- a/modules/fs/ut-coverage/fs_UT.c +++ b/modules/fs/ut-coverage/fs_UT.c @@ -97,7 +97,7 @@ void Test_CFE_FS_InitHeader(void) /* Test initializing the header */ UT_InitData(); CFE_FS_InitHeader(&Hdr, "description", 123); - UT_Report(__FILE__, __LINE__, Hdr.SubType == 123, "CFE_FS_InitHeader", "Initialize header - successful"); + UtAssert_INT32_EQ(Hdr.SubType, 123); } /* @@ -113,15 +113,13 @@ void Test_CFE_FS_ReadHeader(void) /* Test reading the header with a lseek failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_lseek), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_ReadHeader(&Hdr, FileDes) == OS_ERROR, "CFE_FS_ReadHeader", - "Header read lseek failed"); + UtAssert_INT32_EQ(CFE_FS_ReadHeader(&Hdr, FileDes), OS_ERROR); /* Test successfully reading the header */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_lseek), 1, OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OS_read), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_ReadHeader(&Hdr, FileDes) != sizeof(CFE_FS_Header_t), "CFE_FS_ReadHeader", - "Header read - successful"); + UtAssert_INT32_EQ(CFE_FS_ReadHeader(&Hdr, FileDes), OS_ERROR); } /* @@ -137,15 +135,13 @@ void Test_CFE_FS_WriteHeader(void) /* Test writing the header with a lseek failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_lseek), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_WriteHeader(FileDes, &Hdr) == OS_ERROR, "CFE_FS_WriteHeader", - "Header write lseek failed"); + UtAssert_INT32_EQ(CFE_FS_WriteHeader(FileDes, &Hdr), OS_ERROR); /* Test successfully writing the header */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_lseek), 1, OS_SUCCESS); UT_SetDeferredRetcode(UT_KEY(OS_write), 1, OS_SUCCESS); - UT_Report(__FILE__, __LINE__, CFE_FS_WriteHeader(FileDes, &Hdr) == OS_SUCCESS, "CFE_FS_WriteHeader", - "Header write - successful"); + UtAssert_INT32_EQ(CFE_FS_WriteHeader(FileDes, &Hdr), OS_SUCCESS); } /* @@ -161,25 +157,21 @@ void Test_CFE_FS_SetTimestamp(void) /* Test setting the time stamp with a lseek failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_lseek), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_SetTimestamp(FileDes, NewTimestamp) == OS_ERROR, "CFE_FS_SetTimestamp", - "Failed to lseek time fields"); + UtAssert_INT32_EQ(CFE_FS_SetTimestamp(FileDes, NewTimestamp), OS_ERROR); /* Test setting the time stamp with a seconds write failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_write), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_SetTimestamp(FileDes, NewTimestamp) != CFE_SUCCESS, "CFE_FS_SetTimestamp", - "Failed to write seconds"); + UtAssert_INT32_EQ(CFE_FS_SetTimestamp(FileDes, NewTimestamp), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Test setting the time stamp with a subeconds write failure */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_write), 1, 0); - UT_Report(__FILE__, __LINE__, CFE_FS_SetTimestamp(FileDes, NewTimestamp) != CFE_SUCCESS, "CFE_FS_SetTimestamp", - "Failed to write subseconds"); + UtAssert_INT32_EQ(CFE_FS_SetTimestamp(FileDes, NewTimestamp), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Test successfully setting the time stamp */ UT_InitData(); - UT_Report(__FILE__, __LINE__, CFE_FS_SetTimestamp(FileDes, NewTimestamp) == CFE_SUCCESS, "CFE_FS_SetTimestamp", - "Write time stamp - successful"); + CFE_UtAssert_SUCCESS(CFE_FS_SetTimestamp(FileDes, NewTimestamp)); } /* @@ -203,11 +195,15 @@ void Test_CFE_FS_ByteSwapCFEHeader(void) /* Test byte-swapping the header values */ CFE_FS_ByteSwapCFEHeader(&Hdr); - UT_Report(__FILE__, __LINE__, - Hdr.ContentType == 0x44332211 && Hdr.SubType == 0x55443322 && Hdr.Length == 0x66554433 && - Hdr.SpacecraftID == 0x77665544 && Hdr.ProcessorID == 0x88776655 && Hdr.ApplicationID == 0x99887766 && - Hdr.TimeSeconds == 0xaa998877 && Hdr.TimeSubSeconds == 0xbbaa9988, - "CFE_FS_ByteSwapUint32", "Byte swap header - successful"); + + UtAssert_UINT32_EQ(Hdr.ContentType, 0x44332211); + UtAssert_UINT32_EQ(Hdr.SubType, 0x55443322); + UtAssert_UINT32_EQ(Hdr.Length, 0x66554433); + UtAssert_UINT32_EQ(Hdr.SpacecraftID, 0x77665544); + UtAssert_UINT32_EQ(Hdr.ProcessorID, 0x88776655); + UtAssert_UINT32_EQ(Hdr.ApplicationID, 0x99887766); + UtAssert_UINT32_EQ(Hdr.TimeSeconds, 0xaa998877); + UtAssert_UINT32_EQ(Hdr.TimeSubSeconds, 0xbbaa9988); } /* @@ -223,7 +219,7 @@ void Test_CFE_FS_ByteSwapUint32(void) /* Test byte-swapping a uint32 value */ UT_InitData(); CFE_FS_ByteSwapUint32(testptr); - UT_Report(__FILE__, __LINE__, test == 0x44332211, "CFE_FS_ByteSwapUint32", "Byte swap - successful"); + UtAssert_UINT32_EQ(test, 0x44332211); } /* @@ -251,56 +247,49 @@ void Test_CFE_FS_ParseInputFileNameEx(void) /* nominal with fully-qualified input */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_FULLY_QUALIFIED, sizeof(OutBuffer), - sizeof(TEST_INPUT_FULLY_QUALIFIED), TEST_DEFAULT_INPUT, - TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_FULLY_QUALIFIED, sizeof(OutBuffer), + sizeof(TEST_INPUT_FULLY_QUALIFIED), TEST_DEFAULT_INPUT, + TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, TEST_INPUT_FULLY_QUALIFIED, "Fully-qualified pass thru -> %s", OutBuffer); /* Same but as a default input, rather than in the buffer */ - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, NULL, sizeof(OutBuffer), 0, TEST_DEFAULT_INPUT, - TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, NULL, sizeof(OutBuffer), 0, TEST_DEFAULT_INPUT, + TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, TEST_DEFAULT_INPUT, "Fully-qualified pass thru -> %s", OutBuffer); /* nominal with no path input */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_PATH, sizeof(OutBuffer), - sizeof(TEST_INPUT_NO_PATH), TEST_DEFAULT_INPUT, TEST_DEFAULT_PATH, - TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_PATH, sizeof(OutBuffer), + sizeof(TEST_INPUT_NO_PATH), TEST_DEFAULT_INPUT, TEST_DEFAULT_PATH, + TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/dflpath/file.log", "No Path input -> %s", OutBuffer); /* nominal with no path input - should remove duplicate path separators */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_XTRA_SEPARATOR_PATH, sizeof(OutBuffer), - sizeof(TEST_XTRA_SEPARATOR_PATH), TEST_DEFAULT_INPUT, - TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_XTRA_SEPARATOR_PATH, sizeof(OutBuffer), + sizeof(TEST_XTRA_SEPARATOR_PATH), TEST_DEFAULT_INPUT, + TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/xtra/sep/file.log", "No Path input, extra separators -> %s", OutBuffer); /* nominal with no extension input */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), - sizeof(TEST_INPUT_NO_EXTENSION), TEST_DEFAULT_INPUT, - TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), + sizeof(TEST_INPUT_NO_EXTENSION), TEST_DEFAULT_INPUT, + TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/path/to/file.dflext", "No Extension input -> %s", OutBuffer); /* nominal with no extension input, no separator (should be added) */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), - sizeof(TEST_INPUT_NO_EXTENSION), TEST_DEFAULT_INPUT, - TEST_DEFAULT_PATH, TEST_NO_SEPARATOR), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), + sizeof(TEST_INPUT_NO_EXTENSION), TEST_DEFAULT_INPUT, + TEST_DEFAULT_PATH, TEST_NO_SEPARATOR)); UtAssert_StrCmp(OutBuffer, "/path/to/file.nosep", "No Extension input, no separator -> %s", OutBuffer); /* nominal with neither path nor extension input */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), - sizeof(TEST_INPUT_BASENAME), TEST_DEFAULT_INPUT, TEST_DEFAULT_PATH, - TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), + sizeof(TEST_INPUT_BASENAME), TEST_DEFAULT_INPUT, TEST_DEFAULT_PATH, + TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/dflpath/file.dflext", "No Path nor Extension input -> %s", OutBuffer); /* Bad arguments for buffer pointer/size */ @@ -326,21 +315,18 @@ void Test_CFE_FS_ParseInputFileNameEx(void) /* if the default path/extension is null it is just ignored, not an error. */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), - sizeof(TEST_INPUT_BASENAME), NULL, NULL, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), + sizeof(TEST_INPUT_BASENAME), NULL, NULL, TEST_DEFAULT_EXTENSION)); /* If no path this still adds a leading / */ UtAssert_StrCmp(OutBuffer, "/file.dflext", "No Path nor default -> %s", OutBuffer); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), - sizeof(TEST_INPUT_BASENAME), NULL, TEST_DEFAULT_PATH, NULL), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_BASENAME, sizeof(OutBuffer), + sizeof(TEST_INPUT_BASENAME), NULL, TEST_DEFAULT_PATH, NULL)); UtAssert_StrCmp(OutBuffer, "/dflpath/file", "No Extension nor default -> %s", OutBuffer); /* test corner case for termination where result fits exactly, including NUL (should work) */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_PATH, 18, sizeof(TEST_INPUT_NO_PATH), NULL, - TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, TEST_INPUT_NO_PATH, 18, sizeof(TEST_INPUT_NO_PATH), + NULL, TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/dflpath/file.log", "Exact Length input -> %s", OutBuffer); UtAssert_INT32_EQ(OutBuffer[18], 0x7F); /* Confirm character after buffer was not touched */ @@ -362,16 +348,14 @@ void Test_CFE_FS_ParseInputFileNameEx(void) /* test case for where input is not terminated */ /* only the specified number of chars should be used from input */ memset(OutBuffer, 0x7F, sizeof(OutBuffer)); - UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutBuffer, "abcdefgh", sizeof(OutBuffer), 4, NULL, TEST_DEFAULT_PATH, - TEST_DEFAULT_EXTENSION), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS(CFE_FS_ParseInputFileNameEx(OutBuffer, "abcdefgh", sizeof(OutBuffer), 4, NULL, + TEST_DEFAULT_PATH, TEST_DEFAULT_EXTENSION)); UtAssert_StrCmp(OutBuffer, "/dflpath/abcd.dflext", "Non terminated input -> %s", OutBuffer); /* For coverage, also invoke the simplified CFE_FS_ParseInputFileName() */ /* no more error paths here, as all real logic is in CFE_FS_ParseInputFileNameEx() */ - UtAssert_INT32_EQ( - CFE_FS_ParseInputFileName(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), CFE_FS_FileCategory_TEXT_LOG), - CFE_SUCCESS); + CFE_UtAssert_SUCCESS( + CFE_FS_ParseInputFileName(OutBuffer, TEST_INPUT_NO_EXTENSION, sizeof(OutBuffer), CFE_FS_FileCategory_TEXT_LOG)); UtAssert_StrCmp(OutBuffer, "/path/to/file.log", "Simplified API -> %s", OutBuffer); } @@ -390,55 +374,26 @@ void Test_CFE_FS_DefaultFileStrings(void) * that the returned pointer address, not the actual string content. */ - const char *Result; - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_UNKNOWN); - UtAssert_NULL(Result); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_DYNAMIC_MODULE); - UtAssert_True(Result == GLOBAL_CONFIGDATA.Default_ModuleExtension, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CONFIGDATA.Default_ModuleExtension); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP); - UtAssert_NOT_NULL(Result); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_TEXT_LOG); - UtAssert_NOT_NULL(Result); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_SCRIPT); - UtAssert_NOT_NULL(Result); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_TEMP); - UtAssert_NOT_NULL(Result); - - Result = CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_MAX); - UtAssert_NULL(Result); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_UNKNOWN); - UtAssert_NULL(Result); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_DYNAMIC_MODULE); - UtAssert_True(Result == GLOBAL_CFE_CONFIGDATA.NonvolMountPoint, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CFE_CONFIGDATA.NonvolMountPoint); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP); - UtAssert_True(Result == GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_TEXT_LOG); - UtAssert_True(Result == GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_SCRIPT); - UtAssert_True(Result == GLOBAL_CFE_CONFIGDATA.NonvolMountPoint, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CFE_CONFIGDATA.NonvolMountPoint); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_TEMP); - UtAssert_True(Result == GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint, "Result (%lx) matches config (%lx)", - (unsigned long)Result, (unsigned long)GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); - - Result = CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_MAX); - UtAssert_NULL(Result); + UtAssert_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_UNKNOWN)); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_DYNAMIC_MODULE), + GLOBAL_CONFIGDATA.Default_ModuleExtension); + UtAssert_NOT_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_BINARY_DATA_DUMP)); + UtAssert_NOT_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_TEXT_LOG)); + UtAssert_NOT_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_SCRIPT)); + UtAssert_NOT_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_TEMP)); + UtAssert_NULL(CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_MAX)); + + UtAssert_NULL(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_UNKNOWN)); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_DYNAMIC_MODULE), + GLOBAL_CFE_CONFIGDATA.NonvolMountPoint); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_BINARY_DATA_DUMP), + GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_TEXT_LOG), + GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_SCRIPT), + GLOBAL_CFE_CONFIGDATA.NonvolMountPoint); + UtAssert_ADDRESS_EQ(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_TEMP), GLOBAL_CFE_CONFIGDATA.RamdiskMountPoint); + UtAssert_NULL(CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_MAX)); } /* @@ -459,13 +414,11 @@ void Test_CFE_FS_ExtractFileNameFromPath(void) UT_InitData(); strncpy(Original, "/cf/appslibrary.gz", sizeof(Original) - 1); Original[sizeof(Original) - 1] = '\0'; - UT_Report(__FILE__, __LINE__, CFE_FS_ExtractFilenameFromPath("name", FileName) == CFE_FS_INVALID_PATH, - "CFE_FS_ExtractFilenameFromPath", "Missing file path"); + UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath("name", FileName), CFE_FS_INVALID_PATH); /* Test extracting the file name from a path that's null */ UT_InitData(); - UT_Report(__FILE__, __LINE__, CFE_FS_ExtractFilenameFromPath(NULL, FileName) == CFE_FS_BAD_ARGUMENT, - "CFE_FS_ExtractFilenameFromPath", "Null name"); + UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(NULL, FileName), CFE_FS_BAD_ARGUMENT); /* Test extracting the file name from a path/file name that's too long */ UT_InitData(); @@ -478,18 +431,15 @@ void Test_CFE_FS_ExtractFileNameFromPath(void) strcat(LongFileName, ".gz"); - UT_Report(__FILE__, __LINE__, CFE_FS_ExtractFilenameFromPath(LongFileName, FileName) == CFE_FS_FNAME_TOO_LONG, - "CFE_FS_ExtractFilenameFromPath", "Path/file name too long"); + UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(LongFileName, FileName), CFE_FS_FNAME_TOO_LONG); /* Test successfully extracting the file name from a path/file name */ UT_InitData(); - UT_Report(__FILE__, __LINE__, CFE_FS_ExtractFilenameFromPath(Original, FileName) == CFE_SUCCESS, - "CFE_FS_ExtractFilenameFromPath", "Extract path name - successful"); + CFE_UtAssert_SUCCESS(CFE_FS_ExtractFilenameFromPath(Original, FileName)); /* Test extracting the file name from a file name that's null */ UT_InitData(); - UT_Report(__FILE__, __LINE__, CFE_FS_ExtractFilenameFromPath(Original, NULL) == CFE_FS_BAD_ARGUMENT, - "CFE_FS_ExtractFilenameFromPath", "Null file name"); + UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Original, NULL), CFE_FS_BAD_ARGUMENT); } /* @@ -501,41 +451,36 @@ void Test_CFE_FS_Private(void) /* Test successful FS initialization */ UT_InitData(); - UT_Report(__FILE__, __LINE__, CFE_FS_EarlyInit() == CFE_SUCCESS, "CFE_FS_EarlyInit", - "FS initialization - successful"); + CFE_UtAssert_SUCCESS(CFE_FS_EarlyInit()); /* Test FS initialization with a mutex creation failure */ UT_InitData(); UT_SetDefaultReturnValue(UT_KEY(OS_MutSemCreate), OS_ERROR); - UT_Report(__FILE__, __LINE__, CFE_FS_EarlyInit() == -1, "CFE_FS_EarlyInit", "Mutex creation failure"); + UtAssert_INT32_EQ(CFE_FS_EarlyInit(), OS_ERROR); /* Test successful locking of shared data */ UT_InitData(); CFE_FS_LockSharedData("FunctionName"); - UT_Report(__FILE__, __LINE__, UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 0, "CFE_FS_LockSharedData", - "Lock shared data - successful"); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 0); /* Test locking of shared data with a mutex take error */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_MutSemTake), 1, -1); CFE_FS_LockSharedData("FunctionName"); - UT_Report(__FILE__, __LINE__, - UT_SyslogIsInHistory(FS_SYSLOG_MSGS[1]) && UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, - "CFE_FS_LockSharedData", "Shared data mutex take error"); + CFE_UtAssert_SYSLOG(FS_SYSLOG_MSGS[1]); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); /* Test successful unlocking of shared data */ UT_InitData(); CFE_FS_UnlockSharedData("FunctionName"); - UT_Report(__FILE__, __LINE__, UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 0, "CFE_FS_UnlockSharedData", - "Unlock shared data - successful"); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 0); /* Test unlocking of shared data with a mutex give error */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_MutSemGive), 1, -1); CFE_FS_UnlockSharedData("FunctionName"); - UT_Report(__FILE__, __LINE__, - UT_SyslogIsInHistory(FS_SYSLOG_MSGS[2]) && UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, - "CFE_FS_UnlockSharedData", "SharedData mutex give error"); + CFE_UtAssert_SYSLOG(FS_SYSLOG_MSGS[2]); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); UtPrintf("End Test Private\n"); } @@ -548,52 +493,39 @@ void Test_CFE_FS_BackgroundFileDump(void) */ CFE_FS_FileWriteMetaData_t State; uint32 MyBuffer[2]; - int32 Status; + uint32 i; memset(UT_FS_FileWriteEventCount, 0, sizeof(UT_FS_FileWriteEventCount)); memset(&State, 0, sizeof(State)); memset(&CFE_FS_Global.FileDump, 0, sizeof(CFE_FS_Global.FileDump)); /* Nominal with nothing pending - should accumulate credit */ - UtAssert_True(!CFE_FS_RunBackgroundFileDump(1, NULL), - "CFE_FS_RunBackgroundFileDump() nothing pending, short delay"); - UtAssert_True(CFE_FS_Global.FileDump.Current.Credit > 0, "Credit accumulating (%lu)", - (unsigned long)CFE_FS_Global.FileDump.Current.Credit); - UtAssert_True(CFE_FS_Global.FileDump.Current.Credit < CFE_FS_BACKGROUND_MAX_CREDIT, "Credit not max (%lu)", - (unsigned long)CFE_FS_Global.FileDump.Current.Credit); - - UtAssert_True(!CFE_FS_RunBackgroundFileDump(100000, NULL), - "CFE_FS_RunBackgroundFileDump() nothing pending, long delay"); - UtAssert_True(CFE_FS_Global.FileDump.Current.Credit == CFE_FS_BACKGROUND_MAX_CREDIT, "Credit at max (%lu)", - (unsigned long)CFE_FS_Global.FileDump.Current.Credit); - - Status = CFE_FS_BackgroundFileDumpRequest(NULL); - UtAssert_True(Status == CFE_FS_BAD_ARGUMENT, "CFE_FS_BackgroundFileDumpRequest(NULL) (%lu) == CFE_FS_BAD_ARGUMENT", - (unsigned long)Status); - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_FS_BAD_ARGUMENT, - "CFE_FS_BackgroundFileDumpRequest(&State) (%lu) == CFE_FS_BAD_ARGUMENT", (unsigned long)Status); - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); + CFE_UtAssert_FALSE(CFE_FS_RunBackgroundFileDump(1, NULL)); + CFE_UtAssert_ATLEAST(CFE_FS_Global.FileDump.Current.Credit, 1); + CFE_UtAssert_ATMOST(CFE_FS_Global.FileDump.Current.Credit, CFE_FS_BACKGROUND_MAX_CREDIT); + + CFE_UtAssert_FALSE(CFE_FS_RunBackgroundFileDump(100000, NULL)); + UtAssert_INT32_EQ(CFE_FS_Global.FileDump.Current.Credit, CFE_FS_BACKGROUND_MAX_CREDIT); + + UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(NULL), CFE_FS_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&State), CFE_FS_BAD_ARGUMENT); + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); UtAssert_STUB_COUNT(CFE_ES_BackgroundWakeup, 0); /* confirm CFE_ES_BackgroundWakeup() was not invoked */ /* Set the data except file name and description */ State.FileSubType = 2; State.GetData = UT_FS_DataGetter; State.OnEvent = UT_FS_OnEvent; - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_FS_INVALID_PATH, - "CFE_FS_BackgroundFileDumpRequest(&State) (%lu) == CFE_FS_INVALID_PATH", (unsigned long)Status); - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); + UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&State), CFE_FS_INVALID_PATH); + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); UtAssert_STUB_COUNT(CFE_ES_BackgroundWakeup, 0); /* confirm CFE_ES_BackgroundWakeup() was not invoked */ /* Set up remainder of fields, so entry is valid */ strncpy(State.FileName, "/ram/UT.bin", sizeof(State.FileName)); strncpy(State.Description, "UT", sizeof(State.Description)); - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_SUCCESS, "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_SUCCESS", - (unsigned long)Status); - UtAssert_True(CFE_FS_BackgroundFileDumpIsPending(&State), "CFE_FS_BackgroundFileDumpIsPending(&State)"); + CFE_UtAssert_SUCCESS(CFE_FS_BackgroundFileDumpRequest(&State)); + CFE_UtAssert_TRUE(CFE_FS_BackgroundFileDumpIsPending(&State)); UtAssert_STUB_COUNT(CFE_ES_BackgroundWakeup, 1); /* confirm CFE_ES_BackgroundWakeup() was invoked */ /* @@ -603,88 +535,72 @@ void Test_CFE_FS_BackgroundFileDump(void) MyBuffer[0] = 10; MyBuffer[1] = 20; UT_SetDataBuffer(UT_KEY(UT_FS_DataGetter), MyBuffer, sizeof(MyBuffer), false); - UtAssert_True(CFE_FS_RunBackgroundFileDump(1, NULL), "CFE_FS_RunBackgroundFileDump() request pending nominal"); + CFE_UtAssert_TRUE(CFE_FS_RunBackgroundFileDump(1, NULL)); UtAssert_STUB_COUNT(OS_OpenCreate, 1); /* confirm OS_open() was invoked */ - UtAssert_True(CFE_FS_Global.FileDump.Current.Credit <= 0, "Credit exhausted (%lu)", - (unsigned long)CFE_FS_Global.FileDump.Current.Credit); + CFE_UtAssert_ATMOST(CFE_FS_Global.FileDump.Current.Credit, 0); UtAssert_STUB_COUNT(OS_close, 0); /* confirm OS_close() was not invoked */ UT_SetDeferredRetcode(UT_KEY(UT_FS_DataGetter), 2, true); /* return EOF */ - UtAssert_True(!CFE_FS_RunBackgroundFileDump(100, NULL), "CFE_FS_RunBackgroundFileDump() request pending EOF"); + CFE_UtAssert_FALSE(CFE_FS_RunBackgroundFileDump(100, NULL)); UtAssert_STUB_COUNT(OS_OpenCreate, 1); /* confirm OS_open() was not invoked again */ UtAssert_STUB_COUNT(OS_close, 1); /* confirm OS_close() was invoked */ - UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, - CFE_FS_Global.FileDump.RequestCount); /* request was completed */ - UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_COMPLETE], 1); /* complete event was sent */ - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); + /* No more pending requests */ + UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, CFE_FS_Global.FileDump.RequestCount); + /* complete event was sent */ + UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_COMPLETE], 1); + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); UT_ResetState(UT_KEY(UT_FS_DataGetter)); /* Error opening file */ - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_SUCCESS, "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_SUCCESS", - (unsigned long)Status); + CFE_UtAssert_SETUP(CFE_FS_BackgroundFileDumpRequest(&State)); UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, OS_ERROR); - UtAssert_True(CFE_FS_RunBackgroundFileDump(100, NULL), - "CFE_FS_RunBackgroundFileDump() request pending, file open error"); + CFE_UtAssert_TRUE(CFE_FS_RunBackgroundFileDump(100, NULL)); UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_CREATE_ERROR], 1); /* create error event was sent */ - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); - UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, - CFE_FS_Global.FileDump.RequestCount); /* request was completed */ + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); + /* No more pending requests */ + UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, CFE_FS_Global.FileDump.RequestCount); /* Error writing header */ - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_SUCCESS, "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_SUCCESS", - (unsigned long)Status); + CFE_UtAssert_SETUP(CFE_FS_BackgroundFileDumpRequest(&State)); UT_SetDeferredRetcode(UT_KEY(OS_write), 1, OS_ERROR); - UtAssert_True(CFE_FS_RunBackgroundFileDump(100, NULL), - "CFE_FS_RunBackgroundFileDump() request pending, file write header error"); + CFE_UtAssert_TRUE(CFE_FS_RunBackgroundFileDump(100, NULL)); UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_HEADER_WRITE_ERROR], 1); /* header error event was sent */ - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); - UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, - CFE_FS_Global.FileDump.RequestCount); /* request was completed */ + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); + /* No more pending requests */ + UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, CFE_FS_Global.FileDump.RequestCount); /* Error writing data */ - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_SUCCESS, "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_SUCCESS", - (unsigned long)Status); + CFE_UtAssert_SETUP(CFE_FS_BackgroundFileDumpRequest(&State)); UT_SetDeferredRetcode(UT_KEY(OS_write), 2, OS_ERROR); UT_SetDataBuffer(UT_KEY(UT_FS_DataGetter), MyBuffer, sizeof(MyBuffer), false); - UtAssert_True(CFE_FS_RunBackgroundFileDump(100, NULL), - "CFE_FS_RunBackgroundFileDump() request pending, file write data error"); - UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_RECORD_WRITE_ERROR], - 1); /* record error event was sent */ - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(&State), "!CFE_FS_BackgroundFileDumpIsPending(&State)"); - UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, - CFE_FS_Global.FileDump.RequestCount); /* request was completed */ + CFE_UtAssert_TRUE(CFE_FS_RunBackgroundFileDump(100, NULL)); + /* record error event was sent */ + UtAssert_UINT32_EQ(UT_FS_FileWriteEventCount[CFE_FS_FileWriteEvent_RECORD_WRITE_ERROR], 1); + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(&State)); + /* No more pending requests */ + UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.CompleteCount, CFE_FS_Global.FileDump.RequestCount); UT_ResetState(UT_KEY(UT_FS_DataGetter)); /* Request multiple file dumps, check queing logic */ - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_SUCCESS, "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_SUCCESS", - (unsigned long)Status); - Status = CFE_FS_BackgroundFileDumpRequest(&State); - UtAssert_True(Status == CFE_STATUS_REQUEST_ALREADY_PENDING, - "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_STATUS_REQUEST_ALREADY_PENDING", - (unsigned long)Status); - - do + CFE_UtAssert_SETUP(CFE_FS_BackgroundFileDumpRequest(&State)); + UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&State), CFE_STATUS_REQUEST_ALREADY_PENDING); + + for (i = 0; i < (CFE_FS_MAX_BACKGROUND_FILE_WRITES - 2); ++i) { State.IsPending = false; /* UT hack to fill queue - Force not pending. Real code should not do this. */ - Status = CFE_FS_BackgroundFileDumpRequest(&State); - } while (Status == CFE_SUCCESS); + CFE_UtAssert_SETUP(CFE_FS_BackgroundFileDumpRequest(&State)); + } - UtAssert_True(Status == CFE_STATUS_REQUEST_ALREADY_PENDING, - "CFE_FS_BackgroundFileDumpRequest() (%lu) == CFE_STATUS_REQUEST_ALREADY_PENDING", - (unsigned long)Status); + UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&State), CFE_STATUS_REQUEST_ALREADY_PENDING); UtAssert_UINT32_EQ(CFE_FS_Global.FileDump.RequestCount, (CFE_FS_Global.FileDump.CompleteCount + CFE_FS_MAX_BACKGROUND_FILE_WRITES - 1)); /* Confirm null arg handling in CFE_FS_BackgroundFileDumpIsPending() */ - UtAssert_True(!CFE_FS_BackgroundFileDumpIsPending(NULL), "!CFE_FS_BackgroundFileDumpIsPending(NULL)"); + CFE_UtAssert_FALSE(CFE_FS_BackgroundFileDumpIsPending(NULL)); }