Skip to content

Commit

Permalink
Fix #460, UT dependencies on BSP volume maps
Browse files Browse the repository at this point in the history
Do not assume BSP volume table provides a "/cf" directory map.
Instead, create a UT-specific map of a consistent name, and use
that.
  • Loading branch information
jphickey committed May 14, 2020
1 parent 1c36569 commit b251466
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 63 deletions.
7 changes: 7 additions & 0 deletions osconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,12 @@
*/
#define OS_MAX_CONSOLES 1

/**
* \brief The system-specific file extension used on loadable module files
*
* Fixed value based on system selection, not user configurable.
*/
#define OS_MODULE_FILE_EXTENSION "@CMAKE_SHARED_LIBRARY_SUFFIX@"


#endif /* INCLUDE_OSCONFIG_H_ */
19 changes: 15 additions & 4 deletions src/tests/file-api-test/file-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ os_err_name_t errname;

void UtTest_Setup(void)
{
uint32 fs_id;

errname[0] = 0;

if (OS_API_Init() != OS_SUCCESS)
{
UtAssert_Abort("OS_API_Init() failed");
}

/*
* This test case requires a fixed virtual dir for one test case.
* Just map /test to a dir of the same name, relative to current dir.
*/
if (OS_FileSysAddFixedMap(&fs_id, "./test", "/test") != OS_SUCCESS)
{
UtAssert_Abort("OS_FileSysAddFixedMap() failed");
}

/*
* Register the test setup and check routines in UT assert
*
Expand Down Expand Up @@ -667,13 +678,13 @@ void TestOpenReadCloseDir(void)

/* Test case for bug #181 - make sure that a directory used as a mount point
* is able to be opened. This should not require a trailing
* slash (i.e. /cf rather than /cf/) */
status = OS_DirectoryOpen(&dirh, "/cf");
UtAssert_True(status >= OS_SUCCESS, "OS_DirectoryOpen /cf Id=%u Rc=%d",(unsigned int)dirh,(int)status);
* slash (i.e. /test rather than /test/) */
status = OS_DirectoryOpen(&dirh, "/test");
UtAssert_True(status >= OS_SUCCESS, "OS_DirectoryOpen /test Id=%u Rc=%d",(unsigned int)dirh,(int)status);

/*Close the file */
status = OS_DirectoryClose(dirh);
UtAssert_True(status >= OS_SUCCESS, "OS_DirectoryClose /cf Rc=%d",(int)status);
UtAssert_True(status >= OS_SUCCESS, "OS_DirectoryClose /test Rc=%d",(int)status);

/* remove the files */
status = OS_remove(filename1);
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/osloader-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ while(MOD GREATER 0)
set_target_properties(MODULE${MOD} PROPERTIES
COMPILE_DEFINITIONS "MODULE_NAME=module${MOD}"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY eeprom1)
LIBRARY_OUTPUT_DIRECTORY utmod)
add_dependencies(osal_loader_UT MODULE${MOD})
endwhile(MOD GREATER 0)
6 changes: 2 additions & 4 deletions src/unit-tests/osloader-test/ut_osloader_module_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ void UT_os_module_load_test()
/* Setup */
for ( i = 0; i< OS_MAX_MODULES; i++ )
{
memset(module_name, '\0', sizeof(module_name));
UT_os_sprintf(module_name, "MODULE%d",i);
memset(module_file_name, '\0', sizeof(module_file_name));
UT_os_sprintf(module_file_name, UT_OS_SPECIFIC_MODULE_NAME, i);
snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i);
snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i);
res = OS_ModuleLoad(&module_id, module_name, module_file_name);
if ( res != OS_SUCCESS )
{
Expand Down
39 changes: 17 additions & 22 deletions src/unit-tests/osloader-test/ut_osloader_symtable_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,11 @@ void UT_os_symbol_table_dump_test()
int32 res = 0;
const char* testDesc;

/*-----------------------------------------------------*/
testDesc = "API Not implemented";

res = OS_SymbolTableDump("/cf/apps/SymbolFile.dat", 32000);
if (res == OS_ERR_NOT_IMPLEMENTED)
{
UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA);
goto UT_os_symbol_table_dump_test_exit_tag;
}
/*
* Note that even if the functionality is not implemented,
* the API still validates the input pointers (not null) and
* the validity of the file name.
*/

/*-----------------------------------------------------*/
testDesc = "#1 Invalid-pointer-arg";
Expand All @@ -157,23 +153,22 @@ void UT_os_symbol_table_dump_test()
UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE);

