Merge pull request #7459 from sfc-gh-ljoswiak/features/module-link-tests

Add test executables to catch missing symbols in modules
This commit is contained in:
Markus Pilman 2022-07-11 17:31:11 -06:00 committed by GitHub
commit fa9e623fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 4 deletions

View File

@ -189,7 +189,7 @@ endfunction()
function(add_flow_target)
set(options EXECUTABLE STATIC_LIBRARY
DYNAMIC_LIBRARY)
DYNAMIC_LIBRARY LINK_TEST)
set(oneValueArgs NAME)
set(multiValueArgs SRCS COVERAGE_FILTER_OUT DISABLE_ACTOR_DIAGNOSTICS ADDL_SRCS)
cmake_parse_arguments(AFT "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
@ -277,6 +277,12 @@ function(add_flow_target)
set(strip_target ON)
add_library(${AFT_NAME} DYNAMIC ${sources} ${AFT_ADDL_SRCS})
endif()
if(AFT_LINK_TEST)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/linktest)
set(strip_target ON)
set(target_type exec)
add_executable(${AFT_NAME} ${sources} ${AFT_ADDL_SRCS})
endif()
foreach(src IN LISTS sources AFT_ADDL_SRCS)
get_filename_component(dname ${CMAKE_CURRENT_SOURCE_DIR} NAME)

View File

@ -45,6 +45,7 @@ static unsigned int crc32_align(unsigned int crc, unsigned char* p, unsigned lon
unsigned int CRC32_FUNCTION_ASM(unsigned int crc, unsigned char* p, unsigned long len);
unsigned int CRC32_FUNCTION(unsigned int crc, unsigned char* p, unsigned long len) {
#ifdef __powerpc64 // avoid link failures on systems without CRC32_FUNCTION_ASM declared
unsigned int prealign;
unsigned int tail;
@ -76,6 +77,6 @@ out:
#ifdef CRC_XOR
crc ^= 0xffffffff;
#endif
#endif
return crc;
}

View File

@ -89,6 +89,9 @@ if(WIN32)
add_dependencies(fdbclient_sampling_actors fdbclient_actors)
endif()
add_flow_target(LINK_TEST NAME fdbclientlinktest SRCS ${FDBCLIENT_SRCS} LinkTest.cpp ADDL_SRCS ${options_srcs})
target_link_libraries(fdbclientlinktest PRIVATE fdbclient rapidxml) # re-link rapidxml due to private link interface
if(BUILD_AZURE_BACKUP)
target_link_libraries(fdbclient PRIVATE curl uuid azure-storage-lite)
target_link_libraries(fdbclient_sampling PRIVATE curl uuid azure-storage-lite)

8
fdbclient/LinkTest.cpp Normal file
View File

@ -0,0 +1,8 @@
// When creating a static or shared library, undefined symbols will be ignored.
// Since we want to ensure no symbols from other modules are used, each module
// will create an executable so the linker will throw errors if it can't find
// the declaration of a symbol. This class defines a dummy main function so the
// executable can be built.
int main() {
return 0;
}

View File

@ -25,6 +25,10 @@ add_flow_target(STATIC_LIBRARY NAME fdbrpc_sampling
SRCS ${FDBRPC_SRCS}
DISABLE_ACTOR_DIAGNOSTICS ${FDBRPC_SRCS_DISABLE_ACTOR_DIAGNOSTICS})
add_flow_target(LINK_TEST NAME fdbrpclinktest SRCS ${FDBRPC_SRCS} LinkTest.cpp DISABLE_ACTOR_DIAGNOSTICS ${FDBRPC_SRCS_DISABLE_ACTOR_DIAGNOSTICS})
target_link_libraries(fdbrpclinktest PRIVATE fdbrpc rapidjson)
target_include_directories(fdbrpclinktest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libeio)
if(COMPILE_EIO)
add_library(eio STATIC libeio/eio.c)
if(USE_VALGRIND)

8
fdbrpc/LinkTest.cpp Normal file
View File

@ -0,0 +1,8 @@
// When creating a static or shared library, undefined symbols will be ignored.
// Since we want to ensure no symbols from other modules are used, each module
// will create an executable so the linker will throw errors if it can't find
// the declaration of a symbol. This class defines a dummy main function so the
// executable can be built.
int main() {
return 0;
}

View File

@ -2,6 +2,10 @@ find_package(Threads REQUIRED)
fdb_find_sources(FLOW_SRCS)
# Remove files with `main` defined so we can create a link test executable.
list(REMOVE_ITEM FLOW_SRCS TLSTest.cpp)
list(REMOVE_ITEM FLOW_SRCS MkCertCli.cpp)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
list(APPEND FLOW_SRCS aarch64/memcmp.S aarch64/memcpy.S)
endif()
@ -13,7 +17,14 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY
add_flow_target(STATIC_LIBRARY NAME flow SRCS ${FLOW_SRCS})
add_flow_target(STATIC_LIBRARY NAME flow_sampling SRCS ${FLOW_SRCS})
foreach(ft flow flow_sampling)
# When creating a static or shared library, undefined symbols will be ignored.
# Since we want to ensure no symbols from other modules are used, create an
# executable so the linker will throw errors if it can't find the declaration
# of a symbol.
add_flow_target(LINK_TEST NAME flowlinktest SRCS ${FLOW_SRCS} LinkTest.cpp)
target_link_libraries(flowlinktest PRIVATE flow stacktrace)
foreach(ft flow flow_sampling flowlinktest)
target_include_directories(${ft} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include")
target_link_libraries(${ft} PRIVATE stacktrace)
@ -68,7 +79,6 @@ if(WIN32)
add_dependencies(flow_sampling_actors flow_actors)
endif()
add_executable(mkcert MkCertCli.cpp)
target_link_libraries(mkcert PUBLIC flow)

8
flow/LinkTest.cpp Normal file
View File

@ -0,0 +1,8 @@
// When creating a static or shared library, undefined symbols will be ignored.
// Since we want to ensure no symbols from other modules are used, each module
// will create an executable so the linker will throw errors if it can't find
// the declaration of a symbol. This class defines a dummy main function so the
// executable can be built.
int main() {
return 0;
}