Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UT assert for OSAL unit tests #318

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 10 additions & 56 deletions src/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,21 @@
# not necessary and other OS's like RTEMS should work.
#


# This first routine checks for overlap between
# the set of supported OS type macro definitions
# and the set of macros defined in CMAKE_C_FLAGS.
#
# 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)
message(STATUS "Extended tests do not support ${OSAL_SYSTEM_OSTYPE}, skipping build")
return()
# For VxWorks and RTEMS targets there are still a few slight
# variances that need to be accounted for, mainly in the file
# names and/or directory structures that the test case uses.
set(UT_COMPILEDEFS_vxworks "_VXWORKS_OS_")
set(UT_COMPILEDEFS_rtems "_RTEMS_OS_")
set(UT_COMPILEDEFS_posix "_POSIX_OS_")
if (DEFINED UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE})
add_definitions(-D${UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE}})
endif()

enable_testing()

add_definitions(-DUT_VERBOSE)
add_definitions(-D_OSAL_UNIT_TEST_)

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)

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(${OSAL_SOURCE_DIR}/ut_assert/inc)
include_directories(inc)

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
**================================================================================*/
8 changes: 5 additions & 3 deletions src/unit-tests/oscore-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ set(TEST_MODULE_FILES
ut_oscore_countsem_test.c
ut_oscore_mutex_test.c
ut_oscore_task_test.c
ut_oscore_test.c)
ut_oscore_interrupt_test.c
ut_oscore_exception_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