diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2db60e1920..f817a84511 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,5 +2,6 @@ if(UNIX) add_compile_options(-fPIC) endif() add_subdirectory(core) +add_subdirectory(aio) add_subdirectory(dist) add_subdirectory(tests) diff --git a/src/core/aio/CMakeLists.txt b/src/aio/CMakeLists.txt similarity index 95% rename from src/core/aio/CMakeLists.txt rename to src/aio/CMakeLists.txt index 6fad9e66a2..6e2d701898 100644 --- a/src/core/aio/CMakeLists.txt +++ b/src/aio/CMakeLists.txt @@ -15,3 +15,5 @@ set(MY_PROJ_LIBS dsn_runtime) set(MY_BINPLACES "") dsn_add_static_library() + +add_subdirectory(tests) diff --git a/src/core/aio/aio_provider.cpp b/src/aio/aio_provider.cpp similarity index 100% rename from src/core/aio/aio_provider.cpp rename to src/aio/aio_provider.cpp diff --git a/src/core/aio/aio_provider.h b/src/aio/aio_provider.h similarity index 100% rename from src/core/aio/aio_provider.h rename to src/aio/aio_provider.h diff --git a/src/core/aio/aio_task.cpp b/src/aio/aio_task.cpp similarity index 100% rename from src/core/aio/aio_task.cpp rename to src/aio/aio_task.cpp diff --git a/src/core/aio/disk_engine.cpp b/src/aio/disk_engine.cpp similarity index 100% rename from src/core/aio/disk_engine.cpp rename to src/aio/disk_engine.cpp diff --git a/src/core/aio/disk_engine.h b/src/aio/disk_engine.h similarity index 100% rename from src/core/aio/disk_engine.h rename to src/aio/disk_engine.h diff --git a/src/core/aio/file_io.cpp b/src/aio/file_io.cpp similarity index 100% rename from src/core/aio/file_io.cpp rename to src/aio/file_io.cpp diff --git a/src/core/aio/native_linux_aio_provider.cpp b/src/aio/native_linux_aio_provider.cpp similarity index 100% rename from src/core/aio/native_linux_aio_provider.cpp rename to src/aio/native_linux_aio_provider.cpp diff --git a/src/core/aio/native_linux_aio_provider.h b/src/aio/native_linux_aio_provider.h similarity index 100% rename from src/core/aio/native_linux_aio_provider.h rename to src/aio/native_linux_aio_provider.h diff --git a/src/core/aio/sim_aio_provider.cpp b/src/aio/sim_aio_provider.cpp similarity index 100% rename from src/core/aio/sim_aio_provider.cpp rename to src/aio/sim_aio_provider.cpp diff --git a/src/core/aio/sim_aio_provider.h b/src/aio/sim_aio_provider.h similarity index 100% rename from src/core/aio/sim_aio_provider.h rename to src/aio/sim_aio_provider.h diff --git a/src/aio/tests/CMakeLists.txt b/src/aio/tests/CMakeLists.txt new file mode 100644 index 0000000000..9fb1c940d4 --- /dev/null +++ b/src/aio/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +set(MY_PROJ_NAME dsn_aio_test) + +# Source files under CURRENT project directory will be automatically included. +# You can manually set MY_PROJ_SRC to include source files under other directories. +set(MY_PROJ_SRC "") + +# 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 gtest dsn_runtime dsn_aio) + +set(MY_BOOST_LIBS Boost::system Boost::filesystem) + +# Extra files that will be installed +set(MY_BINPLACES + "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" + "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" + "${CMAKE_CURRENT_SOURCE_DIR}/copy_source.txt" +) + +dsn_add_test() diff --git a/src/core/tests/aio.cpp b/src/aio/tests/aio.cpp similarity index 94% rename from src/core/tests/aio.cpp rename to src/aio/tests/aio.cpp index 0927c77bab..52bb3d70ca 100644 --- a/src/core/tests/aio.cpp +++ b/src/aio/tests/aio.cpp @@ -24,24 +24,14 @@ * 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 "test_utils.h" using namespace ::dsn; +DEFINE_THREAD_POOL_CODE(THREAD_POOL_TEST_SERVER) DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, THREAD_POOL_TEST_SERVER); TEST(core, aio) @@ -204,12 +194,12 @@ struct aio_result TEST(core, dsn_file) { int64_t fin_size, fout_size; - ASSERT_TRUE(utils::filesystem::file_size("command.txt", fin_size)); + ASSERT_TRUE(utils::filesystem::file_size("copy_source.txt", fin_size)); ASSERT_LT(0, fin_size); - dsn::disk_file *fin = file::open("command.txt", O_RDONLY, 0); + dsn::disk_file *fin = file::open("copy_source.txt", O_RDONLY, 0); ASSERT_NE(nullptr, fin); - dsn::disk_file *fout = file::open("command.copy.txt", O_RDWR | O_CREAT | O_TRUNC, 0666); + dsn::disk_file *fout = file::open("copy_dest.txt", O_RDWR | O_CREAT | O_TRUNC, 0666); ASSERT_NE(nullptr, fout); char buffer[1024]; uint64_t offset = 0; @@ -278,6 +268,6 @@ TEST(core, dsn_file) ASSERT_EQ(ERR_OK, file::close(fout)); ASSERT_EQ(ERR_OK, file::close(fin)); - ASSERT_TRUE(utils::filesystem::file_size("command.copy.txt", fout_size)); + ASSERT_TRUE(utils::filesystem::file_size("copy_dest.txt", fout_size)); ASSERT_EQ(fin_size, fout_size); } diff --git a/src/aio/tests/clear.sh b/src/aio/tests/clear.sh new file mode 100755 index 0000000000..38ad6f82d4 --- /dev/null +++ b/src/aio/tests/clear.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -rf data dsn_aio_test.xml copy_dest.txt diff --git a/src/aio/tests/config.ini b/src/aio/tests/config.ini new file mode 100644 index 0000000000..4cfa2bf5bd --- /dev/null +++ b/src/aio/tests/config.ini @@ -0,0 +1,21 @@ +[apps..default] +run = true +count = 1 + +[apps.mimic] +type = dsn.app.mimic +arguments = +ports = 20101 +pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER +run = true +count = 1 + +[threadpool.THREAD_POOL_TEST_SERVER] +partitioned = false + +[core] +enable_default_app_mimic = true +tool = nativerun +pause_on_start = false +logging_start_level = LOG_LEVEL_DEBUG +logging_factory_name = dsn::tools::simple_logger diff --git a/src/aio/tests/copy_source.txt b/src/aio/tests/copy_source.txt new file mode 100644 index 0000000000..d6971722f8 --- /dev/null +++ b/src/aio/tests/copy_source.txt @@ -0,0 +1,10 @@ + +help +help engine +help unexist-cmd +engine +task-code +config-dump config-dump.ini +test-cmd this is test argument +unexist-cmd arg1 arg2 + diff --git a/src/aio/tests/main.cpp b/src/aio/tests/main.cpp new file mode 100644 index 0000000000..67d12167e2 --- /dev/null +++ b/src/aio/tests/main.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017-present, Xiaomi, Inc. All rights reserved. +// 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 +#include + +GTEST_API_ int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + dsn_run_config("config.ini", false); + return RUN_ALL_TESTS(); +} diff --git a/src/aio/tests/run.sh b/src/aio/tests/run.sh new file mode 100755 index 0000000000..5ae3f9fc9a --- /dev/null +++ b/src/aio/tests/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -z "${REPORT_DIR}" ]; then + REPORT_DIR="." +fi + +./clear.sh +output_xml="${REPORT_DIR}/dsn_aio_test.xml" +GTEST_OUTPUT="xml:${output_xml}" ./dsn_aio_test diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index cba503583c..adb795f09e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,7 +2,6 @@ add_subdirectory(core) add_subdirectory(perf_counter) add_subdirectory(tools) add_subdirectory(tests) -add_subdirectory(aio) add_subdirectory(rpc) add_subdirectory(task) diff --git a/src/core/tests/clear.sh b/src/core/tests/clear.sh index 8de94fa255..9a294e8a21 100755 --- a/src/core/tests/clear.sh +++ b/src/core/tests/clear.sh @@ -1,4 +1,4 @@ #!/bin/bash -rm -rf core* log.* nfs_test_dir* *.tmp command.copy.txt data +rm -rf core* log.* nfs_test_dir* *.tmp data diff --git a/src/dist/nfs/nfs_server_impl.h b/src/dist/nfs/nfs_server_impl.h index 10480d642c..c4ae71365a 100644 --- a/src/dist/nfs/nfs_server_impl.h +++ b/src/dist/nfs/nfs_server_impl.h @@ -36,7 +36,6 @@ #include #include -#include "core/aio/disk_engine.h" #include "nfs_server.h" #include "nfs_client_impl.h"