Skip to content

Commit

Permalink
Fix #1679, Add functional tests for resource misc
Browse files Browse the repository at this point in the history
  • Loading branch information
nmullane committed Aug 11, 2021
1 parent eb9c523 commit f1b7720
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_cfe_app(cfe_testcase
src/fs_header_test.c
src/fs_util_test.c
src/message_id_test.c
src/resource_id_misc_test.c
src/sb_pipe_mang_test.c
src/tbl_content_access_test.c
src/tbl_content_mang_test.c
Expand Down
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void CFE_TestMain(void)
FSHeaderTestSetup();
FSUtilTestSetup();
MessageIdTestSetup();
ResourceIdMiscTestSetup();
SBPipeMangSetup();
TBLContentAccessTestSetup();
TBLContentMangTestSetup();
Expand Down
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void EVSSendTestSetup(void);
void FSHeaderTestSetup(void);
void FSUtilTestSetup(void);
void MessageIdTestSetup(void);
void ResourceIdMiscTestSetup(void);
void SBPipeMangSetup(void);
void TBLContentAccessTestSetup(void);
void TBLContentMangTestSetup(void);
Expand Down
167 changes: 167 additions & 0 deletions modules/cfe_testcase/src/resource_id_misc_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: resource_id_misc_test.c
**
** Purpose:
** Functional test of Miscellaneous Resource Id APIs
**
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/

/*
* Includes
*/

#include "cfe_test.h"
/* Needed for CFE_RESOURCEID_MAKE_BASE macro */
#include "cfe_resourceid_basevalue.h"

bool TestReturnFalse(CFE_ResourceId_t CheckId)
{
return false;
}

bool TestReturnTrue(CFE_ResourceId_t CheckId)
{
return true;
}

void TestToFromInteger(void)
{
UtPrintf("Testing: CFE_ResourceId_ToInteger, CFE_ResourceId_FromInteger, CFE_ResourceId_Equal");
uint32 Id1 = 1;
uint32 Id2 = 999;
CFE_ResourceId_t ResourceId1 = CFE_ResourceId_FromInteger(Id1);
CFE_ResourceId_t ResourceId2 = CFE_ResourceId_FromInteger(Id2);
CFE_ResourceId_t ResourceId1Exp = Id1;
CFE_ResourceId_t ResourceId2Exp = Id2;
UtAssert_UINT32_EQ(CFE_ResourceId_ToInteger(ResourceId1), Id1);
UtAssert_UINT32_EQ(CFE_ResourceId_ToInteger(ResourceId2), Id2);
UtAssert_UINT32_EQ(ResourceId1, ResourceId1Exp);
UtAssert_UINT32_EQ(ResourceId2, ResourceId2Exp);
}

void TestIsDefined(void)
{
UtPrintf("Testing: CFE_ResourceId_IsDefined");
CFE_ResourceId_t ResourceId1 = 1;
CFE_ResourceId_t ResourceId2 = 999;
UtAssert_BOOL_TRUE(CFE_ResourceId_IsDefined(ResourceId1));
UtAssert_BOOL_TRUE(CFE_ResourceId_IsDefined(ResourceId2));
UtAssert_BOOL_FALSE(CFE_ResourceId_IsDefined(CFE_RESOURCEID_UNDEFINED));
}

void TestGetBaseSerial(void)
{
UtPrintf("Testing: CFE_ResourceId_GetBase, CFE_ResourceId_GetSerial");
CFE_ES_AppId_t AppId;
CFE_ES_LibId_t LibId;
CFE_ES_TaskId_t TaskId;
CFE_ES_CounterId_t CounterId;
CFE_ES_MemHandle_t PoolId;
CFE_ES_CDSHandle_t CDSHandleId;
const char * LibName = "ASSERT_LIB";
const char * CounterName = "TEST_COUNTER";
int8 Pool[1024];
size_t CDSBlockSize = 10;
const char * CDSName = "TEST_CDS";

/* Referenced from cfe_core_resourceid_basevalues.h */
int TASKID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_OS_TASK);
int APPID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 1);
int LIBID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 2);
int COUNTID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 3);
int POOLID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 4);
int CDSBLOCKID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 5);

