Skip to content

Commit

Permalink
Fix #46, 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.

This eases future maintainence, when an internal API changes one just
needs to re-run the stub generator tool to update it
  • Loading branch information
jphickey committed Mar 22, 2023
1 parent 71fe47a commit 68f484c
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 73 deletions.
5 changes: 3 additions & 2 deletions unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

add_cfe_coverage_stubs("hk_internal"
utilities/hk_test_utils.c
stubs/hk_global_stubs.c
stubs/hk_utils_stubs.c
stubs/hk_app_stubs.c
)
Expand All @@ -26,13 +27,13 @@ target_include_directories(coverage-hk_internal-stubs PUBLIC ../fsw/src)
# 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
124 changes: 88 additions & 36 deletions unit-test/stubs/hk_app_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,121 @@
* limitations under the License.
************************************************************************/

#include "hk_app.h"
#include "hk_msg.h"
#include "hk_events.h"
#include "hk_version.h"
#include "hk_msgids.h"
#include "hk_utils.h"
/**
* @file
*
* Auto-Generated stub implementations for functions defined in hk_app header
*/

#include <string.h>
#include "hk_app.h"
#include "utgenstub.h"

/* UT includes */
#include "uttest.h"
#include "utassert.h"
#include "utstubs.h"
/*
* ----------------------------------------------------
* Generated stub function for HK_AppInit()
* ----------------------------------------------------
*/
int32 HK_AppInit(void)
{
UT_GenStub_SetupReturnBuffer(HK_AppInit, int32);

HK_AppData_t HK_AppData;
UT_GenStub_Execute(HK_AppInit, Basic, NULL);

void HK_AppMain(void)
{
UtPrintf("HK_AppMain Stub");
UT_DEFAULT_IMPL(HK_AppMain);
return UT_GenStub_GetReturnValue(HK_AppInit, int32);
}

int32 HK_AppInit(void)
/*
* ----------------------------------------------------
* Generated stub function for HK_AppMain()
* ----------------------------------------------------
*/
void HK_AppMain(void)
{
return UT_DEFAULT_IMPL(HK_AppInit);
}

int32 HK_TableInit(void)
{
return UT_DEFAULT_IMPL(HK_TableInit);
UT_GenStub_Execute(HK_AppMain, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_AppPipe()
* ----------------------------------------------------
*/
void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr)
{
UT_Stub_RegisterContext(UT_KEY(HK_AppPipe), BufPtr);
UT_DEFAULT_IMPL(HK_AppPipe);
}
UT_GenStub_AddParam(HK_AppPipe, const CFE_SB_Buffer_t *, BufPtr);

void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr)
{
UT_Stub_RegisterContext(UT_KEY(HK_SendCombinedHKCmd), BufPtr);
UT_DEFAULT_IMPL(HK_SendCombinedHKCmd);
UT_GenStub_Execute(HK_AppPipe, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_HousekeepingCmd()
* ----------------------------------------------------
*/
void HK_HousekeepingCmd(const CFE_MSG_CommandHeader_t *Msg)
{
UT_Stub_RegisterContext(UT_KEY(HK_HousekeepingCmd), Msg);
UT_DEFAULT_IMPL(HK_HousekeepingCmd);
UT_GenStub_AddParam(HK_HousekeepingCmd, const CFE_MSG_CommandHeader_t *, Msg);

UT_GenStub_Execute(HK_HousekeepingCmd, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_NoopCmd()
* ----------------------------------------------------
*/
void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
{
UT_Stub_RegisterContext(UT_KEY(HK_NoopCmd), BufPtr);
UT_DEFAULT_IMPL(HK_NoopCmd);
UT_GenStub_AddParam(HK_NoopCmd, const CFE_SB_Buffer_t *, BufPtr);

UT_GenStub_Execute(HK_NoopCmd, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_ResetCtrsCmd()
* ----------------------------------------------------
*/
void HK_ResetCtrsCmd(const CFE_SB_Buffer_t *BufPtr)
{
UT_Stub_RegisterContext(UT_KEY(HK_ResetCtrsCmd), BufPtr);
UT_DEFAULT_IMPL(HK_ResetCtrsCmd);
UT_GenStub_AddParam(HK_ResetCtrsCmd, const CFE_SB_Buffer_t *, BufPtr);

UT_GenStub_Execute(HK_ResetCtrsCmd, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_ResetHkData()
* ----------------------------------------------------
*/
void HK_ResetHkData(void)
{
UT_DEFAULT_IMPL(HK_ResetHkData);

UT_GenStub_Execute(HK_ResetHkData, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_SendCombinedHKCmd()
* ----------------------------------------------------
*/
void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr)
{
UT_GenStub_AddParam(HK_SendCombinedHKCmd, const CFE_SB_Buffer_t *, BufPtr);

UT_GenStub_Execute(HK_SendCombinedHKCmd, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for HK_TableInit()
* ----------------------------------------------------
*/
int32 HK_TableInit(void)
{
UT_GenStub_SetupReturnBuffer(HK_TableInit, int32);

UT_GenStub_Execute(HK_TableInit, Basic, NULL);

return UT_GenStub_GetReturnValue(HK_TableInit, int32);
}
27 changes: 27 additions & 0 deletions unit-test/stubs/hk_global_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/************************************************************************
* NASA Docket No. GSC-18,919-1, and identified as “Core Flight
* System (cFS) Housekeeping (HK) Application version 2.5.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 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.
************************************************************************/

#include "hk_app.h"

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

HK_AppData_t HK_AppData;
Loading

0 comments on commit 68f484c

Please sign in to comment.