diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..40bcc896a23f16272fee29d25bc09c48da96b85d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,321 @@ +cmake_minimum_required(VERSION 3.2) + +project(distributed_ut VERSION 1.0.0) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17 -pthread") + +add_compile_options(-Werror=sign-compare -Werror=unused-variable) +add_compile_options(-Wno-conversion-null) +add_compile_options(-Wuninitialized) +add_compile_options(-Wformat) +add_compile_options(-Wno-deprecated-declarations) + +# Address Sanitizer +option(USE_ASAN "Compile with address sanitiser" OFF) +if (USE_ASAN) + message(STATUS "Compile with address sanitiser ${USE_ASAN}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1") +endif() + +function(download_repo repo_name repo_url) + execute_process( + COMMAND [ -d ${repo_name} ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE REPO_EXISTS + ) + message(STATUS "check ${repo_name} exists result: ${REPO_EXISTS}") + if (NOT (${REPO_EXISTS} EQUAL 0)) + message(STATUS "Downloading ${repo_name} from ${repo_url}") + separate_arguments(repo_url) + execute_process( + COMMAND git clone ${repo_url} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + ) + message(STATUS "Download ${repo_name} finished") + endif() +endfunction(download_repo) + +# create third_party directory +execute_process( + COMMAND mkdir -p ${PROJECT_SOURCE_DIR}/third_party + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + +# Download dependencies +download_repo("third_party_jsoncpp" "https://gitee.com/openharmony/third_party_jsoncpp.git") +download_repo("third_party_googletest" "https://gitee.com/openharmony/third_party_googletest.git") +download_repo("third_party_openssl" "https://gitee.com/openharmony/third_party_openssl.git") +download_repo("third_party_zlib" "https://gitee.com/openharmony/third_party_zlib.git") +download_repo("third_party_sqlite" "https://gitee.com/openharmony/third_party_sqlite.git") +download_repo("utils_native" "https://gitee.com/openharmony/utils_native.git") +download_repo("kate" "https://gitee.com/lianhuix/kate.git") +download_repo("third_party_cJSON" "https://gitee.com/openharmony/third_party_cJSON.git") +download_repo("resourceschedule_ffrt" " -b weekly_20231127 https://gitee.com/openharmony/resourceschedule_ffrt.git") + +function(build_repo repo_name script_path) + execute_process( + COMMAND [ -f ${repo_name}/Makefile ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE SCRIPT_EXISTS + ) + if (NOT (${SCRIPT_EXISTS} EQUAL 0)) + message(STATUS "Copy build script ${script_path}/Makefile to repo ${repo_name}") + execute_process( + COMMAND cp third_party/kate/${script_path}/Makefile third_party/${repo_name} -f + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + message(STATUS "Build ${repo_name}") + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + message(STATUS "Build finished") + endif() +endfunction(build_repo) + +function(cmake_repo repo_name) + execute_process( + COMMAND [ -d ${repo_name}/build ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE BUILD_FINISHED + ) + if (NOT (${BUILD_FINISHED} EQUAL 0)) + message(STATUS "compile repo ${repo_name}") + execute_process( + COMMAND mkdir -p build + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND cmake .. + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build + ) + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build + ) + endif() +endfunction(cmake_repo) + +function(build_openssl repo_name) + execute_process( + COMMAND [ -f Makefile ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + RESULT_VARIABLE BUILD_FINISHED + ) + if (NOT (${BUILD_FINISHED} EQUAL 0)) + message(STATUS "compile repo ${repo_name}") + execute_process( + COMMAND chmod +x ./config + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND ./config + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + endif() +endfunction(build_openssl) + +function(build_ffrt repo_name) + execute_process( + COMMAND [ -f Makefile ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + RESULT_VARIABLE BUILD_FINISHED + ) + if (NOT (${BUILD_FINISHED} EQUAL 0)) + message(STATUS "compile repo ${repo_name}") + execute_process( + COMMAND cmake -DFFRT_EXAMPLE=OFF -DFFRT_CLANG_COMPILE=OFF ./ + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + endif() +endfunction(build_ffrt) + +# build openssl Makefile +build_openssl("third_party_openssl") + +# build securec +build_repo("utils_native" "securec") + +# build sqlite +build_repo("third_party_sqlite" "sqlite") + +# build jsoncpp +cmake_repo("third_party_jsoncpp") + +# build zlib +cmake_repo("third_party_zlib") + +# build cJSON +cmake_repo("third_party_cJSON" "cJSON") + +# build ffrt +build_ffrt("resourceschedule_ffrt") + +#build googletest +execute_process( + COMMAND sed -i /Wshadow/d internal_utils.cmake + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/cmake +) +execute_process( + COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googlemock/src/gmock_main.cc + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest +) +execute_process( + COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googletest/src/gtest_main.cc + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest +) +cmake_repo("third_party_googletest") + +# add_definitions(-Wno-format) +add_definitions(-DSQLITE_ENABLE_SNAPSHOT) +add_definitions(-D_LARGEFILE64_SOURCE) +add_definitions(-D_FILE_OFFSET_BITS=64) +add_definitions(-DSQLITE_HAS_CODEC) +add_definitions(-DSQLITE_ENABLE_JSON1) +add_definitions(-DUSING_HILOG_LOGGER) +# add_definitions(-DUSE_SQLITE_SYMBOLS) +add_definitions(-DUSING_DB_JSON_EXTRACT_AUTOMATICALLY) +add_definitions(-DJSONCPP_USE_BUILDER) +add_definitions(-DOMIT_FLATBUFFER) +add_definitions(-DUSE_PRINT) +add_definitions(-DRELATIONAL_STORE) +add_definitions(-DMANNUAL_SYNC_AND_CLEAN_CLOUD_DATA) +# add_definitions(-DSQLITE3_HW_EXPORT_SYMBOLS) +add_definitions(-DTEST_DB) +add_definitions(-DDB_DEBUG_ENV) +add_definitions(-DTESTCASES_USING_GTEST_EXT) +add_definitions(-DSQLITE_DISTRIBUTE_RELATIONAL) +add_definitions(-DSQLITE_ENABLE_DROPTABLE_CALLBACK) +add_definitions(-DRUNNING_ON_TESTCASE) +add_definitions(-DOMIT_MULTI_VER) +add_definitions(-DUSE_FFRT) + +# build cJSON +#cmake_repo("third_party_cJSON" "cJSON") + +add_definitions(-DDB_DEBUG_ENV) + +find_package(Threads) +enable_testing() + +set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb) + +include_directories( + ${DB_PATH}/common/include + ${DB_PATH}/common/include/relational + ${DB_PATH}/common/include/cloud + ${DB_PATH}/common/src + ${DB_PATH}/common/src/evloop/include + ${DB_PATH}/common/src/evloop/src + ${DB_PATH}/common/src/cloud + ${DB_PATH}/communicator/include + ${DB_PATH}/communicator/src + ${DB_PATH}/include + ${DB_PATH}/interfaces/include + ${DB_PATH}/interfaces/include/cloud + ${DB_PATH}/interfaces/include/relational + ${DB_PATH}/interfaces/src + ${DB_PATH}/interfaces/src/relational + ${DB_PATH}/storage/include + ${DB_PATH}/storage/src + ${DB_PATH}/storage/src/multiver + ${DB_PATH}/storage/src/operation + ${DB_PATH}/storage/src/sqlite + ${DB_PATH}/storage/src/naturalbase_lite + ${DB_PATH}/storage/src/sqlite/relational + ${DB_PATH}/storage/src/upgrader + ${DB_PATH}/storage/src/gaussdb_rd + ${DB_PATH}/syncer/include + ${DB_PATH}/syncer/src + ${DB_PATH}/syncer/src/cloud + ${DB_PATH}/test/unittest/common/common + ${DB_PATH}/test/unittest/common/communicator + ${DB_PATH}/test/unittest/common/interfaces + ${DB_PATH}/test/unittest/common/storage + ${DB_PATH}/test/unittest/common/syncer + ${DB_PATH}/test/unittest/common/syncer/cloud +) + +include_directories( + ${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googlemock/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_jsoncpp/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite/include + ${PROJECT_SOURCE_DIR}/third_party/utils_native/base/include + ${PROJECT_SOURCE_DIR}/third_party/utils_native/base/src/securec + ${PROJECT_SOURCE_DIR}/third_party/third_party_openssl/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_zlib + ${PROJECT_SOURCE_DIR}/third_party/kate/log/include + ${PROJECT_SOURCE_DIR}/third_party/resourceschedule_ffrt/interfaces/kits +) + +link_directories( + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/build/lib + ${PROJECT_SOURCE_DIR}/third_party/third_party_jsoncpp/build/lib + ${PROJECT_SOURCE_DIR}/third_party/third_party_openssl + ${PROJECT_SOURCE_DIR}/third_party/third_party_zlib/build + ${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite + ${PROJECT_SOURCE_DIR}/third_party/utils_native + ${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON/build + ${PROJECT_SOURCE_DIR}/third_party/resourceschedule_ffrt/src +) + +message("DB_PATH = ${DB_PATH}") +file(GLOB_RECURSE DISTRIBUTEDDB_SRC "${DB_PATH}/*.cpp") + +list(REMOVE_ITEM DISTRIBUTEDDB_SRC "${DB_PATH}/test/unittest/common/storage/distributeddb_storage_encrypt_test.cpp") +file(GLOB_RECURSE RD_SRC "${DB_PATH}/gaussdb_rd/*.cpp") +list(REMOVE_ITEM DISTRIBUTEDDB_SRC ${RD_SRC}) + +foreach (ITR ${DISTRIBUTEDDB_SRC}) + if ("${ITR}" MATCHES "(.*)moduletest(.*)") + # message(STATUS"Remove Item from List:${ITR}") + list (REMOVE_ITEM DISTRIBUTEDDB_SRC ${ITR}) + endif ("${ITR}" MATCHES "(.*)moduletest(.*)") +endforeach(ITR) + +file(GLOB_RECURSE FUZZTEST_SRC "${DB_PATH}/test/fuzztest/*.cpp") + +if(FUZZTEST_SRC) + list(REMOVE_ITEM DISTRIBUTEDDB_SRC ${FUZZTEST_SRC}) +endif() + +set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb) + +add_executable(distributed_ut ${DISTRIBUTEDDB_SRC} ${SECUREC_SRC} ${SQLITE_SRC}) + +target_include_directories(distributed_ut PUBLIC + ${DB_PATH}/gaussdb_rd/include + ${DB_PATH}/gaussdb_rd/include/grd_base + ${DB_PATH}/gaussdb_rd/include/grd_document + ${DB_PATH}/gaussdb_rd/include/grd_kv ) + +target_link_libraries( + distributed_ut + pthread + ${CMAKE_THREAD_LIBS_INIT} + ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb/gaussdb_rd/build/libdocument_rd.a + securec + jsoncpp + ssl + crypto + sqlite3 + z + gtest + gtest_main + cjson + gmock + gmock_main + dl + gcov + ffrt +) \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/CMakeLists.txt b/frameworks/libs/distributeddb/gaussdb_rd/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c521e5114d9785394c0c7b398e921eccd5c3d79 --- /dev/null +++ b/frameworks/libs/distributeddb/gaussdb_rd/CMakeLists.txt @@ -0,0 +1,240 @@ +cmake_minimum_required(VERSION 3.2) + +project(gaussdb_rd VERSION 1.0.0) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++17 -pthread") + +add_compile_options(-Werror=sign-compare) +add_compile_options(-Werror=unused-variable) +add_compile_options(-Wno-conversion-null) +add_compile_options(-Wuninitialized) +add_compile_options(-Wformat) +add_compile_options(-Wno-deprecated-declarations) + +# Address Sanitizer +option(USE_ASAN "Compile with address sanitiser" OFF) +if (USE_ASAN) + message(STATUS "Compile with address sanitiser ${USE_ASAN}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O0") +endif() + +function(download_repo repo_name repo_url) + execute_process( + COMMAND [ -d ${repo_name} ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE REPO_EXISTS + ) + message(STATUS "check ${repo_name} exists result: ${REPO_EXISTS}") + if (NOT (${REPO_EXISTS} EQUAL 0)) + message(STATUS "Downloading ${repo_name} from ${repo_url}") + execute_process( + COMMAND git clone ${repo_url} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + ) + message(STATUS "Download ${repo_name} finished") + endif() +endfunction(download_repo) + +function(build_repo repo_name script_path) + execute_process( + COMMAND [ -f ${repo_name}/Makefile ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE SCRIPT_EXISTS + ) + if (NOT (${SCRIPT_EXISTS} EQUAL 0)) + message(STATUS "Copy build script ${script_path}/Makefile to repo ${repo_name}") + execute_process( + COMMAND cp third_party/kate/${script_path}/Makefile third_party/${repo_name} -f + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + message(STATUS "Build ${repo_name}") + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + message(STATUS "Build finished") + endif() +endfunction(build_repo) + +function(cmake_repo repo_name) + execute_process( + COMMAND [ -d ${repo_name}/build ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party + RESULT_VARIABLE BUILD_FINISHED + ) + if (NOT (${BUILD_FINISHED} EQUAL 0)) + message(STATUS "compile repo ${repo_name}") + execute_process( + COMMAND mkdir -p build + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND cmake .. + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build + ) + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name}/build + ) + endif() +endfunction(cmake_repo) + +function(build_openssl repo_name) + execute_process( + COMMAND [ -f Makefile ] + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + RESULT_VARIABLE BUILD_FINISHED + ) + if (NOT (${BUILD_FINISHED} EQUAL 0)) + message(STATUS "compile repo ${repo_name}") + execute_process( + COMMAND chmod +x ./config + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND ./config + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + execute_process( + COMMAND make -j9 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/${repo_name} + ) + endif() +endfunction(build_openssl) + +# create third_party directory +execute_process( + COMMAND mkdir -p ${PROJECT_SOURCE_DIR}/third_party + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + +# Download dependencies +download_repo("third_party_cJSON" "https://gitee.com/openharmony/third_party_cJSON.git") +download_repo("third_party_googletest" "https://gitee.com/openharmony/third_party_googletest.git") +download_repo("third_party_openssl" "https://gitee.com/openharmony/third_party_openssl.git") +download_repo("third_party_sqlite" "https://gitee.com/openharmony/third_party_sqlite.git") +download_repo("utils_native" "https://gitee.com/openharmony/utils_native.git") +download_repo("kate" "https://gitee.com/Jeremyzz/kate.git") + +# build cJSON +cmake_repo("third_party_cJSON" "cJSON") + +# build openssl Makefile +build_openssl("third_party_openssl") + +# build securec +build_repo("utils_native" "securec") + +# build sqlite +build_repo("third_party_sqlite" "sqlite") + +#build googletest +execute_process( + COMMAND sed -i /Wshadow/d internal_utils.cmake + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/cmake +) +execute_process( + COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googlemock/src/gmock_main.cc + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest +) +execute_process( + COMMAND sed -i "s%testing::GTEST_FLAG(output)%// testing::GTEST_FLAG(output)%g" googletest/src/gtest_main.cc + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest +) +cmake_repo("third_party_googletest") + +add_definitions(-DDB_DEBUG_ENV) + +# build coverage rate +add_definitions(-fprofile-arcs) +add_definitions(-ftest-coverage) + +find_package(Threads) +enable_testing() + +set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb) + +file(GLOB_RECURSE DOCUMENT_SRC "${PROJECT_SOURCE_DIR}/src/*.cpp") +file(GLOB_RECURSE DOCUMENT_TEST "${PROJECT_SOURCE_DIR}/test/unittest/*.cpp") + +include_directories( + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src/storage + ${PROJECT_SOURCE_DIR}/src/storage/include + ${PROJECT_SOURCE_DIR}/src/storage/src + ${PROJECT_SOURCE_DIR}/src/common + ${PROJECT_SOURCE_DIR}/src/common/include + ${PROJECT_SOURCE_DIR}/src/executor/include + ${PROJECT_SOURCE_DIR}/src/executor/base + ${PROJECT_SOURCE_DIR}/src/executor/document + ${PROJECT_SOURCE_DIR}/src/oh_adapter + ${PROJECT_SOURCE_DIR}/src/oh_adapter/include + ${PROJECT_SOURCE_DIR}/src/oh_adapter/src + ${PROJECT_SOURCE_DIR}/src/interface + ${PROJECT_SOURCE_DIR}/src/interface/include + ${PROJECT_SOURCE_DIR}/src/interface/src + +) +include_directories( + ${PROJECT_SOURCE_DIR}/test/unittest/common +) + +set(DISTRIBUTEDDB_PATH ${PROJECT_SOURCE_DIR}/third_party/distributeddatamgr_kv_store/frameworks/libs/distributeddb/) +include_directories( + ${DISTRIBUTEDDB_PATH}/include + ${DISTRIBUTEDDB_PATH}/interfaces/include +) + +include_directories( + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googletest/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/googlemock/include + ${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON + ${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite/include + ${PROJECT_SOURCE_DIR}/third_party/utils_native/base/include + ${PROJECT_SOURCE_DIR}/third_party/utils_native/base/src/securec + ${PROJECT_SOURCE_DIR}/third_party/third_party_openssl/include + ${PROJECT_SOURCE_DIR}/third_party/kate/log/include +) + +link_directories( + ${PROJECT_SOURCE_DIR}/third_party/third_party_googletest/build/lib + ${PROJECT_SOURCE_DIR}/third_party/third_party_cJSON/build + ${PROJECT_SOURCE_DIR}/third_party/third_party_openssl + ${PROJECT_SOURCE_DIR}/third_party/third_party_sqlite + ${PROJECT_SOURCE_DIR}/third_party/utils_native +) + +add_executable(document_ut ${DOCUMENT_SRC} ${DOCUMENT_TEST}) +add_library(document_rd ${DOCUMENT_SRC}) + +target_link_libraries(document_ut + cjson + + sqlite3 + securec + ssl + crypto + + gtest + gtest_main + gmock + gmock_main + gcov + dl +) + +target_link_libraries(document_rd + cjson + + sqlite3 + securec + ssl + crypto + + gtest + gtest_main + gmock + gmock_main + gcov + dl +) \ No newline at end of file