/* App ID */
UtAssert_INT32_EQ(CFE_ES_GetAppID(&AppId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(AppId), APPID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(AppId), AppId - APPID_BASE);
/* Lib ID */
UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&LibId, LibName), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(LibId), LIBID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(LibId), LibId - LIBID_BASE);
/* Task ID */
UtAssert_INT32_EQ(CFE_ES_GetTaskID(&TaskId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(TaskId), TASKID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(TaskId), TaskId - TASKID_BASE);
/* Counter ID */
UtAssert_UINT32_EQ(CFE_ES_RegisterGenCounter(&CounterId, CounterName), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(CounterId), COUNTID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(CounterId), CounterId - COUNTID_BASE);
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(CounterId), CFE_SUCCESS);
/* Pool ID */
UtAssert_INT32_EQ(CFE_ES_PoolCreate(&PoolId, Pool, sizeof(Pool)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(PoolId), POOLID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(PoolId), PoolId - POOLID_BASE);
UtAssert_INT32_EQ(CFE_ES_PoolDelete(PoolId), CFE_SUCCESS);
/* CDS Block Id */
/*
* Commented out until this macro is merged in cfe#1790
* CFE_UtAssert_SUCCESS(CFE_ES_RegisterCDS(&CDSHandleId, CDSBlockSize, CDSName));
*/
CFE_ES_RegisterCDS(&CDSHandleId, CDSBlockSize, CDSName);
UtAssert_INT32_EQ(CFE_ResourceId_GetBase(CDSHandleId), CDSBLOCKID_BASE);
UtAssert_INT32_EQ(CFE_ResourceId_GetSerial(CDSHandleId), CDSHandleId - CDSBLOCKID_BASE);
}

void TestFindNext(void)
{
UtPrintf("Testing: CFE_ResourceId_FindNext");
CFE_ES_AppId_t AppId;
UtAssert_INT32_EQ(CFE_ES_GetAppID(&AppId), CFE_SUCCESS);
/*
* The FindNext API requires a callback function to determine if a resource id is already in use. This test provides
* two local callback functions TestReturnFalse and TestReturnTrue to test the basic functionality of this API.
*/
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, CFE_PLATFORM_ES_MAX_APPLICATIONS, TestReturnFalse), AppId + 1);
/* Pretend every application id is used */
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, CFE_PLATFORM_ES_MAX_APPLICATIONS, TestReturnTrue),
CFE_RESOURCEID_UNDEFINED);
/* maximum number of applications is 0 */
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, 0, TestReturnFalse), CFE_RESOURCEID_UNDEFINED);
}

void TestToIndex(void)
{
UtPrintf("Testing: CFE_ResourceId_ToIndex");
CFE_ES_AppId_t AppId;
uint32 idx;
int APPID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 1);
UtAssert_INT32_EQ(CFE_ES_GetAppID(&AppId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(AppId, APPID_BASE, CFE_PLATFORM_ES_MAX_APPLICATIONS, NULL),
CFE_ES_BAD_ARGUMENT);
/* pretend maximum number of applications is 0 */
UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(AppId, APPID_BASE, 0, &idx), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_ResourceId_ToIndex(AppId, APPID_BASE, CFE_PLATFORM_ES_MAX_APPLICATIONS, &idx), CFE_SUCCESS);
UtAssert_INT32_LTEQ(idx, CFE_PLATFORM_ES_MAX_APPLICATIONS);
}

void ResourceIdMiscTestSetup(void)
{
UtTest_Add(TestToFromInteger, NULL, NULL, "Test Resource Id to Integer");
UtTest_Add(TestIsDefined, NULL, NULL, "Test Resource Id is Defined");
UtTest_Add(TestGetBaseSerial, NULL, NULL, "Test Resource Id Get Base");
UtTest_Add(TestFindNext, NULL, NULL, "Test Resource Id Find Next");
UtTest_Add(TestToIndex, NULL, NULL, "Test Resource Id to Index");
}

0 comments on commit f1b7720

Please sign in to comment.