-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1679, Add functional tests for resource misc
- Loading branch information
Showing
4 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/************************************************************************* | ||
** | ||
** 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 DummyReturnFalse(CFE_ResourceId_t CheckId) | ||
{ | ||
return false; | ||
} | ||
|
||
bool DummyReturnTrue(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); | ||
/* 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); | ||
/* CDS Block Id */ | ||
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); | ||
/* | ||
* To test FindNext better the internal function CFE_ES_CheckCounterIdSlotUsed needs to be reimplemented or accessed | ||
* somehow. The current test just uses dummy functions to always return true or false | ||
*/ | ||
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, CFE_PLATFORM_ES_MAX_APPLICATIONS, DummyReturnFalse), AppId + 1); | ||
/* Pretend every application id is used */ | ||
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, CFE_PLATFORM_ES_MAX_APPLICATIONS, DummyReturnTrue), | ||
CFE_RESOURCEID_UNDEFINED); | ||
/* maximum number of applications is 0 */ | ||
UtAssert_UINT32_EQ(CFE_ResourceId_FindNext(AppId, 0, DummyReturnFalse), 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"); | ||
} |