Skip to content

Commit

Permalink
Fix #83, use generated stubs
Browse files Browse the repository at this point in the history
Separate the global variables into separate stub source units, then
re-run the stub generator for all internal APIs. The committed result
here is the exact output of the tool, unmodified.
  • Loading branch information
jphickey committed Mar 28, 2023
1 parent 2f177ae commit 6287c40
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 158 deletions.
7 changes: 4 additions & 3 deletions unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_cfe_coverage_stubs("lc_internal"
stubs/lc_custom_stubs.c
stubs/lc_utils_stubs.c
stubs/lc_watch_stubs.c
stubs/lc_global_stubs.c
)

# Link with the cfe core stubs and unit test assert libs
Expand All @@ -29,14 +30,14 @@ target_include_directories(coverage-lc_internal-stubs PUBLIC ../fsw/src)
# Accomplish this by cycling through all the app's source files, there must be
# a *_tests file for each
foreach(SRCFILE ${APP_SRC_FILES})
# Get the base sourcefile name as a module name without path or the

# Get the base sourcefile name as a module name without path or the
# extension, this will be used as the base name of the unit test file.
get_filename_component(UNIT_NAME "${SRCFILE}" NAME_WE)

# Use the module name to make the test name by adding _tests to the end
set(TESTS_NAME "${UNIT_NAME}_tests")

# Make the test sourcefile name with unit test path and extension
set(TESTS_SOURCE_FILE "${PROJECT_SOURCE_DIR}/unit-test/${TESTS_NAME}.c")

Expand Down
22 changes: 0 additions & 22 deletions unit-test/stubs/lc_action_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,13 @@
* limitations under the License.
************************************************************************/

/**
* @file
* Specification for the CFS Limit Checker (LC) routines that
* handle actionpoint processing
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_action header
*/

#include "lc_action.h"
#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/*
Expand Down
28 changes: 1 addition & 27 deletions unit-test/stubs/lc_app_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,15 @@
* limitations under the License.
************************************************************************/

/**
* @file
* Unit specification for the Core Flight System (CFS)
* Limit Checker (LC) Application.
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_app header
*/

#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/************************************************************************
** LC Global Data
*************************************************************************/
LC_OperData_t LC_OperData;
LC_AppData_t LC_AppData;

/*
* ----------------------------------------------------
* Generated stub function for LC_AppInit()
Expand All @@ -74,6 +47,7 @@ int32 LC_AppInit(void)
*/
void LC_AppMain(void)
{

UT_GenStub_Execute(LC_AppMain, Basic, NULL);
}

Expand Down
31 changes: 5 additions & 26 deletions unit-test/stubs/lc_cmds_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,13 @@
* limitations under the License.
************************************************************************/

/**
* @file
* Specification for the CFS Limit Checker (LC) routines that
* handle command processing
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_cmds header
*/

#include "lc_cmds.h"
#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/*
Expand Down Expand Up @@ -123,6 +101,7 @@ void LC_ResetCmd(const CFE_SB_Buffer_t *BufPtr)
*/
void LC_ResetCounters(void)
{

UT_GenStub_Execute(LC_ResetCounters, Basic, NULL);
}

Expand All @@ -131,11 +110,11 @@ void LC_ResetCounters(void)
* Generated stub function for LC_ResetResultsAP()
* ----------------------------------------------------
*/
void LC_ResetResultsAP(uint32 StartIndex, uint32 EndIndex, bool ResetCmd)
void LC_ResetResultsAP(uint32 StartIndex, uint32 EndIndex, bool ResetStatsCmd)
{
UT_GenStub_AddParam(LC_ResetResultsAP, uint32, StartIndex);
UT_GenStub_AddParam(LC_ResetResultsAP, uint32, EndIndex);
UT_GenStub_AddParam(LC_ResetResultsAP, bool, ResetCmd);
UT_GenStub_AddParam(LC_ResetResultsAP, bool, ResetStatsCmd);

UT_GenStub_Execute(LC_ResetResultsAP, Basic, NULL);
}
Expand All @@ -145,11 +124,11 @@ void LC_ResetResultsAP(uint32 StartIndex, uint32 EndIndex, bool ResetCmd)
* Generated stub function for LC_ResetResultsWP()
* ----------------------------------------------------
*/
void LC_ResetResultsWP(uint32 StartIndex, uint32 EndIndex, bool ResetCmd)
void LC_ResetResultsWP(uint32 StartIndex, uint32 EndIndex, bool ResetStatsCmd)
{
UT_GenStub_AddParam(LC_ResetResultsWP, uint32, StartIndex);
UT_GenStub_AddParam(LC_ResetResultsWP, uint32, EndIndex);
UT_GenStub_AddParam(LC_ResetResultsWP, bool, ResetCmd);
UT_GenStub_AddParam(LC_ResetResultsWP, bool, ResetStatsCmd);

UT_GenStub_Execute(LC_ResetResultsWP, Basic, NULL);
}
Expand Down
35 changes: 6 additions & 29 deletions unit-test/stubs/lc_custom_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,13 @@
* limitations under the License.
************************************************************************/

/**
* @file
* Specification for the CFS Limit Checker (LC) mission specific
* custom function template
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_custom header
*/

