Skip to content

Commit

Permalink
Merge pull request nasa#1292 from jphickey/fix-1281-test-app
Browse files Browse the repository at this point in the history
Fix nasa#1281, remove testrunner and convert testcase to app
  • Loading branch information
astrogeco authored and zanzaben committed Apr 22, 2021
2 parents 9e52770 + 65693a7 commit 63c356d
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 169 deletions.
2 changes: 1 addition & 1 deletion cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ 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)
list(APPEND MISSION_GLOBAL_APPLIST cfe_assert cfe_testcase)
endif (ENABLE_UNIT_TESTS)

11 changes: 6 additions & 5 deletions cmake/sample_defs/cpu1_cfe_es_startup.scr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
CFE_LIB, sample_lib, SAMPLE_LIB_Init, SAMPLE_LIB, 0, 0, 0x0, 0;
CFE_APP, sample_app, SAMPLE_APP_Main, SAMPLE_APP, 50, 16384, 0x0, 0;
CFE_APP, ci_lab, CI_Lab_AppMain, CI_LAB_APP, 60, 16384, 0x0, 0;
CFE_APP, to_lab, TO_Lab_AppMain, TO_LAB_APP, 70, 16384, 0x0, 0;
CFE_APP, sch_lab, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
CFE_LIB, cfe_assert, CFE_Assert_LibInit, ASSERT_LIB, 0, 0, 0x0, 0;
CFE_LIB, sample_lib, SAMPLE_LIB_Init, SAMPLE_LIB, 0, 0, 0x0, 0;
CFE_APP, sample_app, SAMPLE_APP_Main, SAMPLE_APP, 50, 16384, 0x0, 0;
CFE_APP, ci_lab, CI_Lab_AppMain, CI_LAB_APP, 60, 16384, 0x0, 0;
CFE_APP, to_lab, TO_Lab_AppMain, TO_LAB_APP, 70, 16384, 0x0, 0;
CFE_APP, sch_lab, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
!
! Startup script fields:
! 1. Object Type -- CFE_APP for an Application, or CFE_LIB for a library.
Expand Down
24 changes: 11 additions & 13 deletions docs/README_functionaltest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

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
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
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
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`.
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
- `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`.


Expand All @@ -29,12 +29,10 @@ cases. It also must be loaded after `cfe_assert`.
To execute tests at startup, the following lines can be added to `cfe_es_startup.scr` on the
designated test target:

CFE_LIB, cfe_assert, CFE_Assert_LibInit, ASSERT_LIB, 0, 0, 0x0, 0;
CFE_APP, cfe_testrunner, CFE_TR_AppMain, TESTRUN_APP, 100, 16384, 0x0, 0;
CFE_LIB, cfe_testcase, CFE_Test_Init, CFETEST_LIB, 0, 0, 0x0, 0;
CFE_LIB, psp_test, PSP_Test_Init, PSPTEST_LIB, 0, 0, 0x0, 0;
CFE_LIB, cfe_assert, CFE_Assert_LibInit, ASSERT_LIB, 0, 0, 0x0, 0;
CFE_APP, cfe_testcase, CFE_TestMain, CFE_TEST_APP, 100, 16384, 0x0, 0;

It is important that `cfe_assert` is loaded first, as all other test libraries depend on
It is important that `cfe_assert` is loaded first, as all other test applications 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.
matter with respect to symbol resolution, but note that test apps may be executed in
a different order than they are listed in the startup script.
1 change: 1 addition & 0 deletions modules/cfe_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(CFE_ASSERT C)
add_cfe_app(cfe_assert
src/cfe_assert_io.c
src/cfe_assert_init.c
src/cfe_assert_runner.c
$<TARGET_OBJECTS:ut_assert_pic>
)

Expand Down
33 changes: 30 additions & 3 deletions modules/cfe_assert/inc/cfe_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
** Includes
*************************************************************************/
#include "common_types.h"
#include "cfe_es_api_typedefs.h"

/************************************************************************
** Type Definitions
Expand All @@ -50,19 +51,45 @@ typedef void (*CFE_Assert_StatusCallback_t)(uint8 MessageType, const char *Prefi
*************************************************************************/

/************************************************************************/
/** \brief Application Entry Point Function
/** \brief Library Init Function
**
** \par Description
** This function should be specified in the cfe_es_startup.scr file
** as part of starting this application.
** as part of loading this library.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \return #CFE_SUCCESS if successful, or error code
**
*************************************************************************/
int32 CFE_Assert_LibInit(CFE_ES_LibId_t LibId);

/************************************************************************/
/** \brief Start Test
**
** \par Description
**
** \par Assumptions, External Events, and Notes:
** Must be followed by a call to CFE_Assert_ExecuteTest()
**
** \return None
**
*************************************************************************/
int32 CFE_Assert_RegisterTest(const char *TestName);

/************************************************************************/
/** \brief Execute Test and Exit
**
** \par Description
**
** \par Assumptions, External Events, and Notes:
** None
**
** \return None
**
*************************************************************************/
void CFE_Assert_AppMain(void);
void CFE_Assert_ExecuteTest(void);

/************************************************************************/
/** \brief Register a test status callback
Expand Down
13 changes: 12 additions & 1 deletion modules/cfe_assert/src/cfe_assert_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,22 @@ void CFE_Assert_RegisterCallback(CFE_Assert_StatusCallback_t Callback)
/*
* Initialization Function for this library
*/
int32 CFE_Assert_LibInit(uint32 LibId)
int32 CFE_Assert_LibInit(CFE_ES_LibId_t LibId)
{
int32 status;

memset(&CFE_Assert_Global, 0, sizeof(CFE_Assert_Global));

UtTest_EarlyInit();
UT_BSP_Setup();

status = OS_MutSemCreate(&CFE_Assert_Global.AccessMutex, "CFE_Assert", 0);
if (status != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): OS_MutSemCreate failed, rc=%d\n", __func__, (int)status);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

/*
* Start a test case for all startup logic.
*
Expand Down
2 changes: 0 additions & 2 deletions modules/cfe_assert/src/cfe_assert_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,4 @@ void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters)

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

OS_TaskExit();
}
54 changes: 54 additions & 0 deletions modules/cfe_assert/src/cfe_assert_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,73 @@
*************************************************************************/
#include "common_types.h"
#include "cfe_assert.h"
#include "cfe_mission_cfg.h"

/**
* State of the CFE assert library.
*
* Note that typically tests need to be deferred until the CFE system
* reaches "operational" state. CFE assert has its own internal state
* that needs to be managed as well.
*/
typedef enum
{
CFE_Assert_State_INIT, /**< Initial state prior to CFE_Assert_LibInit() */
CFE_Assert_State_STARTUP, /**< cFE starting: successful CFE_Assert_LibInit(), but no tests run yet. */
CFE_Assert_State_ACTIVE /**< cFE operational: Normal test applications are allowed to run */
} CFE_Assert_State_Enum_t;

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

typedef struct
{
CFE_Assert_State_Enum_t LibState;

/**
* Verbosity of default (syslog) output
*
* This controls the type(s) of assert messages that will be written to syslog.
* This only applies for default syslog output. Use of a status callback
* function overrides this.
*/
uint32 CurrVerbosity;

/**
* Function to invoke to report test status
*/
CFE_Assert_StatusCallback_t StatusCallback;

/**
* Mutex to control access to UtAssert structures.
*
* The UtAssert library is designed for single-threaded testing. To use it
* in a multi-threaded environment like CFE, it requires synchronization between
* apps, such that only one test app registers/runs tests at a time.
*/
osal_id_t AccessMutex;

/**
* AppID of the current UtAssert resource owner.
*
* Only one test application may use UtAssert facilities at a given time.
* This records the AppID of the current owner. It is set when AccessMutex
* is first acquired, and cleared once the tests have executed and the
* resource becomes available to another app.
*/
CFE_ES_AppId_t OwnerAppId;

/**
* Name of current test set being prepared/executed.
*
* This is set when the AccessMutex is first acquired, and cleared when
* the mutex is released. It is a free-form string to indicate the owner,
* and may or may not match the app name (i.e. test apps may implement
* more than one test set).
*/
char CurrentTestName[CFE_MISSION_MAX_API_LEN];

} CFE_Assert_Global_t;

extern CFE_Assert_Global_t CFE_Assert_Global;
Expand Down
Loading

0 comments on commit 63c356d

Please sign in to comment.