Skip to content

Commit

Permalink
Merge pull request nasa#804 from jphickey/fix-778-cfe-assert-take2
Browse files Browse the repository at this point in the history
Fix nasa#778, Add CFE_Assert library and test module
  • Loading branch information
astrogeco authored Aug 18, 2020
2 parents 846a739 + fa9c253 commit d50028d
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ set(MISSION_MODULE_SEARCH_PATH
set(cfe-core_SEARCH_PATH "cfe/fsw")
set(osal_SEARCH_PATH ".")
set(psp_SEARCH_PATH ".")

# If ENABLE_UNIT_TEST is enabled, then include the cfe_assert library in
# all targets. This can still be overridden in targets.cmake.
if (ENABLE_UNIT_TESTS)
list(APPEND MISSION_GLOBAL_APPLIST cfe_assert cfe_testrunner cfe_testcase)
endif (ENABLE_UNIT_TESTS)

40 changes: 40 additions & 0 deletions docs/README_functionaltest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Mini-HOWTO guide for running CFE functional tests

This version of CFE includes additional modular libraries and an application
to execute functional tests within an unmodified CFE environment. These are
distinct from the unit tests, which are executed separately from CFE in a
confined (non-CFE, test-specific) environment.

## Building the modules

These modules are built automatically when `ENABLE_UNIT_TESTS` is enabled
in the build. However, they can be added to any CFE build by adding the
following to the `APPLIST` of any target in `targets.cmake`:

- `cfe_assert`: a CFE-compatible library wrapping the basic UT assert library. This
is the same library that all other unit tests use, but configured to be
dynamically loaded into the CFE environment, and using CFE syslog for its output.
This must be the first library loaded for any functional test.

- `cfe_testcase`: a CFE-compatible library implementing test cases for CFE core apps.
This must be loaded after `cfe_assert`.

- `cfe_testrunner`: a CFE application that actually executes the tests. This is a very
simple app that waits for CFE startup to complete, then executes all registered test
cases. It also must be loaded after `cfe_assert`.


## Example startup script entries

To execute tests at startup, the following lines can be added to `cfe_es_startup.scr` on the
designated test target:

CFE_LIB, /cf/cfe_assert.so, CFE_Assert_LibInit, ASSERT_LIB, 0, 0, 0x0, 0;
CFE_APP, /cf/cfe_testrunner.so, CFE_TestRunner_AppMain, TESTRUN_APP, 100, 16384, 0x0, 0;
CFE_LIB, /cf/cfe_testcase.so, CFE_Test_Init, CFETEST_LIB, 0, 0, 0x0, 0;
CFE_LIB, /cf/psp_test.so, PSP_Test_Init, PSPTEST_LIB, 0, 0, 0x0, 0;

It is important that `cfe_assert` is loaded first, as all other test libraries depend on
symbols provided in this library. The order of loading other test cases should not
matter with respect to symbol resolution, but note that test cases will be executed in
the same order that they are registered.
12 changes: 12 additions & 0 deletions modules/cfe_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(CFE_ASSERT C)

include_directories("${CFE_ASSERT_SOURCE_DIR}/inc")
include_directories("${UT_ASSERT_SOURCE_DIR}/inc")

# Create the app module
add_cfe_app(cfe_assert
src/cfe_assert_io.c
src/cfe_assert_init.c
$<TARGET_OBJECTS:ut_assert_pic>
)

63 changes: 63 additions & 0 deletions modules/cfe_assert/inc/cfe_assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: cfe_assert.h
**
** Purpose:
** Specification for the CFE assert (UT assert wrapper) functions.
**
*************************************************************************/
#ifndef cfe_assert_h_
#define cfe_assert_h_

/************************************************************************
** Includes
*************************************************************************/
#include <common_types.h>

/************************************************************************
** Type Definitions
*************************************************************************/

/*************************************************************************
** Exported Functions
*************************************************************************/

/************************************************************************/
/** \brief Application Entry Point Function
**
** \par Description
** This function should be specified in the cfe_es_startup.scr file
** as part of starting this application.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \return Execution status, see \ref CFEReturnCodes
**
**
*************************************************************************/
void CFE_Assert_AppMain(void);

#endif /* cfe_assert_h_ */

/************************/
/* End of File Comment */
/************************/
56 changes: 56 additions & 0 deletions modules/cfe_assert/src/cfe_assert_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: cfe_assert_main.c
**
** Purpose:
** Implementation of the CFE assert (UT assert wrapper) functions.
**
*************************************************************************/

/*
* Includes
*/

#include <cfe.h>

#include "cfe_assert.h"

#include "uttest.h"
#include "utbsp.h"

/*
* Initialization Function for this library
*/
int32 CFE_Assert_LibInit(uint32 LibId)
{
UtTest_EarlyInit();
UT_BSP_Setup();

/*
* Start a test case for all startup logic.
*
* Test libs may use assert statements within their init function and these
* will be reported as a "startup" test case.
*/
UtAssert_BeginTest("CFE-STARTUP");

return CFE_SUCCESS;
}
137 changes: 137 additions & 0 deletions modules/cfe_assert/src/cfe_assert_io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: cfe_assert_io.c
**
** Purpose:
** Implementation of the CFE assert (UT assert wrapper) functions.
**
*************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#include <cfe.h>

#include "utbsp.h"
#include "uttest.h"

/*
** Local Variables
*/
typedef struct
{
uint32 CurrVerbosity;
} BSP_UT_GlobalData_t;

BSP_UT_GlobalData_t BSP_UT_Global;

void UT_BSP_Setup(void)
{
BSP_UT_Global.CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1;
UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "CFE FUNCTIONAL TEST");
}