#include "lc_custom.h"
#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/*
Expand All @@ -56,17 +34,16 @@
uint8 LC_CustomFunction(uint16 WatchIndex, uint32 ProcessedWPData, const CFE_SB_Buffer_t *BufPtr,
uint32 WDTCustomFuncArg)
{
/*UT_GenStub_SetupReturnBuffer(LC_CustomFunction, uint8);
UT_GenStub_SetupReturnBuffer(LC_CustomFunction, uint8);

UT_GenStub_AddParam(LC_CustomFunction, uint16 , WatchIndex);
UT_GenStub_AddParam(LC_CustomFunction, uint32 , ProcessedWPData);
UT_GenStub_AddParam(LC_CustomFunction, const CFE_SB_Buffer_t* , BufPtr);
UT_GenStub_AddParam(LC_CustomFunction, uint32 , WDTCustomFuncArg);
UT_GenStub_AddParam(LC_CustomFunction, uint16, WatchIndex);
UT_GenStub_AddParam(LC_CustomFunction, uint32, ProcessedWPData);
UT_GenStub_AddParam(LC_CustomFunction, const CFE_SB_Buffer_t *, BufPtr);
UT_GenStub_AddParam(LC_CustomFunction, uint32, WDTCustomFuncArg);

UT_GenStub_Execute(LC_CustomFunction, Basic, NULL);

return UT_GenStub_GetReturnValue(LC_CustomFunction, uint8);*/
return UT_DEFAULT_IMPL(LC_CustomFunction);
return UT_GenStub_GetReturnValue(LC_CustomFunction, uint8);
}

/*
Expand Down
37 changes: 37 additions & 0 deletions unit-test/stubs/lc_global_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/************************************************************************
* NASA Docket No. GSC-18,921-1, and identified as “CFS Limit Checker
* Application version 2.2.1”
*
* Copyright (c) 2021 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_app header
*/

#include "lc_app.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

/************************************************************************
** LC Global Data
*************************************************************************/
LC_OperData_t LC_OperData;
LC_AppData_t LC_AppData;
32 changes: 5 additions & 27 deletions unit-test/stubs/lc_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,13 @@
* limitations under the License.
************************************************************************/

/**
* @file
* CFS Limit Checker (LC) utility functions
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_utils header
*/

#include "lc_utils.h"
#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/*
Expand Down Expand Up @@ -96,13 +75,12 @@ int32 LC_UpdateTaskCDS(void)
*/
bool LC_VerifyMsgLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
/* UT_GenStub_SetupReturnBuffer(LC_VerifyMsgLength, bool); */
UT_GenStub_SetupReturnBuffer(LC_VerifyMsgLength, bool);

/* UT_GenStub_AddParam(LC_VerifyMsgLength, const CFE_MSG_Message_t* , MsgPtr); */
/* UT_GenStub_AddParam(LC_VerifyMsgLength, size_t , ExpectedLength); */
UT_GenStub_AddParam(LC_VerifyMsgLength, const CFE_MSG_Message_t *, MsgPtr);
UT_GenStub_AddParam(LC_VerifyMsgLength, size_t, ExpectedLength);

/* UT_GenStub_Execute(LC_VerifyMsgLength, Basic, NULL); */
UT_GenStub_Execute(LC_VerifyMsgLength, Basic, NULL);

/* return UT_GenStub_GetReturnValue(LC_VerifyMsgLength, bool); */
return UT_DEFAULT_IMPL(LC_VerifyMsgLength) != 0;
return UT_GenStub_GetReturnValue(LC_VerifyMsgLength, bool);
}
27 changes: 3 additions & 24 deletions unit-test/stubs/lc_watch_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,13 @@
* limitations under the License.
************************************************************************/

/**
* @file
* Specification for the CFS Limit Checker (LC) routines that
* handle watchpoint processing
*/

/**
* @file
*
* Auto-Generated stub implementations for functions defined in lc_watch header
*/

#include "lc_watch.h"
#include "lc_app.h"
#include "lc_msg.h"
#include "lc_msgdefs.h"
#include "lc_msgids.h"
#include "lc_events.h"
#include "lc_version.h"
#include "lc_test_utils.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"

#include <unistd.h>
#include <stdlib.h>

#include "utgenstub.h"

/*
Expand Down Expand Up @@ -84,6 +62,7 @@ void LC_CheckMsgForWPs(CFE_SB_MsgId_t MessageID, const CFE_SB_Buffer_t *BufPtr)
*/
void LC_CreateHashTable(void)
{

UT_GenStub_Execute(LC_CreateHashTable, Basic, NULL);
}

Expand All @@ -97,8 +76,8 @@ uint8 LC_FloatCompare(uint16 WatchIndex, LC_MultiType_t *WPMultiType, LC_MultiTy
UT_GenStub_SetupReturnBuffer(LC_FloatCompare, uint8);

UT_GenStub_AddParam(LC_FloatCompare, uint16, WatchIndex);
UT_GenStub_AddParam(LC_FloatCompare, LC_MultiType_t, WPMultiType);
UT_GenStub_AddParam(LC_FloatCompare, LC_MultiType_t, CompareMultiType);
UT_GenStub_AddParam(LC_FloatCompare, LC_MultiType_t *, WPMultiType);
UT_GenStub_AddParam(LC_FloatCompare, LC_MultiType_t *, CompareMultiType);

UT_GenStub_Execute(LC_FloatCompare, Basic, NULL);

Expand Down

0 comments on commit 6287c40

Please sign in to comment.