/*-----------------------------------------------------*/
testDesc = "#3 OS-call-failure";

UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_INFO);

/*-----------------------------------------------------*/
testDesc = "#4 Nominal";
testDesc = "#3 Nominal";

/* Setup */
res = OS_SymbolTableDump("/cf/apps/SymbolFile.dat", 32000);
if ( res == OS_SUCCESS )
res = OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolFile.dat", 32000);
if (res == OS_ERR_NOT_IMPLEMENTED)
{
/* allowed, not applicable on this system */
UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA);
}
else if ( res == OS_SUCCESS )
{
UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS);
}
else
{
UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE);

UT_os_symbol_table_dump_test_exit_tag:
return;

}
}

/*================================================================================*
Expand Down
13 changes: 13 additions & 0 deletions src/unit-tests/osloader-test/ut_osloader_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,24 @@

void UtTest_Setup(void)
{
uint32 fs_id;

if (OS_API_Init() != OS_SUCCESS)
{
UtAssert_Abort("OS_API_Init() failed");
}

/*
* This test needs to load the modules from the filesystem, so
* there must be a virtual path corresponding to the path where
* the module files reside. This UT-specific mapping should be
* independent of the volume tables provided by the BSP.
*/
if (OS_FileSysAddFixedMap(&fs_id, "./utmod", "/utmod") != OS_SUCCESS)
{
UtAssert_Abort("OS_FileSysAddFixedMap() failed");
}

UtTest_Add(UT_os_module_load_test, NULL, NULL, "OS_ModuleLoad");
UtTest_Add(UT_os_module_unload_test, NULL, NULL, "OS_ModuleUnload");
UtTest_Add(UT_os_module_info_test, NULL, NULL, "OS_ModuleInfo");
Expand Down
38 changes: 6 additions & 32 deletions src/unit-tests/osloader-test/ut_osloader_test_platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,14 @@
** Macros
**--------------------------------------------------------------------------------*/

/*
* The actual module files that the loader tests attempt to load need
* to be consistent with the system type that is being compiled for.
*
* It can be assumed that the BSP will provide some sort of virtual
* filesystem mapping for the /cf directory, but the file extension
* for a loadable module still differs.
*/
#define UT_OS_GENERIC_MODULE_DIR "/utmod/"
#define UT_OS_GENERIC_MODULE_BASENAME "MODULE"

/*--------------------------------------------*/
#if defined(_VXWORKS_OS_) || defined(OSP_ARINC653)
/*--------------------------------------------*/
#define UT_OS_GENERIC_MODULE_NAME1 UT_OS_GENERIC_MODULE_DIR UT_OS_GENERIC_MODULE_BASENAME "0" OS_MODULE_FILE_EXTENSION
#define UT_OS_GENERIC_MODULE_NAME2 UT_OS_GENERIC_MODULE_DIR UT_OS_GENERIC_MODULE_BASENAME "1" OS_MODULE_FILE_EXTENSION

#define UT_OS_GENERIC_MODULE_NAME1 "/cf/apps/MODULE.o"
#define UT_OS_GENERIC_MODULE_NAME2 "/cf/apps/MODULE1.o"
#define UT_OS_SPECIFIC_MODULE_NAME "/cf/apps/MODULE%d.o"

/*--------------------------------------------*/
#elif defined(_RTEMS_OS_)
/*--------------------------------------------*/

#define UT_OS_GENERIC_MODULE_NAME1 "/cf/MODULE.obj"
#define UT_OS_GENERIC_MODULE_NAME2 "/cf/MODULE1.obj"
#define UT_OS_SPECIFIC_MODULE_NAME "/cf/MODULE%d.obj"

/*--------------------------------------------*/
#else /* For any other OS assume Linux/POSIX style .so files */
/*--------------------------------------------*/

#define UT_OS_GENERIC_MODULE_NAME1 "/cf/MODULE.so"
#define UT_OS_GENERIC_MODULE_NAME2 "/cf/MODULE1.so"
#define UT_OS_SPECIFIC_MODULE_NAME "/cf/MODULE%d.so"

#endif
#define UT_OS_GENERIC_MODULE_NAME_TEMPLATE UT_OS_GENERIC_MODULE_BASENAME "%d"
#define UT_OS_GENERIC_MODULE_FILE_TEMPLATE UT_OS_GENERIC_MODULE_DIR UT_OS_GENERIC_MODULE_NAME_TEMPLATE OS_MODULE_FILE_EXTENSION

/*--------------------------------------------------------------------------------*
** Data types
Expand Down

0 comments on commit b251466

Please sign in to comment.