From d316f18cbc60815c66725c9c3975cc57ab42fbcf Mon Sep 17 00:00:00 2001 From: XuPeng-SH Date: Wed, 18 Dec 2019 18:11:18 +0800 Subject: [PATCH] Integrate libfiu for fault injection (#784) * (feat): add libfiu for fault injection * (feat): change libfiu from static to shared * (feat): install libfiu --- core/CMakeLists.txt | 4 +++ core/build.sh | 8 ++++- core/cmake/DefineOptions.cmake | 2 ++ core/cmake/ThirdPartyPackages.cmake | 53 ++++++++++++++++++++++++++++- core/src/CMakeLists.txt | 4 +++ core/thirdparty/versions.txt | 1 + core/unittest/CMakeLists.txt | 1 + 7 files changed, 71 insertions(+), 2 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 760a32fdb3..4290bc74fd 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -178,6 +178,10 @@ if (MILVUS_WITH_PROMETHEUS) add_compile_definitions("MILVUS_WITH_PROMETHEUS") endif () +if (MILVUS_WITH_FIU) + add_compile_definitions("FIU_ENABLE") +endif () + if (CMAKE_BUILD_TYPE STREQUAL "Release") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp") if (MILVUS_GPU_VERSION) diff --git a/core/build.sh b/core/build.sh index badcc5a032..f1a9f9406d 100755 --- a/core/build.sh +++ b/core/build.sh @@ -17,8 +17,9 @@ WITH_MKL="OFF" FAISS_ROOT="" #FAISS root path FAISS_SOURCE="BUNDLED" WITH_PROMETHEUS="ON" +FIU_ENABLE="OFF" -while getopts "p:d:t:f:ulrcgjhxzme" arg; do +while getopts "p:d:t:f:ulrcgjhxzmei" arg; do case $arg in p) INSTALL_PREFIX=$OPTARG @@ -67,6 +68,9 @@ while getopts "p:d:t:f:ulrcgjhxzme" arg; do e) WITH_PROMETHEUS="OFF" ;; + i) + FIU_ENABLE="ON" + ;; h) # help echo " @@ -86,6 +90,7 @@ parameter: -g: build GPU version(default: OFF) -m: build with MKL(default: OFF) -e: build without prometheus(default: OFF) +-i: build FIU_ENABLE(default: OFF) -h: help usage: @@ -125,6 +130,7 @@ CMAKE_CMD="cmake \ -DMILVUS_GPU_VERSION=${GPU_VERSION} \ -DFAISS_WITH_MKL=${WITH_MKL} \ -DMILVUS_WITH_PROMETHEUS=${WITH_PROMETHEUS} \ +-DMILVUS_WITH_FIU=${FIU_ENABLE} ../" echo ${CMAKE_CMD} ${CMAKE_CMD} diff --git a/core/cmake/DefineOptions.cmake b/core/cmake/DefineOptions.cmake index 5206da864d..8f5a42420a 100644 --- a/core/cmake/DefineOptions.cmake +++ b/core/cmake/DefineOptions.cmake @@ -87,6 +87,8 @@ define_option(MILVUS_WITH_ZLIB "Build with zlib compression" ON) define_option(MILVUS_WITH_OPENTRACING "Build with Opentracing" ON) +define_option(MILVUS_WITH_FIU "Build with fiu" OFF) + #---------------------------------------------------------------------- set_option_category("Test and benchmark") diff --git a/core/cmake/ThirdPartyPackages.cmake b/core/cmake/ThirdPartyPackages.cmake index 8d767f8200..28ab35746c 100644 --- a/core/cmake/ThirdPartyPackages.cmake +++ b/core/cmake/ThirdPartyPackages.cmake @@ -26,7 +26,8 @@ set(MILVUS_THIRDPARTY_DEPENDENCIES gperftools GRPC ZLIB - Opentracing) + Opentracing + fiu) message(STATUS "Using ${MILVUS_DEPENDENCY_SOURCE} approach to find dependencies") @@ -60,6 +61,8 @@ macro(build_dependency DEPENDENCY_NAME) build_zlib() elseif ("${DEPENDENCY_NAME}" STREQUAL "Opentracing") build_opentracing() + elseif ("${DEPENDENCY_NAME}" STREQUAL "fiu") + build_fiu() else () message(FATAL_ERROR "Unknown thirdparty dependency to build: ${DEPENDENCY_NAME}") endif () @@ -348,6 +351,12 @@ else () set(OPENTRACING_SOURCE_URL "https://github.com/opentracing/opentracing-cpp/archive/${OPENTRACING_VERSION}.tar.gz") endif () +if (DEFINED ENV{MILVUS_FIU_URL}) + set(MILVUS_FIU_URL "$ENV{MILVUS_FIU_URL}") +else () + set(FIU_SOURCE_URL "https://github.com/albertito/libfiu/archive/${FIU_VERSION}.tar.gz") +endif () + # ---------------------------------------------------------------------- # Google gtest @@ -1268,3 +1277,45 @@ if (MILVUS_WITH_OPENTRACING) get_target_property(OPENTRACING_INCLUDE_DIR opentracing INTERFACE_INCLUDE_DIRECTORIES) include_directories(SYSTEM ${OPENTRACING_INCLUDE_DIR}) endif () + +# ---------------------------------------------------------------------- +# fiu + +macro(build_fiu) + message(STATUS "Building FIU-${FIU_VERSION} from source") + set(FIU_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/fiu_ep-prefix/src/fiu_ep") + set(FIU_SHARED_LIB "${FIU_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}fiu${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(FIU_INCLUDE_DIR "${FIU_PREFIX}/include") + + externalproject_add(fiu_ep + URL + ${FIU_SOURCE_URL} + ${EP_LOG_OPTIONS} + CONFIGURE_COMMAND + "" + BUILD_IN_SOURCE + 1 + BUILD_COMMAND + ${MAKE} + ${MAKE_BUILD_ARGS} + INSTALL_COMMAND + ${MAKE} + "PREFIX=${FIU_PREFIX}" + install + BUILD_BYPRODUCTS + ${FIU_SHARED_LIB} + ) + + file(MAKE_DIRECTORY "${FIU_INCLUDE_DIR}") + add_library(fiu SHARED IMPORTED) + set_target_properties(fiu + PROPERTIES IMPORTED_LOCATION "${FIU_SHARED_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${FIU_INCLUDE_DIR}") + + add_dependencies(fiu fiu_ep) +endmacro() + +resolve_dependency(fiu) + +get_target_property(FIU_INCLUDE_DIR fiu INTERFACE_INCLUDE_DIRECTORIES) +include_directories(SYSTEM ${FIU_INCLUDE_DIR}) diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index b167f86257..7709ed7f16 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -141,6 +141,7 @@ set(third_party_libs yaml-cpp mysqlpp zlib + fiu ${boost_lib} ) @@ -251,6 +252,9 @@ install(FILES ${CMAKE_BINARY_DIR}/mysqlpp_ep-prefix/src/mysqlpp_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlpp${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_BINARY_DIR}/mysqlpp_ep-prefix/src/mysqlpp_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlpp${CMAKE_SHARED_LIBRARY_SUFFIX}.3 ${CMAKE_BINARY_DIR}/mysqlpp_ep-prefix/src/mysqlpp_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlpp${CMAKE_SHARED_LIBRARY_SUFFIX}.3.2.4 + ${CMAKE_BINARY_DIR}/fiu_ep-prefix/src/fiu_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}fiu${CMAKE_SHARED_LIBRARY_SUFFIX} + ${CMAKE_BINARY_DIR}/fiu_ep-prefix/src/fiu_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}fiu${CMAKE_SHARED_LIBRARY_SUFFIX}.0 + ${CMAKE_BINARY_DIR}/fiu_ep-prefix/src/fiu_ep/lib/${CMAKE_SHARED_LIBRARY_PREFIX}fiu${CMAKE_SHARED_LIBRARY_SUFFIX}.1.00 DESTINATION lib) add_subdirectory(sdk) diff --git a/core/thirdparty/versions.txt b/core/thirdparty/versions.txt index e3039b4754..9c531c7d39 100644 --- a/core/thirdparty/versions.txt +++ b/core/thirdparty/versions.txt @@ -10,5 +10,6 @@ GPERFTOOLS_VERSION=2.7 GRPC_VERSION=master ZLIB_VERSION=v1.2.11 OPENTRACING_VERSION=v1.5.1 +FIU_VERSION=1.00 # vim: set filetype=sh: diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index 49c0ca9f55..820559c064 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -128,6 +128,7 @@ set(unittest_libs gfortran opentracing opentracing_mocktracer + fiu ) if (MILVUS_WITH_PROMETHEUS) set(unittest_libs ${unittest_libs}