void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName)
{
char ReportBuffer[128];

snprintf(ReportBuffer, sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName);
UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer);
}

void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage)
{
const char *Prefix;
uint32 MsgEnabled = BSP_UT_Global.CurrVerbosity >> MessageType;

if (MsgEnabled & 1)
{
switch (MessageType)
{
case UTASSERT_CASETYPE_ABORT:
Prefix = "ABORT";
break;
case UTASSERT_CASETYPE_FAILURE:
Prefix = "FAIL";
break;
case UTASSERT_CASETYPE_MIR:
Prefix = "MIR";
break;
case UTASSERT_CASETYPE_TSF:
Prefix = "TSF";
break;
case UTASSERT_CASETYPE_TTF:
Prefix = "TTF";
break;
case UTASSERT_CASETYPE_NA:
Prefix = "N/A";
break;
case UTASSERT_CASETYPE_BEGIN:
Prefix = "BEGIN";
break;
case UTASSERT_CASETYPE_END:
Prefix = "END";
break;
case UTASSERT_CASETYPE_PASS:
Prefix = "PASS";
break;
case UTASSERT_CASETYPE_INFO:
Prefix = "INFO";
break;
case UTASSERT_CASETYPE_DEBUG:
Prefix = "DEBUG";
break;
default:
Prefix = "OTHER";
break;
}

CFE_ES_WriteToSysLog("[%5s] %s\n", Prefix, OutputMessage);
}

/*
* If any ABORT (major failure) message is thrown,
* then call a BSP-provided routine to stop the test and possibly dump a core
*/
if (MessageType == UTASSERT_CASETYPE_ABORT)
{
OS_TaskExit();
}
}

void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters)
{
/*
* Only output a "summary" if there is more than one test Segment.
* Otherwise it is a duplicate of the report already given.
*/
if (TestCounters->TestSegmentCount > 1)
{
UtAssert_DoTestSegmentReport("SUMMARY", TestCounters);
}

CFE_ES_WriteToSysLog("TEST COMPLETE: %u tests Segment(s) executed\n\n",
(unsigned int)TestCounters->TestSegmentCount);

OS_TaskExit();
}
8 changes: 8 additions & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include_directories("${CFE_ASSERT_SOURCE_DIR}/inc")
include_directories("${UT_ASSERT_SOURCE_DIR}/inc")

# Create the app module
add_cfe_app(cfe_testcase
src/cfe_test.c
src/es_test.c
)
43 changes: 43 additions & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** File: cfe_test.c
**
** Purpose:
** Initialization routine for CFE functional test
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/

/*
* Includes
*/

#include "cfe_test.h"

/*
* Initialization function
* Register this test routine with CFE Assert
*/
int32 CFE_Test_Init(int32 LibId)
{
UtTest_Add(ES_Test_AppId, NULL, NULL, "ES AppID");
return CFE_SUCCESS;
}
Loading

0 comments on commit d50028d

Please sign in to comment.