From a74cf3219c7fc34e922498ade4ae15415fabf336 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 30 Mar 2024 08:54:42 +0800 Subject: [PATCH] feat update --- CMakeLists.txt | 69 ++++++++++++++++--------------- include/sled/system/thread_pool.h | 5 ++- src/async/async_test.cc | 6 +-- src/sanitizer_test.cc | 1 + 4 files changed, 40 insertions(+), 41 deletions(-) create mode 100644 src/sanitizer_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 89fea01..2253d19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,19 +24,19 @@ add_subdirectory(3party/asyncplusplus EXCLUDE_FROM_ALL) # add_subdirectory(3party/cppuprofile EXCLUDE_FROM_ALL) # add_subdirectory(3party/protobuf-3.21.12 EXCLUDE_FROM_ALL) if(NOT TARGET marl) - add_subdirectory(3party/marl EXCLUDE_FROM_ALL) + add_subdirectory(3party/marl EXCLUDE_FROM_ALL) endif() if(NOT TARGET rpc_core) - add_subdirectory(3party/rpc_core EXCLUDE_FROM_ALL) + add_subdirectory(3party/rpc_core EXCLUDE_FROM_ALL) endif() if(NOT TARGET fmt) - add_subdirectory(3party/fmt EXCLUDE_FROM_ALL) + add_subdirectory(3party/fmt EXCLUDE_FROM_ALL) endif() if(SLED_LOCATION_PATH) - target_compile_definitions( + target_compile_definitions( sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}") endif() # add_subdirectory(3party/eigen EXCLUDE_FROM_ALL) @@ -44,8 +44,7 @@ target_include_directories(sled PUBLIC include 3party/eigen 3party/inja 3party/rxcpp) target_sources( sled - PRIVATE - src/async/async.cc + PRIVATE src/async/async.cc src/filesystem/path.cc src/log/log.cc src/network/async_resolver.cc @@ -84,16 +83,14 @@ target_sources( include(CheckCCompilerFlag) check_c_compiler_flag("-Wl,--whole-archive" SUPPORT_COMPILE_WHOLE_ARCHIVE) if(SUPPORT_COMPILE_WHOLE_ARCHIVE) - set(WHOLE_ARCHIVE_WRAPPER_START "-Wl,--whole-archive") - set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive") + set(WHOLE_ARCHIVE_WRAPPER_START "-Wl,--whole-archive") + set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive") endif() target_link_libraries( sled - PUBLIC rpc_core fmt marl - Async++ - # protobuf::libprotobuf - # ${WHOLE_ARCHIVE_WRAPPER_START} + PUBLIC rpc_core fmt marl Async++ + # protobuf::libprotobuf ${WHOLE_ARCHIVE_WRAPPER_START} tcmalloc_and_profiler_static # ${WHOLE_ARCHIVE_WRAPPER_END} ) @@ -102,33 +99,33 @@ target_link_libraries( set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON) if(SLED_BUILD_BENCHMARK) - if(NOT TARGET benchmark) - find_package(benchmark REQUIRED) - endif() + if(NOT TARGET benchmark) + find_package(benchmark REQUIRED) + endif() - add_executable( + add_executable( sled_benchmark src/random_bench.cc src/strings/base64_bench.cc src/system/fiber/fiber_bench.cc src/system/thread_pool_bench.cc src/system_time_bench.cc) - target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark + target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark benchmark::benchmark_main) endif(SLED_BUILD_BENCHMARK) if(SLED_BUILD_TESTS) - include(FetchContent) - FetchContent_Declare( + include(FetchContent) + FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip ) - FetchContent_MakeAvailable(googletest) - add_executable( + FetchContent_MakeAvailable(googletest) + add_executable( sled_tests # src/exec/just_test.cc src/async/async_test.cc src/any_test.cc src/filesystem/path_test.cc - src/futures/promise_test.cc + # src/futures/promise_test.cc src/futures/detail/just_test.cc src/log/fmt_test.cc # src/profiling/profiling_test.cc @@ -141,23 +138,27 @@ if(SLED_BUILD_TESTS) src/system/thread_pool_test.cc src/rx_test.cc src/uri_test.cc) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(sled_tests PRIVATE -Wthread-safety) - endif() - target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main) - add_test(NAME sled_tests COMMAND sled_tests) + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(EXTRA_FLAGS -Wthread-safety -g -fsanitize=address + -fno-omit-frame-pointer -fno-optimize-sibling-calls) + target_compile_options(sled_tests PRIVATE ${EXTRA_FLAGS}) + + target_link_options(sled_tests PRIVATE ${EXTRA_FLAGS}) + endif() + target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main) + add_test(NAME sled_tests COMMAND sled_tests) endif(SLED_BUILD_TESTS) if(SLED_BUILD_FUZZ) - macro(add_fuzz_test name sources) - add_executable(${name} ${sources}) - target_link_libraries(${name} PRIVATE sled) - target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address + macro(add_fuzz_test name sources) + add_executable(${name} ${sources}) + target_link_libraries(${name} PRIVATE sled) + target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp) - target_link_options(${name} PRIVATE -fsanitize=fuzzer,address + target_link_options(${name} PRIVATE -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp) - endmacro() + endmacro() - add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc) + add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc) endif(SLED_BUILD_FUZZ) diff --git a/include/sled/system/thread_pool.h b/include/sled/system/thread_pool.h index 05fc6b5..c2ccdda 100644 --- a/include/sled/system/thread_pool.h +++ b/include/sled/system/thread_pool.h @@ -20,9 +20,10 @@ public: auto submit(F &&f, Args &&...args) -> std::future { std::function func = std::bind(std::forward(f), std::forward(args)...); - auto task_ptr = std::make_shared>(func); + auto task_ptr = std::make_shared>(func); + auto future = task_ptr->get_future(); scheduler_->enqueue(marl::Task([task_ptr]() { (*task_ptr)(); })); - return task_ptr->get_future(); + return future; } void Delete() override; diff --git a/src/async/async_test.cc b/src/async/async_test.cc index 14c1d50..d06468b 100644 --- a/src/async/async_test.cc +++ b/src/async/async_test.cc @@ -27,9 +27,5 @@ TEST(Async, parallel_for) TEST(Async, parallel_reduce) { - auto r = async::parallel_reduce(async::irange(1, 5), 0, [](int x, int y) { - LOGD("", "{},{}", x, y); - return x + y; - }); - LOGD("", "{}", r); + auto r = async::parallel_reduce(async::irange(1, 5), 0, [](int x, int y) { return x + y; }); } diff --git a/src/sanitizer_test.cc b/src/sanitizer_test.cc new file mode 100644 index 0000000..2180533 --- /dev/null +++ b/src/sanitizer_test.cc @@ -0,0 +1 @@ +#include