Skip to content

Commit

Permalink
调整单元测试的目录 (#408)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Problem:
当前所有单元测试都放在一个目录下,看起来很混乱,还会额外链接一些多余的库

### What is changed and how it works?
拆分observer、deps/common和deps/memtracer目录
  • Loading branch information
hnwyllmm authored May 14, 2024
1 parent 93ef5bc commit 057fd6d
Show file tree
Hide file tree
Showing 35 changed files with 51 additions and 26 deletions.
10 changes: 5 additions & 5 deletions deps/memtracer/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ mt_visible void operator delete(void *ptr, std::size_t size) noexcept;
mt_visible void operator delete[](void *ptr, std::size_t size) noexcept;

// unsupported libc functions, for simpler memory tracking.
extern "C" mt_visible char * realpath(const char *fname, char *resolved_name);
extern "C" mt_visible void * memalign(size_t alignment, size_t size);
extern "C" mt_visible void * valloc(size_t size);
extern "C" mt_visible void * pvalloc(size_t size);
extern "C" mt_visible char *realpath(const char *fname, char *resolved_name);
extern "C" mt_visible void *memalign(size_t alignment, size_t size);
extern "C" mt_visible void *valloc(size_t size);
extern "C" mt_visible void *pvalloc(size_t size);
extern "C" mt_visible int posix_memalign(void **memptr, size_t alignment, size_t size);
extern "C" mt_visible int brk(void *addr);
extern "C" mt_visible void * sbrk(intptr_t increment);
extern "C" mt_visible void *sbrk(intptr_t increment);
extern "C" mt_visible long int syscall(long int __sysno, ...);

// forword libc interface
Expand Down
5 changes: 2 additions & 3 deletions deps/memtracer/memtracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ class MemTracer
static void stat();

private:
bool is_inited_ = false;
bool is_stop_ = false;
bool is_stop_ = false;
std::atomic<size_t> allocated_memory_{};
std::atomic<size_t> alloc_cnt_{};
std::atomic<size_t> free_cnt_{};
std::once_flag init_hook_funcs_once_;
std::once_flag memory_limit_once_;
size_t memory_limit_ = UINT64_MAX;
size_t memory_limit_ = UINT64_MAX;
size_t print_interval_ms_ = 0;
std::thread t_;
};
Expand Down
24 changes: 6 additions & 18 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
# 可以获取父cmake的变量
MESSAGE("${CMAKE_COMMON_FLAGS}")

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/observer)

find_package(GTest CONFIG REQUIRED)

include(GoogleTest)

#get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
# [CACHE])
FILE(GLOB_RECURSE ALL_SRC *.cpp)
# AUX_SOURCE_DIRECTORY 类似功能
FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
# TODO: 不是所有的单测都需要链接observer_static
TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main observer_static)
add_test(NAME ${prjName} COMMAND ${prjName})
if (${prjName} STREQUAL "memtracer_test")
TARGET_LINK_LIBRARIES(${prjName} memtracer)
endif()
ENDFOREACH (F)
ADD_SUBDIRECTORY(common)
IF (WITH_MEMTRACER)
ADD_SUBDIRECTORY(memtracer)
ENDIF (WITH_MEMTRACER)

ADD_SUBDIRECTORY(observer)
12 changes: 12 additions & 0 deletions unittest/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
# [CACHE])
FILE(GLOB_RECURSE ALL_SRC *.cpp)
# AUX_SOURCE_DIRECTORY 类似功能
FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)
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.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions unittest/memtracer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
# [CACHE])
FILE(GLOB_RECURSE ALL_SRC *.cpp)
# AUX_SOURCE_DIRECTORY 类似功能
FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} pthread dl gtest gtest_main memtracer)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)
File renamed without changes.
14 changes: 14 additions & 0 deletions unittest/observer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/observer)

#get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
# [CACHE])
FILE(GLOB_RECURSE ALL_SRC *.cpp)
# AUX_SOURCE_DIRECTORY 类似功能
FOREACH (F ${ALL_SRC})
get_filename_component(prjName ${F} NAME_WE)
MESSAGE("Build ${prjName} according to ${F}")
ADD_EXECUTABLE(${prjName} ${F})
TARGET_LINK_LIBRARIES(${prjName} common pthread dl gtest gtest_main observer_static)
add_test(NAME ${prjName} COMMAND ${prjName})
ENDFOREACH (F)
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 057fd6d

Please sign in to comment.