From d506c2cc0184989140bacbb13943ae91ee6e1249 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 21 Jul 2022 12:14:23 -0400 Subject: [PATCH] Fix #27, Add library support to application checksum computing function. --- fsw/src/cs_compute.c | 31 +++++----- unit-test/cs_compute_tests.c | 107 ++++++++++++++++++++++++++++------- 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/fsw/src/cs_compute.c b/fsw/src/cs_compute.c index d0917dc..9f3b0be 100644 --- a/fsw/src/cs_compute.c +++ b/fsw/src/cs_compute.c @@ -316,12 +316,12 @@ int32 CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *ComputedCSVa uint32 NewChecksumValue = 0; int32 Status = CS_SUCCESS; int32 Result; - int32 ResultGetAppID = CS_ERROR; - int32 ResultGetAppInfo = CS_ERROR; + int32 ResultGetResourceID = CS_ERROR; + int32 ResultGetResourceInfo = CS_ERROR; int32 ResultAddressValid = false; /* variables to get applications address */ - CFE_ES_AppId_t AppID = CFE_ES_APPID_UNDEFINED; + CFE_ES_ResourceId_t ResourceID = CFE_ES_APPID_UNDEFINED; CFE_ES_AppInfo_t AppInfo; /* By the time we get here, we know we have an enabled entry */ @@ -329,20 +329,25 @@ int32 CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *ComputedCSVa /* set the done flag to false originally */ *DoneWithEntry = false; - ResultGetAppID = CFE_ES_GetAppIDByName(&AppID, ResultsEntry->Name); - Result = ResultGetAppID; + ResultGetResourceID = CFE_ES_GetAppIDByName(&ResourceID, ResultsEntry->Name); + if (ResultGetResourceID == CFE_ES_ERR_NAME_NOT_FOUND) + { + /* Also check for a matching library name */ + ResultGetResourceID = CFE_ES_GetLibIDByName(&ResourceID, ResultsEntry->Name); + } + Result = ResultGetResourceID; if (Result == CFE_SUCCESS) { - /* We got a valid AppID, so get the App info */ + /* We got a valid ResourceID, so get the Resource info */ - ResultGetAppInfo = CFE_ES_GetAppInfo(&AppInfo, AppID); - Result = ResultGetAppInfo; + ResultGetResourceInfo = CFE_ES_GetModuleInfo(&AppInfo, ResourceID); + Result = ResultGetResourceInfo; } if (Result == CFE_SUCCESS) { - /* We got a valid AppID and good App info, so check the for valid addresses */ + /* We got a valid ResourceID and good App info, so check the for valid addresses */ if (AppInfo.AddressesAreValid == false) { @@ -363,7 +368,7 @@ int32 CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *ComputedCSVa if (Result == CFE_SUCCESS) { - /* We got valid AppID, good info, and valid addresses, so run the checksum */ + /* We got valid ResourceID, good info, and valid addresses, so run the checksum */ OffsetIntoCurrEntry = ResultsEntry->ByteOffset; FirstAddrThisCycle = ResultsEntry->StartAddress + OffsetIntoCurrEntry; @@ -417,11 +422,11 @@ int32 CS_ComputeApp(CS_Res_App_Table_Entry_t *ResultsEntry, uint32 *ComputedCSVa } /* end if got module id ok */ else { - /* Something failed -- either invalid AppID, bad App info, or invalid addresses, so notify ground */ + /* Something failed -- either invalid ResourceID, bad App info, or invalid addresses, so notify ground */ CFE_EVS_SendEvent( CS_COMPUTE_APP_ERR_EID, CFE_EVS_EventType_ERROR, - "CS Apps: Problems getting app %s info, GetAppID: 0x%08X, GetAppInfo: 0x%08X, AddressValid: %d", - ResultsEntry->Name, (unsigned int)ResultGetAppID, (unsigned int)ResultGetAppInfo, + "CS Apps: Problems getting module %s info, GetResourceID: 0x%08X, GetModuleInfo: 0x%08X, AddressValid: %d", + ResultsEntry->Name, (unsigned int)ResultGetResourceID, (unsigned int)ResultGetResourceInfo, (unsigned int)ResultAddressValid); Status = CS_ERR_NOT_FOUND; diff --git a/unit-test/cs_compute_tests.c b/unit-test/cs_compute_tests.c index 60e898e..ab3333d 100644 --- a/unit-test/cs_compute_tests.c +++ b/unit-test/cs_compute_tests.c @@ -69,6 +69,22 @@ void CS_COMPUTE_TEST_CFE_TBL_ShareHandler(void *UserObj, UT_EntryKey_t FuncKey, *TblHandlePtr = 99; } +void CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + CFE_ES_AppInfo_t *AppInfo = (CFE_ES_AppInfo_t *)UT_Hook_GetArgValueByName(Context, "AppInfo", CFE_ES_AppInfo_t *); + + AppInfo->CodeSize = 5; + AppInfo->CodeAddress = 1; + AppInfo->AddressesAreValid = true; +} + +void CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler2(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + CFE_ES_AppInfo_t *AppInfo = (CFE_ES_AppInfo_t *)UT_Hook_GetArgValueByName(Context, "AppInfo", CFE_ES_AppInfo_t *); + + AppInfo->AddressesAreValid = false; +} + void CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler1(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { CFE_ES_AppInfo_t *AppInfo = (CFE_ES_AppInfo_t *)UT_Hook_GetArgValueByName(Context, "AppInfo", CFE_ES_AppInfo_t *); @@ -824,7 +840,7 @@ void CS_ComputeTables_Test_ComputeTablesError(void) } /* end CS_ComputeTables_Test_ComputeTablesError */ -void CS_ComputeApp_Test_Nominal(void) +void CS_ComputeApp_Test_NominalApp(void) { int32 Result; CS_Res_App_Table_Entry_t ResultsEntry; @@ -841,7 +857,54 @@ void CS_ComputeApp_Test_Nominal(void) /* Sets AppInfo.CodeSize = 5, sets AppInfo.CodeAddress = 1, AppInfo.AddressesAreValid = true, and returns * CFE_SUCCESS */ - UT_SetHandlerFunction(UT_KEY(CFE_ES_GetAppInfo), CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler1, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1, NULL); + + /* Set to fail condition "NewChecksumValue != ResultsEntry -> ComparisonValue" */ + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CalculateCRC), 1, 2); + + /* Execute the function being tested */ + Result = CS_ComputeApp(&ResultsEntry, &ComputedCSValue, &DoneWithEntry); + + /* Verify results */ + UtAssert_True(DoneWithEntry == true, "DoneWithEntry == true"); + + UtAssert_True(ResultsEntry.NumBytesToChecksum == 5, "ResultsEntry.NumBytesToChecksum == 5"); + UtAssert_True(ResultsEntry.StartAddress == 1, "ResultsEntry.StartAddress == 1"); + + UtAssert_True(ComputedCSValue == 2, "ComputedCSValue == 2"); + UtAssert_True(ResultsEntry.ByteOffset == 0, "ResultsEntry.ByteOffset == 0"); + UtAssert_True(ResultsEntry.TempChecksumValue == 0, "ResultsEntry.TempChecksumValue == 0"); + + UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); + + call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + + UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", + call_count_CFE_EVS_SendEvent); + +} /* end CS_ComputeApp_Test_NominalApp */ + +void CS_ComputeApp_Test_NominalLib(void) +{ + int32 Result; + CS_Res_App_Table_Entry_t ResultsEntry; + uint32 ComputedCSValue = 0; + bool DoneWithEntry = false; + + memset(&ResultsEntry, 0, sizeof(ResultsEntry)); + + CS_AppData.MaxBytesPerCycle = 5; + + ResultsEntry.ComputedYet = true; + + ResultsEntry.ComparisonValue = 2; + + /* Set to generate error CS_COMPUTE_APP_ERR_EID */ + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppIDByName), 1, -1); + + /* Sets AppInfo.CodeSize = 5, sets AppInfo.CodeAddress = 1, AppInfo.AddressesAreValid = true, and returns + * CFE_SUCCESS */ + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1, NULL); /* Set to fail condition "NewChecksumValue != ResultsEntry -> ComparisonValue" */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_CalculateCRC), 1, 2); @@ -866,9 +929,9 @@ void CS_ComputeApp_Test_Nominal(void) UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", call_count_CFE_EVS_SendEvent); -} /* end CS_ComputeApp_Test_Nominal */ +} /* end CS_ComputeApp_Test_NominalLib */ -void CS_ComputeApp_Test_GetAppIDByNameError(void) +void CS_ComputeApp_Test_GetAppAndLibIDByNameError(void) { int32 Result; CS_Res_App_Table_Entry_t ResultsEntry; @@ -880,13 +943,16 @@ void CS_ComputeApp_Test_GetAppIDByNameError(void) memset(&ResultsEntry, 0, sizeof(ResultsEntry)); snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "CS Apps: Problems getting app %%s info, GetAppID: 0x%%08X, GetAppInfo: 0x%%08X, AddressValid: %%d"); + "CS Apps: Problems getting module %%s info, GetAppID: 0x%%08X, GetModuleInfo: 0x%%08X, AddressValid: %%d"); strncpy(ResultsEntry.Name, "name", 10); /* Set to generate error CS_COMPUTE_APP_ERR_EID */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppIDByName), 1, -1); + /* Set to generate error CS_COMPUTE_APP_ERR_EID */ + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetLibIDByName), 1, -1); + /* Execute the function being tested */ Result = CS_ComputeApp(&ResultsEntry, &ComputedCSValue, &DoneWithEntry); @@ -907,9 +973,9 @@ void CS_ComputeApp_Test_GetAppIDByNameError(void) UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", call_count_CFE_EVS_SendEvent); -} /* end CS_ComputeApp_Test_GetAppIDByNameError */ +} /* end CS_ComputeApp_Test_GetAppAndLibIDByNameError */ -void CS_ComputeApp_Test_GetAppInfoError(void) +void CS_ComputeApp_Test_GetModuleInfoError(void) { int32 Result; CS_Res_App_Table_Entry_t ResultsEntry; @@ -921,12 +987,12 @@ void CS_ComputeApp_Test_GetAppInfoError(void) memset(&ResultsEntry, 0, sizeof(ResultsEntry)); snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "CS Apps: Problems getting app %%s info, GetAppID: 0x%%08X, GetAppInfo: 0x%%08X, AddressValid: %%d"); + "CS Apps: Problems getting module %%s info, GetAppID: 0x%%08X, GetModuleInfo: 0x%%08X, AddressValid: %%d"); strncpy(ResultsEntry.Name, "name", 10); /* Set to generate error CS_COMPUTE_APP_ERR_EID */ - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppInfo), 1, -1); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetModuleInfo), 1, -1); /* Execute the function being tested */ Result = CS_ComputeApp(&ResultsEntry, &ComputedCSValue, &DoneWithEntry); @@ -948,7 +1014,7 @@ void CS_ComputeApp_Test_GetAppInfoError(void) UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", call_count_CFE_EVS_SendEvent); -} /* end CS_ComputeApp_Test_GetAppInfoError */ +} /* end CS_ComputeApp_Test_GetModuleInfoError */ void CS_ComputeApp_Test_ComputeAppPlatformError(void) { @@ -965,12 +1031,12 @@ void CS_ComputeApp_Test_ComputeAppPlatformError(void) "CS cannot get a valid address for %%s, due to the platform"); snprintf(ExpectedEventString[1], CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "CS Apps: Problems getting app %%s info, GetAppID: 0x%%08X, GetAppInfo: 0x%%08X, AddressValid: %%d"); + "CS Apps: Problems getting module %%s info, GetAppID: 0x%%08X, GetModuleInfo: 0x%%08X, AddressValid: %%d"); strncpy(ResultsEntry.Name, "name", 10); /* Sets AppInfo.AddressesAreValid = false and returns CFE_SUCCESS */ - UT_SetHandlerFunction(UT_KEY(CFE_ES_GetAppInfo), CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler2, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler2, NULL); /* Execute the function being tested */ Result = CS_ComputeApp(&ResultsEntry, &ComputedCSValue, &DoneWithEntry); @@ -1020,7 +1086,7 @@ void CS_ComputeApp_Test_DifferFromSavedValue(void) /* Sets AppInfo.CodeSize = 5, sets AppInfo.CodeAddress = 1, AppInfo.AddressesAreValid = true, and returns * CFE_SUCCESS */ - UT_SetHandlerFunction(UT_KEY(CFE_ES_GetAppInfo), CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler1, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1, NULL); /* Set to fail condition "NewChecksumValue != ResultsEntry -> ComparisonValue" */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_CalculateCRC), 1, 2); @@ -1060,7 +1126,7 @@ void CS_ComputeApp_Test_FirstTimeThrough(void) /* Sets AppInfo.CodeSize = 5, sets AppInfo.CodeAddress = 1, AppInfo.AddressesAreValid = true, and returns * CFE_SUCCESS */ - UT_SetHandlerFunction(UT_KEY(CFE_ES_GetAppInfo), CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler1, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1, NULL); /* Set to fail condition "NewChecksumValue != ResultsEntry -> ComparisonValue" */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_CalculateCRC), 1, 2); @@ -1109,7 +1175,7 @@ void CS_ComputeApp_Test_EntryNotFinished(void) /* Sets AppInfo.CodeSize = 5, sets AppInfo.CodeAddress = 1, AppInfo.AddressesAreValid = true, and returns * CFE_SUCCESS */ - UT_SetHandlerFunction(UT_KEY(CFE_ES_GetAppInfo), CS_COMPUTE_TEST_CFE_ES_GetAppInfoHandler1, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_ES_GetModuleInfo), CS_COMPUTE_TEST_CFE_ES_GetModuleInfoHandler1, NULL); TblInfo.Size = 5; @@ -2061,11 +2127,12 @@ void UtTest_Setup(void) UtTest_Add(CS_ComputeTables_Test_ComputeTablesError, CS_Test_Setup, CS_Test_TearDown, "CS_ComputeTables_Test_ComputeTablesError"); - UtTest_Add(CS_ComputeApp_Test_Nominal, CS_Test_Setup, CS_Test_TearDown, "CS_ComputeApp_Test_Nominal"); - UtTest_Add(CS_ComputeApp_Test_GetAppIDByNameError, CS_Test_Setup, CS_Test_TearDown, - "CS_ComputeApp_Test_GetAppIDByNameError"); - UtTest_Add(CS_ComputeApp_Test_GetAppInfoError, CS_Test_Setup, CS_Test_TearDown, - "CS_ComputeApp_Test_GetAppInfoError"); + UtTest_Add(CS_ComputeApp_Test_NominalApp, CS_Test_Setup, CS_Test_TearDown, "CS_ComputeApp_Test_NominalApp"); + UtTest_Add(CS_ComputeApp_Test_NominalLib, CS_Test_Setup, CS_Test_TearDown, "CS_ComputeApp_Test_NominalLib"); + UtTest_Add(CS_ComputeApp_Test_GetAppAndLibIDByNameError, CS_Test_Setup, CS_Test_TearDown, + "CS_ComputeApp_Test_GetAppAndLibIDByNameError"); + UtTest_Add(CS_ComputeApp_Test_GetModuleInfoError, CS_Test_Setup, CS_Test_TearDown, + "CS_ComputeApp_Test_GetModuleInfoError"); UtTest_Add(CS_ComputeApp_Test_ComputeAppPlatformError, CS_Test_Setup, CS_Test_TearDown, "CS_ComputeApp_Test_ComputeAppPlatformError"); UtTest_Add(CS_ComputeApp_Test_DifferFromSavedValue, CS_Test_Setup, CS_Test_TearDown,