-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nasa#1577, Add Message API Functional Test
- Loading branch information
pavll
committed
Jul 30, 2021
1 parent
33a4f19
commit 8a7f427
Showing
5 changed files
with
246 additions
and
3 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,240 @@ | ||
/************************************************************************* | ||
** | ||
** GSC-18128-1, "Core Flight Executive Version 6.7" | ||
** | ||
** Copyright (c) 2006-2021 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: msg_api_test.c | ||
** | ||
** Purpose: | ||
** Functional test of cFE Message header APIs. | ||
** | ||
*************************************************************************/ | ||
|
||
/* | ||
* Includes | ||
*/ | ||
|
||
#include "cfe_test.h" | ||
#include <string.h> | ||
|
||
/* merged all test into one function to avoid creating new messages for each test */ | ||
void TestMsgAPI(void) | ||
{ | ||
UtPrintf("Testing: CFE_MSG_Init, CFE_MSG_GetSize, CFE_MSG_SetSize, CFE_MSG_GetType, " | ||
"CFE_MSG_SetType, CFE_MSG_GetHeaderVersion, CFE_MSG_SetHeaderVersion, " | ||
"CFE_MSG_GetHasSecondaryHeader, CFE_MSG_SetHasSecondaryHeader, CFE_MSG_GetApId, " | ||
"CFE_MSG_SetApId, CFE_MSG_GetSegmentationFlag, CFE_MSG_SetSegmentationFlag, " | ||
"CFE_MSG_GetSequenceCount, CFE_MSG_SetSequenceCount, CFE_MSG_GetNextSequenceCount, " | ||
"CFE_MSG_GetEDSVersion, CFE_MSG_SetEDSVersion, CFE_MSG_GetEndian, CFE_MSG_SetEndian, " | ||
"CFE_MSG_GetPlaybackFlag, CFE_MSG_SetPlaybackFlag, CFE_MSG_GetSubsystem, " | ||
"CFE_MSG_SetSubsystem, CFE_MSG_GetSystem, CFE_MSG_SetSystem, CFE_MSG_GenerateChecksum, " | ||
"CFE_MSG_ValidateChecksum, CFE_MSG_SetFcnCode, CFE_MSG_GetFcnCode, " | ||
"CFE_MSG_GetMsgTime, CFE_MSG_SetMsgTime "); | ||
|
||
/* declare local vars */ | ||
CFE_MSG_CommandHeader_t cmd; | ||
CFE_MSG_Size_t size; | ||
CFE_MSG_Type_t type; | ||
CFE_SB_MsgId_Atom_t msgId; | ||
CFE_MSG_HeaderVersion_t hdrVer; | ||
CFE_MSG_ApId_t appId; | ||
CFE_MSG_SegmentationFlag_t segFlag; | ||
CFE_MSG_SequenceCount_t seqCnt; | ||
CFE_MSG_EDSVersion_t edsVersion; | ||
CFE_MSG_Endian_t endian; | ||
CFE_MSG_PlaybackFlag_t playbackFlag; | ||
CFE_MSG_Subsystem_t subSystem; | ||
CFE_MSG_System_t system; | ||
CFE_MSG_FcnCode_t fcnCode; | ||
CFE_TIME_SysTime_t msgTime; | ||
bool hasSecondaryHdr; | ||
bool isValid; | ||
|
||
memset(&cmd, 0xFF, sizeof(cmd)); | ||
msgId = 0; | ||
|
||
/* test msg-init */ | ||
UtAssert_INT32_EQ(CFE_MSG_Init(NULL, CFE_SB_ValueToMsgId(0), sizeof(cmd)), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(0), 0), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(msgId), sizeof(cmd)); | ||
|
||
/* test set-msg-size */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetSize(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetSize(&cmd.Msg, 12u)); | ||
|
||
/* test get-msg-size */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetSize(&cmd.Msg, &size)); | ||
UtAssert_True(size == 12u, "CFE_MSG_SetSize => size = 12u"); | ||
|
||
/* test get-type */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetType(&cmd.Msg, &type)); | ||
/* type has to be ...Type_Cmd because it created within a command */ | ||
UtAssert_INT32_EQ(type, CFE_MSG_Type_Cmd); | ||
|
||
/* test msg set-type */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_SetType(&cmd.Msg, CFE_MSG_Type_Tlm)); | ||
/* check if set-type works like expected */ | ||
UtAssert_INT32_EQ(CFE_MSG_GetType(&cmd.Msg, &type), CFE_MSG_Type_Tlm); | ||
|
||
/* test get header-version */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetHeaderVersion(&cmd.Msg, &hdrVer)); | ||
UtAssert_INT32_EQ(CFE_MSG_GetHeaderVersion(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* test set header-version */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_SetHeaderVersion(&cmd.Msg, CFE_MISSION_CCSDSVER); | ||
CFE_MSG_GetHeaderVersion(&cmd.Msg, &hdrVer); | ||
UtAssert_True(hdrVer == CFE_MISSION_CCSDSVER, "hdrVer = CFE_MISSION_CCSDSVER"); | ||
UtAssert_INT32_EQ(CFE_MSG_SetHeaderVersion(NULL, hdrVer), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_SetHeaderVersion(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* test get-has-secondary-header */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetHasSecondaryHeader(&cmd.Msg, &hasSecondaryHdr)); | ||
UtAssert_INT32_EQ(CFE_MSG_GetHasSecondaryHeader(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* test set-has-scondary-header */ | ||
hasSecondaryHdr = true; | ||
CFE_UtAssert_SUCCESS(CFE_MSG_SetHasSecondaryHeader(&cmd.Msg, hasSecondaryHdr)); | ||
hasSecondaryHdr = false; | ||
CFE_MSG_GetHasSecondaryHeader(&cmd.Msg, &hasSecondaryHdr); | ||
UtAssert_True(hasSecondaryHdr, "CFE_MSG_SetHasSecondaryHeader => CFE_MSG_GetHasSecondaryHeader = true"); | ||
|
||
/* test get-apid */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetApId(&cmd.Msg, &appId)); | ||
UtAssert_INT32_EQ(CFE_MSG_GetApId(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* test set-apid */ | ||
CFE_UtAssert_SUCCESS(CFE_MSG_SetApId(&cmd.Msg, CFE_PLATFORM_DEFAULT_APID)); | ||
UtAssert_True(CFE_MSG_GetApId(&cmd.Msg, &appId) == CFE_PLATFORM_DEFAULT_APID, "CFE_MSG_SetApId => apid = CFE_PLATFORM_DEFAULT_APID"); | ||
UtAssert_INT32_EQ(CFE_MSG_SetApId(&cmd.Msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* test get/set-segmentation-flag */ | ||
UtAssert_INT32_EQ(CFE_MSG_GetSegmentationFlag(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_SetSegmentationFlag(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetSegmentationFlag(&cmd.Msg, CFE_MSG_SegFlag_Continue)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetSegmentationFlag(&cmd.Msg, &segFlag)); | ||
UtAssert_True(segFlag == CFE_MSG_SegFlag_Continue, "CFE_MSG_SetSegmentationFlag => segFlag = CFE_MSG_SegFlag_Continue"); | ||
|
||
/* test set/get-sequence-count */ | ||
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetSequenceCount(&cmd.Msg, 2u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetSequenceCount(&cmd.Msg, &seqCnt)); | ||
|
||
UtAssert_True(seqCnt == 2u, "CFE_MSG_SetSequenceCount => seqCnt = 2"); | ||
|
||
/* test get-next-sequence-count */ | ||
UtAssert_True(CFE_MSG_GetNextSequenceCount(NULL) == 0, "CFE_MSG_GetNextSequenceCount(NULL) = 0"); | ||
/* 0x3FFF <- bad because defined CFE_MSG_SEQCNT_MASK value but not public */ | ||
UtAssert_True(CFE_MSG_GetNextSequenceCount(0x3FFF + 1) == 0, "CFE_MSG_GetNextSequenceCount(0x3FFF+1) = 0"); | ||
UtAssert_True(CFE_MSG_GetNextSequenceCount(2u) == 3u, "CFE_MSG_GetNextSequenceCount(2u) = 3u"); | ||
|
||
/* test get/set-eds-version */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetEDSVersion(&cmd.msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetEDSVersion(&cmd.msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetEDSVersion(&cmd.Msg, 5u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetEDSVersion(&cmd.Msg, &edsVersion)); | ||
|
||
UtAssert_True(edsVersion == 5u, "CFE_MSG_SetEDSVersion => edsVersion = 5u"); | ||
|
||
/* test get/set-endian */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetEndian(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_SetEndian(&cmd.Msg, CFE_MSG_Endian_Invalid), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetEndian(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetEndian(&cmd.Msg, CFE_MSG_Endian_Little)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetEndian(&cmd.Msg, &endian)); | ||
|
||
UtAssert_True(endian == CFE_MSG_Endian_Little, "CFE_MSG_SetEndian => endian = CFE_MSG_Endian_Little"); | ||
|
||
/* test get/set-playback-flag */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetPlaybackFlag(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_SetPlaybackFlag(&cmd.Msg, CFE_MSG_PlayFlag_Invalid), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetPlaybackFlag(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetPlaybackFlag(&cmd.Msg, CFE_MSG_PlayFlag_Playback)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetPlaybackFlag(&cmd.Msg, &playbackFlag)); | ||
|
||
UtAssert_True(playbackFlag == CFE_MSG_PlayFlag_Playback, "CFE_MSG_SetPlaybackFlag => playbackFlag = CFE_MSG_PlayFlag_Playback"); | ||
|
||
/* test get/set-subsystem */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetSubsystem(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetSubsystem(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetSubsystem(&cmd.Msg, 3u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetSubsystem(&cmd.Msg, &subSystem)); | ||
|
||
UtAssert_True(subSystem == 3u, "CFE_MSG_SetSubsystem => subSystem = 3u"); | ||
|
||
/* test get/set-system */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetSystem(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetSystem(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetSystem(&cmd.Msg, 3u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetSystem(&cmd.Msg, &system)); | ||
|
||
UtAssert_True(system == 3u, "CFE_MSG_SetSystem => system = 3u"); | ||
|
||
/* test generate-checksum */ | ||
UtAssert_INT32_EQ(CFE_MSG_GenerateChecksum(NULL), CFE_MSG_BAD_ARGUMENT); | ||
CFE_MSG_SetType(&cmd.Msg, CFE_MSG_Type_Tlm); | ||
UtAssert_INT32_EQ(CFE_MSG_GenerateChecksum(&cmd.Msg), CFE_MSG_BAD_ARGUMENT); | ||
|
||
/* create new cmd message - TODO */ | ||
/* | ||
* CFE_MSG_CommandHeader_t cmd2; | ||
* memset(&cmd2, 0xFF, sizeof(cmd2)); | ||
* CFE_UtAssert_SUCCESS(CFE_MSG_Init(&cmd2.Msg, CFE_SB_ValueToMsgId(1u), sizeof(cmd2)); | ||
* | ||
* UtAssert_UINT32_EQ(CFE_MSG_GenerateChecksum(&cmd2.Msg), <precalculated checksum for a new message>); | ||
* delete cmd2.Msg; | ||
* delete cmd2; | ||
*/ | ||
|
||
/* | ||
* CFE_UtAssert_SUCCESS(CFE_MSG_ValidateChecksum(&cmd.Msg, &isValid)); | ||
* UtAssert_True(isValid, "checksum: isValid = true"); | ||
*/ | ||
|
||
/* test get/set-fcn-code */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetFcnCode(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetFcnCode(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetFcnCode(&cmd.Msg, 4u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetFcnCode(&cmd.Msg, &fcnCode)); | ||
|
||
UtAssert_True(fcnCode == 4u, "CFE_MSG_SetFcnCode => fcnCode = 4u"); | ||
|
||
/* test get/set-msg-time */ | ||
UtAssert_INT32_EQ(CFE_MSG_SetMsgTime(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_MSG_GetMsgTime(&cmd.Msg, NULL), CFE_MSG_BAD_ARGUMENT); | ||
|
||
CFE_UtAssert_SUCCESS(CFE_MSG_SetMsgTime(&cmd.Msg, 7u)); | ||
CFE_UtAssert_SUCCESS(CFE_MSG_GetMsgTime(&cmd.Msg, &msgTime)); | ||
|
||
UtAssert_True(msgTime == 7u, "CFE_MSG_SetMsgTime => msgTime = 7u"); | ||
} | ||
|
||
void MsgAPITestSetup(void) | ||
{ | ||
UtTest_Add(TestMsgAPI, NULL, NULL, "Test message header apis"); | ||
} |
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