Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整单元测试的目录 #408

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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.
Loading