From b25146641ee3471e5f485efaea1f1a218c88a78f Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 14 May 2020 08:05:37 -0400 Subject: [PATCH] Fix #460, UT dependencies on BSP volume maps Do not assume BSP volume table provides a "/cf" directory map. Instead, create a UT-specific map of a consistent name, and use that. --- osconfig.h.in | 7 ++++ src/tests/file-api-test/file-api-test.c | 19 +++++++-- src/unit-tests/osloader-test/CMakeLists.txt | 2 +- .../osloader-test/ut_osloader_module_test.c | 6 +-- .../osloader-test/ut_osloader_symtable_test.c | 39 ++++++++----------- .../osloader-test/ut_osloader_test.c | 13 +++++++ .../ut_osloader_test_platforms.h | 38 +++--------------- 7 files changed, 61 insertions(+), 63 deletions(-) diff --git a/osconfig.h.in b/osconfig.h.in index 24bee2592..0da988e5b 100644 --- a/osconfig.h.in +++ b/osconfig.h.in @@ -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_ */ diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 502292746..29ca9bb9c 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -27,6 +27,8 @@ os_err_name_t errname; void UtTest_Setup(void) { + uint32 fs_id; + errname[0] = 0; if (OS_API_Init() != OS_SUCCESS) @@ -34,6 +36,15 @@ void UtTest_Setup(void) 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 * @@ -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); diff --git a/src/unit-tests/osloader-test/CMakeLists.txt b/src/unit-tests/osloader-test/CMakeLists.txt index 349a274a5..72152120b 100644 --- a/src/unit-tests/osloader-test/CMakeLists.txt +++ b/src/unit-tests/osloader-test/CMakeLists.txt @@ -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) diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.c b/src/unit-tests/osloader-test/ut_osloader_module_test.c index 7cde3d814..89dadbe8b 100644 --- a/src/unit-tests/osloader-test/ut_osloader_module_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.c @@ -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 ) { diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index 04ce252f8..0f43dcd3a 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -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"; @@ -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; - + } } /*================================================================================* diff --git a/src/unit-tests/osloader-test/ut_osloader_test.c b/src/unit-tests/osloader-test/ut_osloader_test.c index 24d12eb51..7dd6fc9f5 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_test.c @@ -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"); diff --git a/src/unit-tests/osloader-test/ut_osloader_test_platforms.h b/src/unit-tests/osloader-test/ut_osloader_test_platforms.h index fe17b76b3..a1fee6f96 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test_platforms.h +++ b/src/unit-tests/osloader-test/ut_osloader_test_platforms.h @@ -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