From 164c75e3e1c67175f1df43611e7cdd22b1a4746e Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:53:52 -0400 Subject: [PATCH] Fix #711, Add msg module unit test --- modules/msg/unit-test-coverage/CMakeLists.txt | 63 +++ modules/msg/unit-test-coverage/msg_UT.c | 55 ++ .../test_cfe_msg_ccsdsext.c | 424 ++++++++++++++++ .../test_cfe_msg_ccsdsext.h | 37 ++ .../test_cfe_msg_ccsdspri.c | 469 ++++++++++++++++++ .../test_cfe_msg_ccsdspri.h | 39 ++ .../test_cfe_msg_checksum.c | 90 ++++ .../test_cfe_msg_checksum.h | 33 ++ .../msg/unit-test-coverage/test_cfe_msg_fc.c | 105 ++++ .../msg/unit-test-coverage/test_cfe_msg_fc.h | 33 ++ .../unit-test-coverage/test_cfe_msg_init.c | 147 ++++++ .../unit-test-coverage/test_cfe_msg_init.h | 37 ++ .../unit-test-coverage/test_cfe_msg_msgid.h | 33 ++ .../test_cfe_msg_msgid_shared.c | 79 +++ .../test_cfe_msg_msgid_shared.h | 33 ++ .../test_cfe_msg_msgid_v1.c | 104 ++++ .../test_cfe_msg_msgid_v2.c | 116 +++++ .../unit-test-coverage/test_cfe_msg_time.c | 98 ++++ .../unit-test-coverage/test_cfe_msg_time.h | 33 ++ .../msg/unit-test-coverage/test_msg_ext_not.c | 85 ++++ modules/msg/unit-test-coverage/test_msg_not.c | 55 ++ modules/msg/unit-test-coverage/test_msg_not.h | 67 +++ .../msg/unit-test-coverage/test_msg_pri_not.c | 102 ++++ .../msg/unit-test-coverage/test_msg_prionly.c | 42 ++ .../msg/unit-test-coverage/test_msg_utils.c | 72 +++ .../msg/unit-test-coverage/test_msg_utils.h | 45 ++ 26 files changed, 2496 insertions(+) create mode 100644 modules/msg/unit-test-coverage/CMakeLists.txt create mode 100644 modules/msg/unit-test-coverage/msg_UT.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_checksum.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_checksum.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_fc.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_fc.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_init.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_init.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_time.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_time.h create mode 100644 modules/msg/unit-test-coverage/test_msg_ext_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_not.h create mode 100644 modules/msg/unit-test-coverage/test_msg_pri_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_prionly.c create mode 100644 modules/msg/unit-test-coverage/test_msg_utils.c create mode 100644 modules/msg/unit-test-coverage/test_msg_utils.h diff --git a/modules/msg/unit-test-coverage/CMakeLists.txt b/modules/msg/unit-test-coverage/CMakeLists.txt new file mode 100644 index 000000000..5449769c4 --- /dev/null +++ b/modules/msg/unit-test-coverage/CMakeLists.txt @@ -0,0 +1,63 @@ +################################################################## +# +# cFE unit test build recipe +# +# This CMake file contains the recipe for building the cFE unit tests. +# It is invoked from the parent directory when unit tests are enabled. +# +################################################################## + +# Unit test object library sources, options, and includes +add_library(ut_${DEP}_objs OBJECT ${${DEP}_SRC}) +target_compile_options(ut_${DEP}_objs PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) +target_include_directories(ut_${DEP}_objs PRIVATE + $) + +set (ut_${DEP}_tests + msg_UT.c + test_msg_utils.c + test_msg_not.c + test_msg_pri_not.c + test_cfe_msg_init.c + test_cfe_msg_ccsdspri.c + test_cfe_msg_msgid_shared.c + test_cfe_msg_checksum.c + test_cfe_msg_fc.c + test_cfe_msg_time.c + $) + +# Add extended header tests if appropriate +if (MISSION_INCLUDE_CCSDSEXT_HEADER) + list(APPEND ut_${DEP}_tests + test_msg_ext_not.c + test_cfe_msg_ccsdsext.c) +else (MISSION_INCLUDE_CCSDSEXT_HEADER) + list(APPEND ut_${DEP}_tests + test_msg_prionly.c) +endif (MISSION_INCLUDE_CCSDSEXT_HEADER) + +# Add the correct message id test +if (MISSION_MSGID_V2) + list(APPEND ut_${DEP}_tests + test_cfe_msg_msgid_v2.c) +else (MISSION_MSGID_V2) + list(APPEND ut_${DEP}_tests + test_cfe_msg_msgid_v1.c) +endif (MISSION_MSGID_V2) + +# Add executable +add_executable(${DEP}_UT ${ut_${DEP}_tests}) + +# Add include to get private defaults +target_include_directories(${DEP}_UT PRIVATE ../private_inc) + +# Also add the UT_COVERAGE_LINK_FLAGS to the link command +# This should enable coverage analysis on platforms that support this +target_link_libraries(${DEP}_UT + ${UT_COVERAGE_LINK_FLAGS} + ut_cfe-core_support + ut_cfe-core_stubs + ut_assert) + +add_test(${DEP}_UT ${DEP}_UT) +install(TARGETS ${DEP}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) diff --git a/modules/msg/unit-test-coverage/msg_UT.c b/modules/msg/unit-test-coverage/msg_UT.c new file mode 100644 index 000000000..3b0359276 --- /dev/null +++ b/modules/msg/unit-test-coverage/msg_UT.c @@ -0,0 +1,55 @@ +/* +** 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. +*/ + +/* + * Message header unit tests + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_cfe_msg_init.h" +#include "test_cfe_msg_ccsdspri.h" +#include "test_cfe_msg_ccsdsext.h" +#include "test_cfe_msg_msgid_shared.h" +#include "test_cfe_msg_msgid.h" +#include "test_cfe_msg_fc.h" +#include "test_cfe_msg_checksum.h" +#include "test_cfe_msg_time.h" + +/* + * Functions + */ +void UtTest_Setup(void) +{ + UT_Init("msg"); + UT_Text("Message header coverage test..."); + + UT_ADD_TEST(Test_MSG_Init); + UT_ADD_TEST(Test_MSG_CCSDSPri); + UT_ADD_TEST(Test_MSG_CCSDSExt); + UT_ADD_TEST(Test_MSG_MsgId_Shared); + UT_ADD_TEST(Test_MSG_MsgId); + UT_ADD_TEST(Test_MSG_Checksum); + UT_ADD_TEST(Test_MSG_FcnCode); + UT_ADD_TEST(Test_MSG_Time); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c new file mode 100644 index 000000000..63b897f26 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c @@ -0,0 +1,424 @@ +/* +** 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. +*/ + +/* + * Test CCSDS Extended header accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_ccsdsext.h" +#include "cfe_error.h" +#include "cfe_mission_cfg.h" +#include "cfe_platform_cfg.h" +#include "cfe_msg_defaults.h" +#include + +/* + * Defines + */ +#define TEST_EDSVER_MAX 0x1F /* Maximum value for EDS Version field */ +#define TEST_SUBSYS_MAX 0x1FF /* Maximum value for Subsystem field */ +#define TEST_SYSTEM_MAX 0xFFFF /* Maximum value for System field */ + +#define TEST_DEFAULT_SUBSYS_MASK 0x100 /* Bits that can be set by default subsys if msgid V2 */ + +/* Extended header initialization specific coverage */ +void Test_MSG_Init_Ext(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_Atom_t msgidval_exp; + CFE_MSG_HeaderVersion_t hdrver; + CFE_MSG_Subsystem_t subsys; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_System_t system; + CFE_MSG_Endian_t endian; + bool is_v1; + + /* Get msgid version by checking if msgid sets header version */ + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + is_v1 = (hdrver == 0); + + UT_Text("Set to all F's, msgid value = 0, and run with clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Default EDS version check */ + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &edsver), CFE_SUCCESS); + ASSERT_EQ(edsver, CFE_PLATFORM_EDSVER); + + /* Default subsystem check */ + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &subsys), CFE_SUCCESS); + if (is_v1) + ASSERT_EQ(subsys, CFE_PLATFORM_DEFAULT_SUBSYS); + else + ASSERT_EQ(subsys, CFE_PLATFORM_DEFAULT_SUBSYS & TEST_DEFAULT_SUBSYS_MASK); + + /* Default system check */ + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &system), CFE_SUCCESS); + ASSERT_EQ(system, CFE_MISSION_SPACECRAFT_ID); + + /* Default endian check */ + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &endian), CFE_SUCCESS); +#if (CFE_PLATFORM_ENDIAN == CCSDS_LITTLE_ENDIAN) + ASSERT_EQ(endian, CFE_MSG_Endian_Little); +#else + ASSERT_EQ(endian, CFE_MSG_Endian_Big); +#endif + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Ext_NotZero(&msg) & ~(MSG_EDSVER_FLAG | MSG_ENDIAN_FLAG | MSG_SUBSYS_FLAG | MSG_SYSTEM_FLAG), 0); + + UT_Text("Set to all 0, max msgid value, and run without clearing"); + memset(&msg, 0, sizeof(msg)); + msgidval_exp = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Default subsystem check */ + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &subsys), CFE_SUCCESS); + if (is_v1) + ASSERT_EQ(subsys, 0); + else + ASSERT_EQ(subsys, 0xFF); + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Ext_NotZero(&msg) & ~MSG_SUBSYS_FLAG, 0); +} + +void Test_MSG_EDSVersion(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_EDSVersion_t input[] = {0, TEST_EDSVER_MAX / 2, TEST_EDSVER_MAX}; + CFE_MSG_EDSVersion_t actual = TEST_EDSVER_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_EDSVER_MAX); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, TEST_EDSVER_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_EDSVER_MAX); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_EDSVER_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_EDSVER_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_EDSVER_FLAG); + } + } +} + +void Test_MSG_Endian(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Endian_t input[] = {CFE_MSG_Endian_Big, CFE_MSG_Endian_Little}; + CFE_MSG_Endian_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_Endian_Invalid, CFE_MSG_Endian_Little + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEndian(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, CFE_MSG_Endian_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, CFE_MSG_Endian_Little + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Endian_Little); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Endian_Little) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_ENDIAN_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Endian_Big); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Endian_Big) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_ENDIAN_FLAG); + } + } +} + +void Test_MSG_PlaybackFlag(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_PlaybackFlag_t input[] = {CFE_MSG_PlayFlag_Original, CFE_MSG_PlayFlag_Playback}; + CFE_MSG_PlaybackFlag_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_PlayFlag_Invalid, CFE_MSG_PlayFlag_Playback + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, CFE_MSG_PlayFlag_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, CFE_MSG_PlayFlag_Playback + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_PlayFlag_Playback); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_PlayFlag_Playback) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_PBACK_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_PlayFlag_Original); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_PlayFlag_Original) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_PBACK_FLAG); + } + } +} + +void Test_MSG_Subsystem(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Subsystem_t input[] = {0, TEST_SUBSYS_MAX / 2, TEST_SUBSYS_MAX}; + CFE_MSG_Subsystem_t actual = TEST_SUBSYS_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SUBSYS_MAX); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, TEST_SUBSYS_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SUBSYS_MAX); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SUBSYS_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SUBSYS_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SUBSYS_FLAG); + } + } +} + +void Test_MSG_System(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_SYSTEM_MAX / 2, TEST_SYSTEM_MAX}; + CFE_MSG_ApId_t actual = TEST_SYSTEM_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SYSTEM_MAX); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSystem(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SYSTEM_MAX); + ASSERT_EQ(CFE_MSG_SetSystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SYSTEM_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SYSTEM_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SYSTEM_FLAG); + } + } +} + +/* + * Test MSG ccsdsext + */ +void Test_MSG_CCSDSExt(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_Init_Ext); + MSG_UT_ADD_SUBTEST(Test_MSG_EDSVersion); + MSG_UT_ADD_SUBTEST(Test_MSG_Endian); + MSG_UT_ADD_SUBTEST(Test_MSG_PlaybackFlag); + MSG_UT_ADD_SUBTEST(Test_MSG_Subsystem); + MSG_UT_ADD_SUBTEST(Test_MSG_System); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h new file mode 100644 index 000000000..d1c416432 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h @@ -0,0 +1,37 @@ +/* +** 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. +*/ + +/* + * cfe_msg_ccsdsext test header + */ +#ifndef test_cfe_msg_ccsdsext_ +#define test_cfe_msg_ccsdsext_ + +/* + * Defines + */ + +/* + * Functions + */ +/* Test CCSDS Extended header accessor functions */ +void Test_MSG_CCSDSExt(void); + +#endif /* test_cfe_msg_ccsdsext_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c new file mode 100644 index 000000000..104c2955c --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c @@ -0,0 +1,469 @@ +/* +** 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. +*/ + +/* + * Test CCSDS Primary header accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_ccsdspri.h" +#include "cfe_error.h" +#include + +/* + * Defines + */ +#define TEST_CCSDSVER_MAX 7 /* Maximum value for CCSDS Version field */ +#define TEST_APID_MAX 0x7FF /* Maximum value for CCSDS ApId field */ +#define TEST_SEQUENCE_MAX 0x3FFF /* Maximum value for CCSDS Sequence field */ + +void Test_MSG_Size(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Size_t input[] = {TEST_MSG_SIZE_OFFSET, 0x8000, 0xFFFF, 0xFFFF + TEST_MSG_SIZE_OFFSET}; + CFE_MSG_Size_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (0, min valid - 1, max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetSize(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, TEST_MSG_SIZE_OFFSET - 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0xFFFF + TEST_MSG_SIZE_OFFSET + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0xFFFFFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0xFFFF + TEST_MSG_SIZE_OFFSET); + ASSERT_EQ(CFE_MSG_SetSize(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0xFFFF + TEST_MSG_SIZE_OFFSET) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_LENGTH_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_MSG_SIZE_OFFSET); + ASSERT_EQ(CFE_MSG_SetSize(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_MSG_SIZE_OFFSET) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_LENGTH_FLAG); + } + } +} + +void Test_MSG_Type(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Type_t input[] = {CFE_MSG_Type_Cmd, CFE_MSG_Type_Tlm}; + CFE_MSG_Type_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_Type_Invalid, CFE_MSG_Type_Tlm + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetType(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetType(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + ASSERT_EQ(CFE_MSG_SetType(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Type_Cmd) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_TYPE_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); + ASSERT_EQ(CFE_MSG_SetType(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Type_Tlm) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + } + } +} + +void Test_MSG_HeaderVersion(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_HeaderVersion_t input[] = {0, TEST_CCSDSVER_MAX / 2, TEST_CCSDSVER_MAX}; + CFE_MSG_HeaderVersion_t actual = TEST_CCSDSVER_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_CCSDSVER_MAX); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, TEST_CCSDSVER_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_CCSDSVER_MAX); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_CCSDSVER_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HDRVER_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HDRVER_FLAG); + } + } +} + +void Test_MSG_HasSecondaryHeader(void) +{ + CFE_MSG_Message_t msg; + bool actual = true; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(NULL, false), CFE_MSG_BAD_ARGUMENT); + + UT_Text("Set to all F's, true and false inputs"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HASSEC_FLAG); + + UT_Text("Set to all 0, true and false inputs"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HASSEC_FLAG); +} + +void Test_MSG_ApId(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_APID_MAX / 2, TEST_APID_MAX}; + CFE_MSG_ApId_t actual = TEST_APID_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_APID_MAX); + ASSERT_EQ(CFE_MSG_GetApId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetApId(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetApId(&msg, TEST_APID_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetApId(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_APID_MAX); + ASSERT_EQ(CFE_MSG_SetApId(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_APID_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_APID_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetApId(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + } + } +} + +void Test_MSG_SegmentationFlag(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_SegmentationFlag_t input[] = {CFE_MSG_SegFlag_Continue, CFE_MSG_SegFlag_First, CFE_MSG_SegFlag_Last, + CFE_MSG_SegFlag_Unsegmented}; + CFE_MSG_SegmentationFlag_t actual = CFE_MSG_SegFlag_Invalid; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (*_Invalid, max valid + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Invalid); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, CFE_MSG_SegFlag_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, CFE_MSG_SegFlag_Unsegmented + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Unsegmented); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_SegFlag_Unsegmented) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SEGMENT_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Continue); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_SegFlag_Continue) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SEGMENT_FLAG); + } + } +} + +void Test_MSG_SequenceCount(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_SEQUENCE_MAX / 2, TEST_SEQUENCE_MAX}; + CFE_MSG_ApId_t actual = TEST_SEQUENCE_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SEQUENCE_MAX); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, TEST_SEQUENCE_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SEQUENCE_MAX); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SEQUENCE_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SEQUENCE_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SEQUENCE_FLAG); + } + } +} + +/* + * Test MSG ccsdspri + */ +void Test_MSG_CCSDSPri(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_Size); + MSG_UT_ADD_SUBTEST(Test_MSG_Type); + MSG_UT_ADD_SUBTEST(Test_MSG_HeaderVersion); + MSG_UT_ADD_SUBTEST(Test_MSG_HasSecondaryHeader); + MSG_UT_ADD_SUBTEST(Test_MSG_ApId); + MSG_UT_ADD_SUBTEST(Test_MSG_SegmentationFlag); + MSG_UT_ADD_SUBTEST(Test_MSG_SequenceCount); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h new file mode 100644 index 000000000..c85e21961 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h @@ -0,0 +1,39 @@ +/* +** 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. +*/ + +/* + * cfe_msg_ccsdspri test header + */ +#ifndef test_cfe_msg_ccsdspri_ +#define test_cfe_msg_ccsdspri_ + +/* + * Defines + */ + +#define TEST_MSG_SIZE_OFFSET 7 /* CCSDS Message length offset */ + +/* + * Functions + */ +/* Test CCSDS Primary header accessor functions */ +void Test_MSG_CCSDSPri(void); + +#endif /* test_cfe_msg_ccsdspri_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c new file mode 100644 index 000000000..5b3b433c5 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c @@ -0,0 +1,90 @@ +/* +** 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. +*/ + +/* + * Test checksum accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_checksum.h" +#include "cfe_error.h" +#include + +void Test_MSG_Checksum(void) +{ + CFE_SB_CmdHdr_t cmd; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd; + bool actual; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&cmd, 0, sizeof(cmd)); + actual = true; + ASSERT_EQ(CFE_MSG_GenerateChecksum(NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_ValidateChecksum(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + + UT_Text("Bad message, no secondary header"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + + UT_Text("Bad message, wrong type (telemetry)"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + + UT_Text("Set to all F's, validate/generate/validate"); + memset(&cmd, 0xFF, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetSize(msgptr, sizeof(cmd)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotF(msgptr), MSG_LENGTH_FLAG); + + UT_Text("Set to all 0 except secheader and type, validate/generate/validate"); + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetSize(msgptr, sizeof(cmd)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_LENGTH_FLAG | MSG_HASSEC_FLAG | MSG_TYPE_FLAG); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h new file mode 100644 index 000000000..5b521fe7f --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_checksum test header + */ +#ifndef test_cfe_msg_checksum_ +#define test_cfe_msg_checksum_ + +/* + * Functions + */ +/* Test checksum accessor functions */ +void Test_MSG_Checksum(void); + +#endif /* test_cfe_msg_checksum_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_fc.c b/modules/msg/unit-test-coverage/test_cfe_msg_fc.c new file mode 100644 index 000000000..062a1d908 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_fc.c @@ -0,0 +1,105 @@ +/* +** 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. +*/ + +/* + * Test function code accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_fc.h" +#include "cfe_error.h" +#include + +/* + * Defines + */ +#define TEST_FCNCODE_MAX 0x7F /* Maximum value for fc field */ + +void Test_MSG_FcnCode(void) +{ + CFE_SB_CmdHdr_t cmd; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd; + CFE_MSG_FcnCode_t input[] = {0, TEST_FCNCODE_MAX / 2, TEST_FCNCODE_MAX}; + CFE_MSG_FcnCode_t actual = TEST_FCNCODE_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers, invalid (max valid + 1, max)"); + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_FCNCODE_MAX); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, TEST_FCNCODE_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + + UT_Text("Bad message, no secondary header"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + + UT_Text("Bad message, wrong type (telemetry)"); + memset(&cmd, 0, sizeof(cmd)); + actual = TEST_FCNCODE_MAX; + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&cmd, 0xFF, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_FCNCODE_MAX); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + ASSERT_EQ(Test_MSG_NotF(msgptr), 0); + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG | MSG_TYPE_FLAG); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_fc.h b/modules/msg/unit-test-coverage/test_cfe_msg_fc.h new file mode 100644 index 000000000..1dbff0fca --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_fc.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_fc test header + */ +#ifndef test_cfe_msg_fc_ +#define test_cfe_msg_fc_ + +/* + * Functions + */ +/* Test function code accessor functions */ +void Test_MSG_FcnCode(void); + +#endif /* test_cfe_msg_fc_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_init.c b/modules/msg/unit-test-coverage/test_cfe_msg_init.c new file mode 100644 index 000000000..d49924493 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_init.c @@ -0,0 +1,147 @@ +/* +** 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. +*/ + +/* + * Test message init + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_init.h" +#include "cfe_error.h" +#include "cfe_msg_defaults.h" +#include + +#define TEST_DEFAULT_APID_MASK 0x780 /* Bits that can be set by default apid if msgid V2 */ + +/* + * Test MSG Init + */ +void Test_MSG_Init(void) +{ + + CFE_MSG_Message_t msg; + CFE_MSG_Size_t size; + CFE_SB_MsgId_Atom_t msgidval_exp; + CFE_SB_MsgId_t msgid_act; + CFE_MSG_HeaderVersion_t hdrver; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + unsigned int flag_exp; + bool hassec; + bool is_v1; + + UT_Text("Bad parameter tests, Null pointer, invalid size, invalid msgid"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_Init(NULL, CFE_SB_ValueToMsgId(0), sizeof(msg), false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(0), 0, false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), sizeof(msg), false), + CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(-1), sizeof(msg), false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, msgid value = 0, and run without clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Get msgid version by checking if header version was set */ + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + is_v1 = (hdrver == 0); + + flag_exp = MSG_TYPE_FLAG | MSG_LENGTH_FLAG | MSG_APID_FLAG; + if (is_v1) + flag_exp |= MSG_HDRVER_FLAG | MSG_HASSEC_FLAG; + + ASSERT_EQ(Test_MSG_Pri_NotF(&msg), flag_exp); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + + UT_Text("Set to all F's, msgid value = 0, and run with clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &segflag), CFE_SUCCESS); + ASSERT_EQ(segflag, CFE_MSG_SegFlag_Unsegmented); + + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + if (!is_v1) + { + ASSERT_EQ(apid, CFE_PLATFORM_DEFAULT_APID & TEST_DEFAULT_APID_MASK); + ASSERT_EQ(hdrver, CFE_MISSION_CCSDSVER); + ASSERT_EQ(hassec, true); + } + else + { + ASSERT_EQ(apid, 0); + ASSERT_EQ(hdrver, 0); + ASSERT_EQ(hassec, false); + } + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~(MSG_APID_FLAG | MSG_HDRVER_FLAG | MSG_HASSEC_FLAG), + MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG); + + UT_Text("Set to all 0, max msgid value, and run without clearing"); + memset(&msg, 0, sizeof(msg)); + msgidval_exp = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + if (!is_v1) + { + ASSERT_EQ(apid & TEST_DEFAULT_APID_MASK, CFE_PLATFORM_DEFAULT_APID & TEST_DEFAULT_APID_MASK); + ASSERT_EQ(hassec, false); + } + else + { + ASSERT_EQ(apid, 0x7FF); + ASSERT_EQ(hassec, true); + } + + ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~(MSG_APID_FLAG | MSG_HASSEC_FLAG), MSG_TYPE_FLAG | MSG_LENGTH_FLAG); + + /* Zero (no default) header version check */ + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + ASSERT_EQ(hdrver, 0); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_init.h b/modules/msg/unit-test-coverage/test_cfe_msg_init.h new file mode 100644 index 000000000..0ee75f86c --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_init.h @@ -0,0 +1,37 @@ +/* +** 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. +*/ + +/* + * cfe_msg_init test header + */ +#ifndef test_cfe_msg_init_ +#define test_cfe_msg_init_ + +/* + * Includes + */ + +/* + * Functions + */ +/* Test extended header mission functionality */ +void Test_MSG_Init(void); + +#endif /* test_cfe_msg_init_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h b/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h new file mode 100644 index 000000000..8a3a467e9 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * Message ID V2 accessor function test header + */ +#ifndef test_cfe_msg_msgid_ +#define test_cfe_msg_msgid_ + +/* + * Functions + */ +/* Test msgid accessor functions */ +void Test_MSG_MsgId(void); + +#endif /* test_cfe_msg_msgid_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c new file mode 100644 index 000000000..4cec04552 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c @@ -0,0 +1,79 @@ +/* +** 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. +*/ + +/* + * Test MsgId shared accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid_shared.h" +#include "cfe_error.h" +#include + +void Test_MSG_GetTypeFromMsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(0); + CFE_MSG_Type_t actual = CFE_MSG_Type_Invalid; + + UT_Text("Bad parameter tests, Null pointer"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, test cmd and tlm"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); + + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + + UT_Text("Set to all 0, test cmd and tlm"); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); +} + +/* + * Test MSG MsgId Shared + */ +void Test_MSG_MsgId_Shared(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_GetTypeFromMsgId); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h new file mode 100644 index 000000000..469f65408 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_msgid_shared test header + */ +#ifndef test_cfe_msg_msgid_shared_ +#define test_cfe_msg_msgid_shared_ + +/* + * Functions + */ +/* Test msgid shared accessor functions */ +void Test_MSG_MsgId_Shared(void); + +#endif /* test_cfe_msg_msgid_shared_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c new file mode 100644 index 000000000..f0e51a2aa --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c @@ -0,0 +1,104 @@ +/* +** 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. +*/ + +/* + * Test MsgId V1 accessors + */ + +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid.h" +#include "cfe_error.h" +#include + +#define TEST_MAX_APID 0x7FF + +void Test_MSG_MsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(1); + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + bool hassec; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(NULL, &msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 1); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(NULL, msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_INVALID_MSG_ID), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set msg to all F's, set msgid to 0 and verify"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0xFFFF); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HDRVER_FLAG | MSG_APID_FLAG | MSG_TYPE_FLAG | MSG_HASSEC_FLAG); + + UT_Text("Set msg to all 0, set msgid to max and verify"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | MSG_HASSEC_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, TEST_MAX_APID); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + ASSERT_EQ(hassec, true); + + UT_Text("Set ApId msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(TEST_MAX_APID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, TEST_MAX_APID); + + UT_Text("Set has secondary header bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x0800)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HASSEC_FLAG); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + ASSERT_EQ(hassec, true); + + UT_Text("Set type msgid bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x1000)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c new file mode 100644 index 000000000..cca35be7a --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c @@ -0,0 +1,116 @@ +/* +** 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. +*/ + +/* + * Test MsgId V2 accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid.h" +#include "cfe_error.h" +#include + +void Test_MSG_MsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(1); + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_Subsystem_t subsystem; + int local_subsys_flag = 0; + + /* Check if subsystem accessor functions are implemented */ + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + local_subsys_flag = MSG_SUBSYS_FLAG; + } + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(NULL, &msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 1); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(NULL, msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_INVALID_MSG_ID), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0xFFFFFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set msg to all F's, set msgid to 0 and verify"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0xFFFF); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | local_subsys_flag); + + UT_Text("Set msg to all 0, set msgid to max and verify"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | local_subsys_flag); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, 0x7F); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + ASSERT_EQ(subsystem, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID >> 8); + } + + UT_Text("Set ApId msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x007F)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, 0x007F); + + UT_Text("Set type msgid bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x0080)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + + UT_Text("Set subsystem msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0xFF00 & CFE_PLATFORM_SB_HIGHEST_VALID_MSGID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), local_subsys_flag); + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + ASSERT_EQ(subsystem, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID >> 8); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_time.c b/modules/msg/unit-test-coverage/test_cfe_msg_time.c new file mode 100644 index 000000000..6e6977d52 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_time.c @@ -0,0 +1,98 @@ +/* +** 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. +*/ + +/* + * Test time accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_time.h" +#include "cfe_error.h" +#include + +void Test_MSG_Time(void) +{ + CFE_SB_TlmHdr_t tlm; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&tlm; + CFE_TIME_SysTime_t input[] = {{0, 0}, {0x12345678, 0xABCDEF12}, {0xFFFFFFFF, 0xFFFFFFFF}}; + CFE_TIME_SysTime_t actual = {0xFFFFFFFF, 0xFFFFFFFF}; + int i; + + UT_Text("Bad parameter tests, Null pointers, no secondary header"); + memset(&tlm, 0, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual.Seconds, 0xFFFFFFFF); + ASSERT_EQ(actual.Subseconds, 0xFFFFFFFF); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetMsgTime(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + + UT_Text("Bad message, wrong type (command)"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&tlm, 0xFF, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, 0xFFFFFFFF); + ASSERT_EQ(actual.Subseconds, 0xFFFF0000); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, input[i].Seconds); + ASSERT_EQ(actual.Subseconds, input[i].Subseconds & 0xFFFF0000); + ASSERT_EQ(Test_MSG_NotF(msgptr), MSG_TYPE_FLAG); + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&tlm, 0, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, input[i].Seconds); + ASSERT_EQ(actual.Subseconds, input[i].Subseconds & 0xFFFF0000); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_time.h b/modules/msg/unit-test-coverage/test_cfe_msg_time.h new file mode 100644 index 000000000..2981d8ee5 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_time.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_time test header + */ +#ifndef test_cfe_msg_time_ +#define test_cfe_msg_time_ + +/* + * Functions + */ +/* Test time accessor functions */ +void Test_MSG_Time(void); + +#endif /* test_cfe_msg_time_ */ diff --git a/modules/msg/unit-test-coverage/test_msg_ext_not.c b/modules/msg/unit-test-coverage/test_msg_ext_not.c new file mode 100644 index 000000000..d764bfabd --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_ext_not.c @@ -0,0 +1,85 @@ +/* +** 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. +*/ + +/* + * Extended message header field not Zero or F + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_Endian_t endian; + CFE_MSG_PlaybackFlag_t playflag; + CFE_MSG_Subsystem_t subsystem; + CFE_MSG_System_t system; + + CFE_MSG_GetEDSVersion(MsgPtr, &edsver); + if (edsver != 0) + bits |= MSG_EDSVER_FLAG; + CFE_MSG_GetEndian(MsgPtr, &endian); + if (endian != CFE_MSG_Endian_Big) + bits |= MSG_ENDIAN_FLAG; + CFE_MSG_GetPlaybackFlag(MsgPtr, &playflag); + if (playflag != CFE_MSG_PlayFlag_Original) + bits |= MSG_PBACK_FLAG; + CFE_MSG_GetSubsystem(MsgPtr, &subsystem); + if (subsystem != 0) + bits |= MSG_SUBSYS_FLAG; + CFE_MSG_GetSystem(MsgPtr, &system); + if (system != 0) + bits |= MSG_SYSTEM_FLAG; + + return bits; +} + +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_Endian_t endian; + CFE_MSG_PlaybackFlag_t playflag; + CFE_MSG_Subsystem_t subsystem; + CFE_MSG_System_t system; + + CFE_MSG_GetEDSVersion(MsgPtr, &edsver); + if (edsver != 0x1F) + bits |= MSG_EDSVER_FLAG; + CFE_MSG_GetEndian(MsgPtr, &endian); + if (endian != CFE_MSG_Endian_Little) + bits |= MSG_ENDIAN_FLAG; + CFE_MSG_GetPlaybackFlag(MsgPtr, &playflag); + if (playflag != CFE_MSG_PlayFlag_Playback) + bits |= MSG_PBACK_FLAG; + CFE_MSG_GetSubsystem(MsgPtr, &subsystem); + if (subsystem != 0x1FF) + bits |= MSG_SUBSYS_FLAG; + CFE_MSG_GetSystem(MsgPtr, &system); + if (system != 0xFFFF) + bits |= MSG_SYSTEM_FLAG; + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_not.c b/modules/msg/unit-test-coverage/test_msg_not.c new file mode 100644 index 000000000..8d7d60e86 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_not.c @@ -0,0 +1,55 @@ +/* +** 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. +*/ + +/* + * Message header field not Zero or F + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + + /* Primary */ + bits |= Test_MSG_Pri_NotZero(MsgPtr); + + /* Extended */ + bits |= Test_MSG_Ext_NotZero(MsgPtr); + + return bits; +} + +unsigned int Test_MSG_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + + /* Primary */ + bits |= Test_MSG_Pri_NotF(MsgPtr); + + /* Extended */ + bits |= Test_MSG_Ext_NotF(MsgPtr); + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_not.h b/modules/msg/unit-test-coverage/test_msg_not.h new file mode 100644 index 000000000..10bb706ba --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_not.h @@ -0,0 +1,67 @@ +/* +** 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. +*/ + +/* + * Message header fields not (Zero or F's) + */ +#ifndef test_msg_not_ +#define test_msg_not_ + +/* + * Defines + */ + +/* Field flags */ +/* CCSDS Primary */ +#define MSG_HDRVER_FLAG 0x00001 +#define MSG_TYPE_FLAG 0x00002 +#define MSG_HASSEC_FLAG 0x00004 +#define MSG_APID_FLAG 0x00008 +#define MSG_SEGMENT_FLAG 0x00010 +#define MSG_SEQUENCE_FLAG 0x00020 +#define MSG_LENGTH_FLAG 0x00040 + +/* Extended */ +#define MSG_EDSVER_FLAG 0x00080 +#define MSG_ENDIAN_FLAG 0x00100 +#define MSG_PBACK_FLAG 0x00200 +#define MSG_SUBSYS_FLAG 0x00400 +#define MSG_SYSTEM_FLAG 0x00800 + +/* Secondary */ +#define MSG_CKSUM_FLAG 0x01000 +#define MSG_FCNCODE_FLAG 0x02000 +#define MSG_TIME_FLAG 0x04000 + +/* + * Prototypes + */ + +/* Returns flags for fields that are 0 */ +unsigned int Test_MSG_NotZero(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Pri_NotZero(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr); + +/* Returns flags for fields that are fully set (aka all F's */ +unsigned int Test_MSG_NotF(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Pri_NotF(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr); + +#endif /* test_msg_not_ */ diff --git a/modules/msg/unit-test-coverage/test_msg_pri_not.c b/modules/msg/unit-test-coverage/test_msg_pri_not.c new file mode 100644 index 000000000..3f35cf3b0 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_pri_not.c @@ -0,0 +1,102 @@ +/* +** 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. +*/ + +/* + * Primary message header field not Zero or F + */ + +/* + * Includes + */ +#include "test_cfe_msg_ccsdspri.h" /* For TEST_MSG_SIZE_OFFSET */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_Pri_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_HeaderVersion_t hdrver; + bool hassec; + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + CFE_MSG_SequenceCount_t seqcnt; + CFE_MSG_Size_t size; + + CFE_MSG_GetHeaderVersion(MsgPtr, &hdrver); + if (hdrver != 0) + bits |= MSG_HDRVER_FLAG; + CFE_MSG_GetType(MsgPtr, &type); + if (type != CFE_MSG_Type_Tlm) + bits |= MSG_TYPE_FLAG; + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassec); + if (hassec) + bits |= MSG_HASSEC_FLAG; + CFE_MSG_GetApId(MsgPtr, &apid); + if (apid != 0) + bits |= MSG_APID_FLAG; + CFE_MSG_GetSegmentationFlag(MsgPtr, &segflag); + if (segflag != CFE_MSG_SegFlag_Continue) + bits |= MSG_SEGMENT_FLAG; + CFE_MSG_GetSequenceCount(MsgPtr, &seqcnt); + if (seqcnt != 0) + bits |= MSG_SEQUENCE_FLAG; + CFE_MSG_GetSize(MsgPtr, &size); + if (size != TEST_MSG_SIZE_OFFSET) + bits |= MSG_LENGTH_FLAG; + + return bits; +} + +unsigned int Test_MSG_Pri_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_HeaderVersion_t hdrver; + bool hassec; + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + CFE_MSG_SequenceCount_t seqcnt; + CFE_MSG_Size_t size; + + CFE_MSG_GetHeaderVersion(MsgPtr, &hdrver); + if (hdrver != 0x7) + bits |= MSG_HDRVER_FLAG; + CFE_MSG_GetType(MsgPtr, &type); + if (type != CFE_MSG_Type_Cmd) + bits |= MSG_TYPE_FLAG; + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassec); + if (!hassec) + bits |= MSG_HASSEC_FLAG; + CFE_MSG_GetApId(MsgPtr, &apid); + if (apid != 0x7FF) + bits |= MSG_APID_FLAG; + CFE_MSG_GetSegmentationFlag(MsgPtr, &segflag); + if (segflag != CFE_MSG_SegFlag_Unsegmented) + bits |= MSG_SEGMENT_FLAG; + CFE_MSG_GetSequenceCount(MsgPtr, &seqcnt); + if (seqcnt != 0x3FFF) + bits |= MSG_SEQUENCE_FLAG; + CFE_MSG_GetSize(MsgPtr, &size); + if (size != 0xFFFF + TEST_MSG_SIZE_OFFSET) + bits |= MSG_LENGTH_FLAG; + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_prionly.c b/modules/msg/unit-test-coverage/test_msg_prionly.c new file mode 100644 index 000000000..6df77d970 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_prionly.c @@ -0,0 +1,42 @@ +/* +** 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. +*/ + +/* + * Extended header stubbed out, use when no extended header is defined + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_cfe_msg_ccsdsext.h" + +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + return 0; +} + +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + return 0; +} + +void Test_MSG_CCSDSExt(void) {} diff --git a/modules/msg/unit-test-coverage/test_msg_utils.c b/modules/msg/unit-test-coverage/test_msg_utils.c new file mode 100644 index 000000000..1b715076e --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_utils.c @@ -0,0 +1,72 @@ +/* +** 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. +*/ + +/* + * Message header test utilities + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_utils.h" +#include "utassert.h" + +void Test_MSG_PrintMsg(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size) +{ + + int i; + char sbuf[121] = {0}; + char wbuf[6] = {0}; + + if (Size == 0) + { + CFE_MSG_GetSize(MsgPtr, &Size); + } + + for (i = 0; i < Size / 2; i++) + { + sprintf(wbuf, "%02X%02X ", MsgPtr->Byte[i * 2], MsgPtr->Byte[(i * 2) + 1]); + strcat(sbuf, wbuf); + + /* Make sure string buffer doesn't overflow */ + if (sizeof(sbuf) < (strlen(sbuf) + 6)) + break; + } + + UtAssert_Message(UTASSERT_CASETYPE_INFO, __FILE__, __LINE__, "Message: %s", sbuf); +} + +unsigned long long int Test_MSG_Sum(const CFE_MSG_Message_t *MsgPtr) +{ + + CFE_MSG_Size_t length; + unsigned long long int sum = 0; + int i; + + CFE_MSG_GetSize(MsgPtr, &length); + + for (i = 0; i < length; i++) + { + sum += MsgPtr->Byte[i]; + } + + return sum; +} diff --git a/modules/msg/unit-test-coverage/test_msg_utils.h b/modules/msg/unit-test-coverage/test_msg_utils.h new file mode 100644 index 000000000..8ff2c6ef8 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_utils.h @@ -0,0 +1,45 @@ +/* +** 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. +*/ + +/* + * Message header test utilities + */ +#ifndef test_msg_utils_ +#define test_msg_utils_ + +/* + * Includes + */ +#include "cfe_msg_typedefs.h" + +/* + * Defines + */ + +/* Subtest macro */ +#define MSG_UT_ADD_SUBTEST(Func) UT_AddSubTest(Func, NULL, NULL, __func__, #Func) + +/* Prints the message, 0 length uses length from message */ +void Test_MSG_PrintMsg(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size); + +/* Sums the message for checking, generically check the entire message */ +unsigned long long int Test_MSG_Sum(const CFE_MSG_Message_t *MsgPtr); + +#endif /* test_msg_utils_ */