Skip to content

Commit

Permalink
Fix nasa#313: Use UT assert for OSAL unit tests
Browse files Browse the repository at this point in the history
Modify the "unit-tests" (extended/functional tests) for OSAL to use
the UT assert library for test case reporting and platform support.

Reduce or eliminate the use of macros for platform abstraction
wherever possible.

This removes most platform-specific logic from the test cases,
leaving that to the OSAL/BSP abstraction.
  • Loading branch information
jphickey committed Dec 12, 2019
1 parent ac42828 commit ba1adcb
Show file tree
Hide file tree
Showing 63 changed files with 2,024 additions and 3,715 deletions.
50 changes: 6 additions & 44 deletions src/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,21 @@
# If no match is found then it means these tests do not
# contain support for that platform and attempting compilation
# will fail.
set(TEST_SUPPORTED_COMPILEDEF_LIST
-D_LINUX_OS_
-D_VXWORKS_OS_
-DOSP_ARINC653)

string(REGEX MATCHALL "-D([A-Z_]+)" ALL_COMPILEDEFS "${CMAKE_C_FLAGS}")
set(OSTYPE_INDEX -1)
foreach(DEF ${ALL_COMPILEDEFS})
list(FIND TEST_SUPPORTED_COMPILEDEF_LIST "${DEF}" OSTYPE_INDEX)
if (NOT OSTYPE_INDEX LESS 0)
# Matching index found - OK
break()
endif()
endforeach()

if (OSTYPE_INDEX LESS 0)
set(UT_COMPILEDEFS_vxworks "_VXWORKS_OS_")
set(UT_COMPILEDEFS_posix "_LINUX_OS_")
if (NOT DEFINED UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE})
message(STATUS "Extended tests do not support ${OSAL_SYSTEM_OSTYPE}, skipping build")
return()
endif()

enable_testing()

add_definitions(-DUT_VERBOSE)
add_definitions(-D_OSAL_UNIT_TEST_)
add_definitions(-D${UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE}})

function(add_stubs OUTVAR)
set(RESULT)
foreach(STUB ${ARGN})
list(APPEND RESULT ${OSAL_SOURCE_DIR}/src/unit-tests/shared/ut_${STUB}_stubs.c)
endforeach()
set(${OUTVAR} ${RESULT} PARENT_SCOPE)
endfunction(add_stubs)
include_directories(${OSAL_SOURCE_DIR}/ut_assert/inc)
include_directories(inc)

macro(add_stubs_except OUTVAR)
foreach(STUB ${STUBFILES})
list(FIND ${ARGN} ${STUB} ISEXCL)
if (ISEXCL GREATER -1)
add_stubs(${OUTVAR} ${STUB})
endif(ISEXCL GREATER -1)
endforeach()
endmacro(add_stubs_except)

set(OSAL_TEST_MODULES core)

# filesys file loader network printf timer)
file(GLOB STUB_SRCS shared/ut_*_stubs.c)
set(STUBFILES)
foreach(STUB ${STUB_SRCS})
string(REGEX REPLACE ".*/shared/ut_(.*)_stubs\\.c$" "\\1" STUBFILE "${STUB}")
list(APPEND STUBFILES ${STUBFILE})
endforeach()

include_directories(shared)
add_subdirectory(oscore-test)
add_subdirectory(osloader-test)
add_subdirectory(osfilesys-test)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,83 @@
/*================================================================================*
** File: ut_osloader_stubs.c
** File: ut_os_support.h
** Owner: Tam Ngo
** Date: March 2013
** Date: May 2013
**================================================================================*/

#ifndef _UT_OS_SUPPORT_H_
#define _UT_OS_SUPPORT_H_

/*--------------------------------------------------------------------------------*
** Includes
**--------------------------------------------------------------------------------*/

#include "ut_os_stubs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*--------------------------------------------------------------------------------*
** Macros
**--------------------------------------------------------------------------------*/
#include "utassert.h"
#include "uttest.h"
#include "osapi.h"

/*--------------------------------------------------------------------------------*
** Data types
**--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*
** External global variables
**--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*
** Global variables
** Macros
**--------------------------------------------------------------------------------*/

UT_OsReturnCode_t g_moduleTblInit = {0,0};
UT_OsReturnCode_t g_moduleLoad = {0,0};
UT_OsReturnCode_t g_moduleUnload = {0,0};
UT_OsReturnCode_t g_moduleInfo = {0,0};
/*
* Buffers to hold names of various objects
*
* These are sized somewhat larger than the osconfig.h specification,
* so that test cases may create names that exceed the allowed length
*/
#define UT_OS_NAME_BUFF_SIZE (OS_MAX_API_NAME + 10)
#define UT_OS_FILE_BUFF_SIZE (OS_MAX_FILE_NAME + 10)
#define UT_OS_PATH_BUFF_SIZE (OS_MAX_PATH_LEN + 10)
#define UT_OS_PHYS_NAME_BUFF_SIZE (OS_FS_PHYS_NAME_LEN + 10)
#define UT_OS_LOCAL_PATH_BUFF_SIZE (OS_MAX_LOCAL_PATH_LEN + 10)

UT_OsReturnCode_t g_symbolTblLookup = {0,0};
UT_OsReturnCode_t g_symbolTblDump = {0,0};
/*
* Generic buffer for I/O operations
*/
#define UT_OS_IO_BUFF_SIZE 128


/*--------------------------------------------------------------------------------*
** Local function prototypes
**--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*
** Function definitions
**--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/

int32 OS_ModuleTableInit()
{
return (g_moduleTblInit.value);
}
#define UT_OS_TEST_RESULT(descStr, caseType) \
UtAssertEx(false, caseType, __FILE__, __LINE__, "%s", descStr)

/*--------------------------------------------------------------------------------*/

int32 OS_ModuleLoad(uint32* module_id, char* module_name, char* filename)
{
return (g_moduleLoad.value);
}
#define UT_os_sprintf(buf,...) \
snprintf(buf,sizeof(buf),__VA_ARGS__)

/*--------------------------------------------------------------------------------*/

int32 OS_ModuleUnload(uint32 module_id)
{
return (g_moduleUnload.value);
}
#define UT_OS_LOG(...) \
UtAssert_Message(UTASSERT_CASETYPE_INFO,__FILE__,__LINE__,__VA_ARGS__);

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Data types
**--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*
** External global variables
**--------------------------------------------------------------------------------*/

int32 OS_ModuleInfo(uint32 module_id, OS_module_prop_t* module_info)
{
return (g_moduleInfo.value);
}
/*--------------------------------------------------------------------------------*
** Global variables
**--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*
** Function prototypes
**--------------------------------------------------------------------------------*/

int32 OS_SymbolLookup(uint32* SymbolAddress, char* SymbolName)
{
return (g_symbolTblLookup.value);
}

/*--------------------------------------------------------------------------------*/

int32 OS_SymbolTableDump(char* filename, uint32 SizeLimit)
{
return (g_symbolTblDump.value);
}
#endif /* _UT_OS_SUPPORT_H_ */

/*================================================================================*
** End of File: ut_osloader_stubs.c
** End of File: ut_os_support.h
**================================================================================*/
3 changes: 1 addition & 2 deletions src/unit-tests/oscore-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ set(TEST_MODULE_FILES
ut_oscore_task_test.c
ut_oscore_test.c)

add_stubs(TEST_STUBS os)
add_osal_ut_exe(osal_core_UT ${TEST_MODULE_FILES} ${TEST_STUBS})
add_osal_ut_exe(osal_core_UT ${TEST_MODULE_FILES})

Loading

0 comments on commit ba1adcb

Please sign in to comment.