diff --git a/include/dsn/tool-api/env_provider.h b/include/dsn/tool-api/env_provider.h index 987acb04f8..0389c8e533 100644 --- a/include/dsn/tool-api/env_provider.h +++ b/include/dsn/tool-api/env_provider.h @@ -56,7 +56,7 @@ class env_provider typedef env_provider *(*factory)(env_provider *); - env_provider(env_provider *inner_provider); + env_provider(env_provider *inner_provider){}; }; /*@}*/ -} // end namespace +} // namespace dsn diff --git a/scripts/linux/build.sh b/scripts/linux/build.sh index 51336c754e..af777316a6 100755 --- a/scripts/linux/build.sh +++ b/scripts/linux/build.sh @@ -190,7 +190,7 @@ echo "################################# start testing ########################## if [ -z "$TEST_MODULE" ] then # supported test module - TEST_MODULE="dsn.core.tests,dsn_perf_counter_test,dsn.zookeeper.tests,dsn_aio_test,dsn.failure_detector.tests,dsn_meta_state_tests,dsn_nfs_test,dsn_block_service_test,dsn.replication.simple_kv,dsn.rep_tests.simple_kv,dsn.meta.test,dsn.replica.test,dsn_http_test,dsn_replica_dup_test,dsn_replica_backup_test,dsn_replica_bulk_load_test" + TEST_MODULE="dsn.core.tests,dsn_utils_tests,dsn_perf_counter_test,dsn.zookeeper.tests,dsn_aio_test,dsn.failure_detector.tests,dsn_meta_state_tests,dsn_nfs_test,dsn_block_service_test,dsn.replication.simple_kv,dsn.rep_tests.simple_kv,dsn.meta.test,dsn.replica.test,dsn_http_test,dsn_replica_dup_test,dsn_replica_backup_test,dsn_replica_bulk_load_test" fi echo "TEST_MODULE=$TEST_MODULE" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 73bea2e230..e46782fee0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,3 +15,4 @@ add_subdirectory(common) add_subdirectory(replica) add_subdirectory(meta) add_subdirectory(tools) +add_subdirectory(utils) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b7e583ec17..f75eb8bcf5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,4 +13,5 @@ add_library(dsn_runtime STATIC $ $ ) +target_link_libraries(dsn_runtime dsn_utils) install(TARGETS dsn_runtime DESTINATION "lib") diff --git a/src/core/core/admission_controller.cpp b/src/core/core/admission_controller.cpp deleted file mode 100644 index b91ae32165..0000000000 --- a/src/core/core/admission_controller.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#include - -namespace dsn { - -// -////-------------------------- BoundedQueueAdmissionController -///-------------------------------------------------- -// -//// arguments: MaxTaskQueueSize -// BoundedQueueAdmissionController::BoundedQueueAdmissionController(task_queue* q, -// std::vector& sargs) -// : admission_controller(q, sargs) -//{ -// if (sargs.size() > 0) -// { -// _maxTaskQueueSize = atoi(sargs[0].c_str()); -// if (_maxTaskQueueSize <= 0) -// { -// dassert (false, "Invalid arguments for BoundedQueueAdmissionController: -// MaxTaskQueueSize = '%s'", sargs[0].c_str()); -// } -// } -// else -// { -// dassert (false, "arguments for BoundedQueueAdmissionController is missing: -// MaxTaskQueueSize"); -// } -//} -// -// BoundedQueueAdmissionController::~BoundedQueueAdmissionController(void) -//{ -//} -// -// bool BoundedQueueAdmissionController::is_task_accepted(task* task) -//{ -// if (InQueueTaskCount() < _maxTaskQueueSize || -// task->spec().pool->shared_same_worker_with_current_task(task)) -// { -// return true; -// } -// else -// { -// return false; -// } -//} -// -// int BoundedQueueAdmissionController::get_system_utilization() -//{ -// return static_cast(100.0 * static_castInQueueTaskCount() / -// static_cast_maxTaskQueueSize); -//} -// -////------------------------------ SingleRpcClassResponseTimeAdmissionController -///---------------------------------------------------------------- -// -//// args: dsn::task_code PercentileType LatencyThreshold100ns(from task create to end in -/// local process) -//// -// -// SingleRpcClassResponseTimeAdmissionController::SingleRpcClassResponseTimeAdmissionController(task_queue* -// q, std::vector& sargs) -// : admission_controller(q, sargs) -//{ -// if (sargs.size() >= 3) -// { -// _rpcCode = enum_from_string(sargs[0].c_str(), TASK_CODE_INVALID); -// _percentile = atoi(sargs[1].c_str()); -// _latencyThreshold100ns = atoi(sargs[2].c_str()); -// -// if (TASK_CODE_INVALID == _rpcCode || task_spec::get(_rpcCode).type != -// TASK_TYPE_RPC_REQUEST -// || _latencyThreshold100ns <= 0 -// || _percentile < 0 -// || _percentile >= 5 -// ) -// { -// dassert (false, "Invalid arguments for SingleRpcClassResponseTimeAdmissionController: -// RpcRequestEventCode PercentileType(0-4) LatencyThreshold100ns\n" -// "\tcounter percentile type (0-4): 999, 99, 95, 90, 50\n"); -// } -// -// _counter = task_spec::get(_rpcCode).rpc_server_latency_100ns; -// } -// else -// { -// dassert (false, "arguments for SingleRpcClassResponseTimeAdmissionController is missing: -// RpcRequestEventCode PercentileType(0-4) LatencyThreshold100ns\n" -// "\tcounter percentile type (0-4): 999, 99, 95, 90, 50\n"); -// } -//} -// -// SingleRpcClassResponseTimeAdmissionController::~SingleRpcClassResponseTimeAdmissionController(void) -//{ -//} -// -// bool SingleRpcClassResponseTimeAdmissionController::is_task_accepted(task* task) -//{ -// if (task->spec().type != TASK_TYPE_RPC_REQUEST -// //|| task->spec().code == _rpcCode -// || _counter->get_percentile(_percentile) < _latencyThreshold100ns -// ) -// { -// return true; -// } -// else -// { -// return false; -// } -//} -// -// int SingleRpcClassResponseTimeAdmissionController::get_system_utilization() -//{ -// return static_cast(100.0 * static_cast_counter->get_percentile(_percentile) / -// static_cast_latencyThreshold100ns); -//} - -} // end namespace diff --git a/src/core/core/env_provider.cpp b/src/core/core/env_provider.cpp deleted file mode 100644 index bd5d45b0b0..0000000000 --- a/src/core/core/env_provider.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#include -#include -#include -#include -#include - -namespace dsn { - -//------------ env_provider --------------- - -env_provider::env_provider(env_provider *inner_provider) {} - -} // end namespace diff --git a/src/core/core/service_api_c.cpp b/src/core/core/service_api_c.cpp index 530f02ff29..b955451e0c 100644 --- a/src/core/core/service_api_c.cpp +++ b/src/core/core/service_api_c.cpp @@ -41,7 +41,7 @@ #include "service_engine.h" #include "core/rpc/rpc_engine.h" #include "core/task/task_engine.h" -#include "coredump.h" +#include "utils/coredump.h" // // global state diff --git a/src/core/core/tool_api.cpp b/src/core/core/tool_api.cpp index 73f9d4087c..4c4d604929 100644 --- a/src/core/core/tool_api.cpp +++ b/src/core/core/tool_api.cpp @@ -36,7 +36,7 @@ #include #include #include -#include "service_engine.h" +#include "core/core/service_engine.h" #include "core/rpc/message_parser_manager.h" namespace dsn { diff --git a/src/core/core/zlocks.cpp b/src/core/core/zlocks.cpp index 19c79f1d8b..08b7322ad0 100644 --- a/src/core/core/zlocks.cpp +++ b/src/core/core/zlocks.cpp @@ -35,7 +35,7 @@ #include #include -#include "core/core/zlock_provider.h" +#include "utils/zlock_provider.h" #include "core/core/service_engine.h" namespace dsn { diff --git a/src/core/task/task_engine.sim.h b/src/core/task/task_engine.sim.h index a2d2fe8251..1e17d19612 100644 --- a/src/core/task/task_engine.sim.h +++ b/src/core/task/task_engine.sim.h @@ -38,7 +38,7 @@ #include #include #include -#include "core/core/zlock_provider.h" +#include "utils/zlock_provider.h" namespace dsn { namespace tools { diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 72d6b36ff2..3d0e95bf64 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -13,18 +13,9 @@ set(MY_PROJ_LIBS gtest set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex) # Extra files that will be installed -set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-key.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-section.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-empty.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-no-key.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-no-section.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-null-section.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-sample.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-test-corrupt-message.ini" +set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-test-corrupt-message.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-test.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-test-sim.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-unmatch-section.ini" "${CMAKE_CURRENT_SOURCE_DIR}/command.txt" "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" diff --git a/src/core/tests/main.cpp b/src/core/tests/main.cpp index 5e6fb95dca..644ff24591 100644 --- a/src/core/tests/main.cpp +++ b/src/core/tests/main.cpp @@ -38,7 +38,6 @@ #include "test_utils.h" extern void task_engine_module_init(); -extern void command_manager_module_init(); int g_test_count = 0; int g_test_ret = 0; @@ -49,7 +48,6 @@ GTEST_API_ int main(int argc, char **argv) // register all tools task_engine_module_init(); - command_manager_module_init(); // register all possible services dsn::service_app::register_factory("test"); diff --git a/src/core/tests/rpc_message.cpp b/src/core/tests/rpc_message.cpp index 14bd15d304..bb93b40db5 100644 --- a/src/core/tests/rpc_message.cpp +++ b/src/core/tests/rpc_message.cpp @@ -33,10 +33,10 @@ * xxxx-xx-xx, author, fix bug about xxx */ +#include "core/core/message_utils.cpp" #include #include #include -#include #include using namespace ::dsn; diff --git a/src/core/tools/common/lockp.std.cpp b/src/core/tools/common/lockp.std.cpp deleted file mode 100644 index f5449c0793..0000000000 --- a/src/core/tools/common/lockp.std.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#include "lockp.std.h" - -namespace dsn { -namespace tools { -void register_std_lock_providers() -{ - lock_provider::register_component("dsn::tools::std_lock_provider"); - lock_nr_provider::register_component("dsn::tools::std_lock_nr_provider"); - rwlock_nr_provider::register_component( - "dsn::tools::std_rwlock_nr_provider"); - semaphore_provider::register_component( - "dsn::tools::std_semaphore_provider"); -} -} -} diff --git a/src/core/tools/common/profiler.cpp b/src/core/tools/common/profiler.cpp index 70af629ef0..21cdd4f97e 100644 --- a/src/core/tools/common/profiler.cpp +++ b/src/core/tools/common/profiler.cpp @@ -50,7 +50,7 @@ START<== queue(server) == ENQUEUE <===== net(reply) ======= REPLY <============= #include #include #include -#include "shared_io_service.h" +#include "utils/shared_io_service.h" #include "profiler_header.h" #include #include diff --git a/src/core/tools/common/providers.common.cpp b/src/core/tools/common/providers.common.cpp index 951f9f19b1..a52c150cdd 100644 --- a/src/core/tools/common/providers.common.cpp +++ b/src/core/tools/common/providers.common.cpp @@ -35,17 +35,28 @@ #include "core/rpc/asio_net_provider.h" #include -#include "lockp.std.h" +#include "utils/lockp.std.h" #include "core/task/simple_task_queue.h" #include "core/task/hpc_task_queue.h" #include "core/rpc/network.sim.h" -#include "simple_logger.h" +#include "utils/simple_logger.h" #include "core/rpc/dsn_message_parser.h" #include "core/rpc/thrift_message_parser.h" #include "core/rpc/raw_message_parser.h" namespace dsn { namespace tools { + +void register_std_lock_providers() +{ + lock_provider::register_component("dsn::tools::std_lock_provider"); + lock_nr_provider::register_component("dsn::tools::std_lock_nr_provider"); + rwlock_nr_provider::register_component( + "dsn::tools::std_rwlock_nr_provider"); + semaphore_provider::register_component( + "dsn::tools::std_semaphore_provider"); +} + void register_common_providers() { register_component_provider("dsn::env_provider"); diff --git a/src/perf_counter/perf_counter_atomic.h b/src/perf_counter/perf_counter_atomic.h index 7e384fa9d3..6fc8d2ecfe 100644 --- a/src/perf_counter/perf_counter_atomic.h +++ b/src/perf_counter/perf_counter_atomic.h @@ -9,7 +9,7 @@ #include #include #include -#include "core/tools/common/shared_io_service.h" +#include "utils/shared_io_service.h" namespace dsn { diff --git a/src/replica/backup/test/CMakeLists.txt b/src/replica/backup/test/CMakeLists.txt index 1c2b21f7ad..eeaa56d71e 100644 --- a/src/replica/backup/test/CMakeLists.txt +++ b/src/replica/backup/test/CMakeLists.txt @@ -10,6 +10,7 @@ set(MY_PROJ_LIBS dsn_meta_server dsn.block_service dsn.block_service.local dsn.block_service.fds + dsn_utils gtest ) diff --git a/src/replica/duplication/test/CMakeLists.txt b/src/replica/duplication/test/CMakeLists.txt index 049c995bf1..0eb03e9199 100644 --- a/src/replica/duplication/test/CMakeLists.txt +++ b/src/replica/duplication/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(MY_PROJ_LIBS dsn_meta_server dsn.replication.zookeeper_provider dsn_replication_common dsn.failure_detector + dsn_utils zookeeper_mt gtest ) diff --git a/src/replica/replica.h b/src/replica/replica.h index 447fa9b235..98c2990ca8 100644 --- a/src/replica/replica.h +++ b/src/replica/replica.h @@ -54,7 +54,7 @@ #include "mutation_log.h" #include "prepare_list.h" #include "replica_context.h" -#include "throttling_controller.h" +#include "utils/throttling_controller.h" namespace dsn { namespace replication { diff --git a/src/replica/test/throttling_controller_test.cpp b/src/replica/test/throttling_controller_test.cpp index 09b22fbe82..4b4828511a 100644 --- a/src/replica/test/throttling_controller_test.cpp +++ b/src/replica/test/throttling_controller_test.cpp @@ -2,7 +2,7 @@ // This source code is licensed under the Apache License Version 2.0, which // can be found in the LICENSE file in the root directory of this source tree. -#include "replica/throttling_controller.h" +#include "utils/throttling_controller.h" #include diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 0000000000..7a36c01c95 --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,17 @@ +set(MY_PROJ_NAME dsn_utils) + +# Search mode for source files under CURRENT project directory? +# "GLOB_RECURSE" for recursive search +# "GLOB" for non-recursive search +set(MY_SRC_SEARCH_MODE "GLOB") + +set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex) + +set(MY_PROJ_LIBS crypto) + +# Extra files that will be installed +set(MY_BINPLACES "") + +dsn_add_shared_library() + +add_subdirectory(test) diff --git a/src/core/core/binary_reader.cpp b/src/utils/binary_reader.cpp similarity index 100% rename from src/core/core/binary_reader.cpp rename to src/utils/binary_reader.cpp diff --git a/src/core/core/binary_writer.cpp b/src/utils/binary_writer.cpp similarity index 100% rename from src/core/core/binary_writer.cpp rename to src/utils/binary_writer.cpp diff --git a/src/core/core/clock.cpp b/src/utils/clock.cpp similarity index 100% rename from src/core/core/clock.cpp rename to src/utils/clock.cpp diff --git a/src/core/core/command_manager.cpp b/src/utils/command_manager.cpp similarity index 100% rename from src/core/core/command_manager.cpp rename to src/utils/command_manager.cpp diff --git a/src/core/core/config_api.cpp b/src/utils/config_api.cpp similarity index 100% rename from src/core/core/config_api.cpp rename to src/utils/config_api.cpp diff --git a/src/core/core/configuration.cpp b/src/utils/configuration.cpp similarity index 100% rename from src/core/core/configuration.cpp rename to src/utils/configuration.cpp diff --git a/src/core/core/coredump.h b/src/utils/coredump.h similarity index 100% rename from src/core/core/coredump.h rename to src/utils/coredump.h diff --git a/src/core/core/coredump.posix.cpp b/src/utils/coredump.posix.cpp similarity index 100% rename from src/core/core/coredump.posix.cpp rename to src/utils/coredump.posix.cpp diff --git a/src/core/core/crc.cpp b/src/utils/crc.cpp similarity index 100% rename from src/core/core/crc.cpp rename to src/utils/crc.cpp diff --git a/src/core/core/error_code.cpp b/src/utils/error_code.cpp similarity index 100% rename from src/core/core/error_code.cpp rename to src/utils/error_code.cpp diff --git a/src/core/core/fail_point.cpp b/src/utils/fail_point.cpp similarity index 100% rename from src/core/core/fail_point.cpp rename to src/utils/fail_point.cpp diff --git a/src/core/core/fail_point_impl.h b/src/utils/fail_point_impl.h similarity index 100% rename from src/core/core/fail_point_impl.h rename to src/utils/fail_point_impl.h diff --git a/src/core/core/filesystem.cpp b/src/utils/filesystem.cpp similarity index 100% rename from src/core/core/filesystem.cpp rename to src/utils/filesystem.cpp diff --git a/src/core/core/flags.cpp b/src/utils/flags.cpp similarity index 100% rename from src/core/core/flags.cpp rename to src/utils/flags.cpp diff --git a/src/core/core/gpid.cpp b/src/utils/gpid.cpp similarity index 100% rename from src/core/core/gpid.cpp rename to src/utils/gpid.cpp diff --git a/src/core/core/join_point.cpp b/src/utils/join_point.cpp similarity index 100% rename from src/core/core/join_point.cpp rename to src/utils/join_point.cpp diff --git a/src/core/tools/common/lockp.std.h b/src/utils/lockp.std.h similarity index 97% rename from src/core/tools/common/lockp.std.h rename to src/utils/lockp.std.h index 9f228534b9..a8fcd68d65 100644 --- a/src/core/tools/common/lockp.std.h +++ b/src/utils/lockp.std.h @@ -36,7 +36,7 @@ #pragma once #include -#include "core/core/zlock_provider.h" +#include "utils/zlock_provider.h" namespace dsn { namespace tools { @@ -102,7 +102,5 @@ class std_semaphore_provider : public semaphore_provider private: dsn::utils::semaphore _sema; }; - -void register_std_lock_providers(); } } // end namespace dsn::tools diff --git a/src/core/core/logging.cpp b/src/utils/logging.cpp similarity index 99% rename from src/core/core/logging.cpp rename to src/utils/logging.cpp index c1d2550cf6..8b0fbd3f21 100644 --- a/src/core/core/logging.cpp +++ b/src/utils/logging.cpp @@ -29,7 +29,7 @@ #include #include #include -#include "core/tools/common/simple_logger.h" +#include "simple_logger.h" DSN_API dsn_log_level_t dsn_log_start_level = dsn_log_level_t::LOG_LEVEL_INFORMATION; DSN_DEFINE_string("core", diff --git a/src/core/core/math.cpp b/src/utils/math.cpp similarity index 100% rename from src/core/core/math.cpp rename to src/utils/math.cpp diff --git a/src/core/core/memutil.h b/src/utils/memutil.h similarity index 100% rename from src/core/core/memutil.h rename to src/utils/memutil.h diff --git a/src/core/core/output_utils.cpp b/src/utils/output_utils.cpp similarity index 100% rename from src/core/core/output_utils.cpp rename to src/utils/output_utils.cpp diff --git a/src/core/core/process_utils.cpp b/src/utils/process_utils.cpp similarity index 100% rename from src/core/core/process_utils.cpp rename to src/utils/process_utils.cpp diff --git a/src/core/core/rand.cpp b/src/utils/rand.cpp similarity index 100% rename from src/core/core/rand.cpp rename to src/utils/rand.cpp diff --git a/src/core/rpc/rpc_address.cpp b/src/utils/rpc_address.cpp similarity index 99% rename from src/core/rpc/rpc_address.cpp rename to src/utils/rpc_address.cpp index 04e01e45ba..ce11110c0a 100644 --- a/src/core/rpc/rpc_address.cpp +++ b/src/utils/rpc_address.cpp @@ -38,7 +38,6 @@ #include #include -#include namespace dsn { diff --git a/src/core/core/safe_strerror_posix.cpp b/src/utils/safe_strerror_posix.cpp similarity index 99% rename from src/core/core/safe_strerror_posix.cpp rename to src/utils/safe_strerror_posix.cpp index b7797ef996..185457efee 100644 --- a/src/core/core/safe_strerror_posix.cpp +++ b/src/utils/safe_strerror_posix.cpp @@ -3,7 +3,6 @@ // found in the LICENSE file. #include -#include "build_config.h" #include #include diff --git a/src/core/tools/common/shared_io_service.h b/src/utils/shared_io_service.h similarity index 100% rename from src/core/tools/common/shared_io_service.h rename to src/utils/shared_io_service.h diff --git a/src/core/tools/common/simple_logger.cpp b/src/utils/simple_logger.cpp similarity index 100% rename from src/core/tools/common/simple_logger.cpp rename to src/utils/simple_logger.cpp diff --git a/src/core/tools/common/simple_logger.h b/src/utils/simple_logger.h similarity index 100% rename from src/core/tools/common/simple_logger.h rename to src/utils/simple_logger.h diff --git a/src/core/core/string_view.cpp b/src/utils/string_view.cpp similarity index 100% rename from src/core/core/string_view.cpp rename to src/utils/string_view.cpp diff --git a/src/core/core/strings.cpp b/src/utils/strings.cpp similarity index 100% rename from src/core/core/strings.cpp rename to src/utils/strings.cpp diff --git a/src/utils/test/CMakeLists.txt b/src/utils/test/CMakeLists.txt new file mode 100644 index 0000000000..d0d27d1222 --- /dev/null +++ b/src/utils/test/CMakeLists.txt @@ -0,0 +1,29 @@ +set(MY_PROJ_NAME dsn_utils_tests) + +# Search mode for source files under CURRENT project directory? +# "GLOB_RECURSE" for recursive search +# "GLOB" for non-recursive search +set(MY_SRC_SEARCH_MODE "GLOB") + +set(MY_PROJ_LIBS dsn_runtime + dsn_utils + gtest + ) + +set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex) + +# Extra files that will be installed +set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-key.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-section.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-empty.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-no-key.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-no-section.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-null-section.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-sample.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-unmatch-section.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" + "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" + ) +add_definitions(-Wno-dangling-else) +dsn_add_test() diff --git a/src/core/tests/TokenBucketTest.cpp b/src/utils/test/TokenBucketTest.cpp similarity index 100% rename from src/core/tests/TokenBucketTest.cpp rename to src/utils/test/TokenBucketTest.cpp diff --git a/src/core/tests/TokenBucketTest.h b/src/utils/test/TokenBucketTest.h similarity index 100% rename from src/core/tests/TokenBucketTest.h rename to src/utils/test/TokenBucketTest.h diff --git a/src/core/tests/address.cpp b/src/utils/test/address.cpp similarity index 100% rename from src/core/tests/address.cpp rename to src/utils/test/address.cpp diff --git a/src/core/tests/autoref_ptr_test.cpp b/src/utils/test/autoref_ptr_test.cpp similarity index 100% rename from src/core/tests/autoref_ptr_test.cpp rename to src/utils/test/autoref_ptr_test.cpp diff --git a/src/utils/test/clear.sh b/src/utils/test/clear.sh new file mode 100755 index 0000000000..df93f5d63e --- /dev/null +++ b/src/utils/test/clear.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -rf dsn.utils.tests.xml log*.txt diff --git a/src/core/tests/command_manager.cpp b/src/utils/test/command_manager.cpp similarity index 73% rename from src/core/tests/command_manager.cpp rename to src/utils/test/command_manager.cpp index 1bcb427ed6..b1074849e0 100644 --- a/src/core/tests/command_manager.cpp +++ b/src/utils/test/command_manager.cpp @@ -56,3 +56,25 @@ void command_manager_module_init() return ss.str(); }); } + +TEST(command_manager, exist_command) +{ + const std::string cmd = "test-cmd"; + const std::vector cmd_args{"this", "is", "test", "argument"}; + std::string output; + dsn::command_manager::instance().run_command(cmd, cmd_args, output); + + std::string expect_output = "test-cmd response: [this is test argument]"; + ASSERT_EQ(output, expect_output); +} + +TEST(command_manager, not_exist_command) +{ + const std::string cmd = "not-exist-cmd"; + const std::vector cmd_args{"arg1", "arg2"}; + std::string output; + dsn::command_manager::instance().run_command(cmd, cmd_args, output); + + std::string expect_output = std::string("unknown command '") + cmd + "'"; + ASSERT_EQ(output, expect_output); +} diff --git a/src/core/tests/config-bad-section.ini b/src/utils/test/config-bad-section.ini similarity index 100% rename from src/core/tests/config-bad-section.ini rename to src/utils/test/config-bad-section.ini diff --git a/src/core/tests/config-dup-key.ini b/src/utils/test/config-dup-key.ini similarity index 100% rename from src/core/tests/config-dup-key.ini rename to src/utils/test/config-dup-key.ini diff --git a/src/core/tests/config-dup-section.ini b/src/utils/test/config-dup-section.ini similarity index 100% rename from src/core/tests/config-dup-section.ini rename to src/utils/test/config-dup-section.ini diff --git a/src/core/tests/config-empty.ini b/src/utils/test/config-empty.ini similarity index 100% rename from src/core/tests/config-empty.ini rename to src/utils/test/config-empty.ini diff --git a/src/core/tests/config-no-key.ini b/src/utils/test/config-no-key.ini similarity index 100% rename from src/core/tests/config-no-key.ini rename to src/utils/test/config-no-key.ini diff --git a/src/core/tests/config-no-section.ini b/src/utils/test/config-no-section.ini similarity index 100% rename from src/core/tests/config-no-section.ini rename to src/utils/test/config-no-section.ini diff --git a/src/core/tests/config-null-section.ini b/src/utils/test/config-null-section.ini similarity index 100% rename from src/core/tests/config-null-section.ini rename to src/utils/test/config-null-section.ini diff --git a/src/core/tests/config-sample.ini b/src/utils/test/config-sample.ini similarity index 100% rename from src/core/tests/config-sample.ini rename to src/utils/test/config-sample.ini diff --git a/src/core/tests/config-unmatch-section.ini b/src/utils/test/config-unmatch-section.ini similarity index 100% rename from src/core/tests/config-unmatch-section.ini rename to src/utils/test/config-unmatch-section.ini diff --git a/src/core/tests/configuration.cpp b/src/utils/test/configuration.cpp similarity index 100% rename from src/core/tests/configuration.cpp rename to src/utils/test/configuration.cpp diff --git a/src/core/tests/endian_test.cpp b/src/utils/test/endian_test.cpp similarity index 100% rename from src/core/tests/endian_test.cpp rename to src/utils/test/endian_test.cpp diff --git a/src/core/tests/env.cpp b/src/utils/test/env.cpp similarity index 95% rename from src/core/tests/env.cpp rename to src/utils/test/env.cpp index b68cb81071..bf55d43deb 100644 --- a/src/core/tests/env.cpp +++ b/src/utils/test/env.cpp @@ -33,10 +33,8 @@ * xxxx-xx-xx, author, fix bug about xxx */ -#include #include #include -#include "core/tools/simulator/env.sim.h" using namespace ::dsn; diff --git a/src/core/tests/fail_point_test.cpp b/src/utils/test/fail_point_test.cpp similarity index 98% rename from src/core/tests/fail_point_test.cpp rename to src/utils/test/fail_point_test.cpp index 081417350b..36318944d9 100644 --- a/src/core/tests/fail_point_test.cpp +++ b/src/utils/test/fail_point_test.cpp @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "core/core/fail_point_impl.h" +#include "utils/fail_point_impl.h" #include diff --git a/src/core/tests/file_system_test.cpp b/src/utils/test/file_system_test.cpp similarity index 100% rename from src/core/tests/file_system_test.cpp rename to src/utils/test/file_system_test.cpp diff --git a/src/core/tests/file_utils.cpp b/src/utils/test/file_utils.cpp similarity index 99% rename from src/core/tests/file_utils.cpp rename to src/utils/test/file_utils.cpp index 48827ffff7..cf72ddf5cb 100644 --- a/src/core/tests/file_utils.cpp +++ b/src/utils/test/file_utils.cpp @@ -58,11 +58,7 @@ static void file_utils_test_get_process_image_path() if (!dsn::utils::filesystem::get_current_directory(imagepath)) { EXPECT_TRUE(false); } -#ifdef WIN32 - imagepath = dsn::utils::filesystem::path_combine(imagepath, "dsn.core.tests.exe"); -#else - imagepath = dsn::utils::filesystem::path_combine(imagepath, "dsn.core.tests"); -#endif + imagepath = dsn::utils::filesystem::path_combine(imagepath, "dsn_utils_tests"); ret = dsn::utils::filesystem::get_current_process_image_path(path); EXPECT_TRUE(ret == dsn::ERR_OK); diff --git a/src/common/test/fmt_logging_test.cpp b/src/utils/test/fmt_logging_test.cpp similarity index 100% rename from src/common/test/fmt_logging_test.cpp rename to src/utils/test/fmt_logging_test.cpp diff --git a/src/core/tests/hostname_test.cpp b/src/utils/test/hostname_test.cpp similarity index 100% rename from src/core/tests/hostname_test.cpp rename to src/utils/test/hostname_test.cpp diff --git a/src/core/tests/join_point.cpp b/src/utils/test/join_point.cpp similarity index 100% rename from src/core/tests/join_point.cpp rename to src/utils/test/join_point.cpp diff --git a/src/core/tests/json_helper_test.cpp b/src/utils/test/json_helper_test.cpp similarity index 100% rename from src/core/tests/json_helper_test.cpp rename to src/utils/test/json_helper_test.cpp diff --git a/src/core/tests/lock.std.cpp b/src/utils/test/lock.std.cpp similarity index 90% rename from src/core/tests/lock.std.cpp rename to src/utils/test/lock.std.cpp index 2b7950e7d9..3a2381a6fe 100644 --- a/src/core/tests/lock.std.cpp +++ b/src/utils/test/lock.std.cpp @@ -24,16 +24,7 @@ * THE SOFTWARE. */ -/* - * Description: - * Unit-test for std lock. - * - * Revision history: - * Nov., 2015, @shengofsun (Weijie Sun), first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#include "core/tools/common/lockp.std.h" +#include "utils/lockp.std.h" #include using namespace dsn; diff --git a/src/core/tests/logger.cpp b/src/utils/test/logger.cpp similarity index 94% rename from src/core/tests/logger.cpp rename to src/utils/test/logger.cpp index b462843e59..f8bf4d1ee1 100644 --- a/src/core/tests/logger.cpp +++ b/src/utils/test/logger.cpp @@ -33,7 +33,7 @@ * xxxx-xx-xx, author, fix bug about xxx */ -#include "core/tools/common/simple_logger.h" +#include "utils/simple_logger.h" #include #include @@ -99,12 +99,7 @@ TEST(tools_common, simple_logger) // cases for print_header screen_logger *logger = new screen_logger("./"); log_print(logger, "%s", "test_print"); - std::thread t( - [](screen_logger *lg) { - tls_dsn.magic = 0xdeadbeef; - log_print(lg, "%s", "test_print"); - }, - logger); + std::thread t([](screen_logger *lg) { log_print(lg, "%s", "test_print"); }, logger); t.join(); logger->flush(); diff --git a/src/core/tests/logging.cpp b/src/utils/test/logging.cpp similarity index 98% rename from src/core/tests/logging.cpp rename to src/utils/test/logging.cpp index 35fe0c2498..03cc31cbb6 100644 --- a/src/core/tests/logging.cpp +++ b/src/utils/test/logging.cpp @@ -33,10 +33,10 @@ * xxxx-xx-xx, author, fix bug about xxx */ -#include #include #include #include +#include TEST(core, logging) { diff --git a/src/utils/test/main.cpp b/src/utils/test/main.cpp new file mode 100644 index 0000000000..d64376a3a4 --- /dev/null +++ b/src/utils/test/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +extern void command_manager_module_init(); + +GTEST_API_ int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + command_manager_module_init(); + // init logging + dsn_log_init("dsn::tools::simple_logger", "./", nullptr); + + return RUN_ALL_TESTS(); +} diff --git a/src/core/tests/memutil_test.cpp b/src/utils/test/memutil_test.cpp similarity index 97% rename from src/core/tests/memutil_test.cpp rename to src/utils/test/memutil_test.cpp index bd16ff74ff..7f5cff462f 100644 --- a/src/core/tests/memutil_test.cpp +++ b/src/utils/test/memutil_test.cpp @@ -14,7 +14,7 @@ // Unit test for memutil.cc -#include "core/core/memutil.h" +#include "utils/memutil.h" #include diff --git a/src/core/tests/output_utils_test.cpp b/src/utils/test/output_utils_test.cpp similarity index 100% rename from src/core/tests/output_utils_test.cpp rename to src/utils/test/output_utils_test.cpp diff --git a/src/core/tests/priority_queue.cpp b/src/utils/test/priority_queue.cpp similarity index 100% rename from src/core/tests/priority_queue.cpp rename to src/utils/test/priority_queue.cpp diff --git a/src/core/tests/rand_test.cpp b/src/utils/test/rand_test.cpp similarity index 100% rename from src/core/tests/rand_test.cpp rename to src/utils/test/rand_test.cpp diff --git a/src/utils/test/run.sh b/src/utils/test/run.sh new file mode 100755 index 0000000000..001353e853 --- /dev/null +++ b/src/utils/test/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -z "${REPORT_DIR}" ]; then + REPORT_DIR="." +fi + +./clear.sh +output_xml="${REPORT_DIR}/dsn_utils_tests.xml" +GTEST_OUTPUT="xml:${output_xml}" ./dsn_utils_tests diff --git a/src/core/tests/sema.cpp b/src/utils/test/sema.cpp similarity index 100% rename from src/core/tests/sema.cpp rename to src/utils/test/sema.cpp diff --git a/src/core/tests/smart_pointers_test.cpp b/src/utils/test/smart_pointers_test.cpp similarity index 100% rename from src/core/tests/smart_pointers_test.cpp rename to src/utils/test/smart_pointers_test.cpp diff --git a/src/core/tests/string_conv_test.cpp b/src/utils/test/string_conv_test.cpp similarity index 100% rename from src/core/tests/string_conv_test.cpp rename to src/utils/test/string_conv_test.cpp diff --git a/src/core/tests/string_view_test.cpp b/src/utils/test/string_view_test.cpp similarity index 100% rename from src/core/tests/string_view_test.cpp rename to src/utils/test/string_view_test.cpp diff --git a/src/core/tests/time_utils_test.cpp b/src/utils/test/time_utils_test.cpp similarity index 100% rename from src/core/tests/time_utils_test.cpp rename to src/utils/test/time_utils_test.cpp diff --git a/src/core/tests/transient_memory.cpp b/src/utils/test/transient_memory.cpp similarity index 100% rename from src/core/tests/transient_memory.cpp rename to src/utils/test/transient_memory.cpp diff --git a/src/core/tests/utils.cpp b/src/utils/test/utils.cpp similarity index 100% rename from src/core/tests/utils.cpp rename to src/utils/test/utils.cpp diff --git a/src/core/core/thread_access_checker.cpp b/src/utils/thread_access_checker.cpp similarity index 100% rename from src/core/core/thread_access_checker.cpp rename to src/utils/thread_access_checker.cpp diff --git a/src/replica/throttling_controller.cpp b/src/utils/throttling_controller.cpp similarity index 100% rename from src/replica/throttling_controller.cpp rename to src/utils/throttling_controller.cpp diff --git a/src/replica/throttling_controller.h b/src/utils/throttling_controller.h similarity index 100% rename from src/replica/throttling_controller.h rename to src/utils/throttling_controller.h diff --git a/src/core/core/transient_memory.cpp b/src/utils/transient_memory.cpp similarity index 100% rename from src/core/core/transient_memory.cpp rename to src/utils/transient_memory.cpp diff --git a/src/core/core/utils.cpp b/src/utils/utils.cpp similarity index 100% rename from src/core/core/utils.cpp rename to src/utils/utils.cpp diff --git a/src/core/core/zlock_provider.h b/src/utils/zlock_provider.h similarity index 100% rename from src/core/core/zlock_provider.h rename to src/utils/zlock_provider.h