Skip to content

Commit

Permalink
refactor: move aio module from src/core/aio to src/aio (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
levy5307 authored Jul 8, 2020
1 parent 24f5524 commit b73d1aa
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ if(UNIX)
add_compile_options(-fPIC)
endif()
add_subdirectory(core)
add_subdirectory(aio)
add_subdirectory(dist)
add_subdirectory(tests)
2 changes: 2 additions & 0 deletions src/core/aio/CMakeLists.txt → src/aio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ set(MY_PROJ_LIBS dsn_runtime)
set(MY_BINPLACES "")

dsn_add_static_library()

add_subdirectory(tests)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions src/aio/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 5 additions & 15 deletions src/core/tests/aio.cpp → src/aio/tests/aio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dsn/tool-api/async_calls.h>
#include <dsn/utility/filesystem.h>
#include <dsn/service_api_cpp.h>

#include <gtest/gtest.h>
#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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions src/aio/tests/clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

rm -rf data dsn_aio_test.xml copy_dest.txt
21 changes: 21 additions & 0 deletions src/aio/tests/config.ini
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions src/aio/tests/copy_source.txt
Original file line number Diff line number Diff line change
@@ -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

13 changes: 13 additions & 0 deletions src/aio/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>
#include <dsn/service_api_cpp.h>

GTEST_API_ int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
dsn_run_config("config.ini", false);
return RUN_ALL_TESTS();
}
9 changes: 9 additions & 0 deletions src/aio/tests/run.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/clear.sh
Original file line number Diff line number Diff line change
@@ -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

1 change: 0 additions & 1 deletion src/dist/nfs/nfs_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <dsn/tool-api/task_tracker.h>
#include <dsn/perf_counter/perf_counter_wrapper.h>

#include "core/aio/disk_engine.h"
#include "nfs_server.h"
#include "nfs_client_impl.h"

Expand Down

0 comments on commit b73d1aa

Please sign in to comment.