提交 71eb58f5 编写于 作者: H haozi007

change tests name

Signed-off-by: Nhaozi007 <liuhao27@huawei.com>
上级 9cfc4a93
...@@ -85,10 +85,8 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party) ...@@ -85,10 +85,8 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
# llt and gcoverage # ut and gcoverage
if (LCR_GCOV) add_subdirectory(tests)
add_subdirectory(tests)
endif()
# install all files # install all files
install(FILES ${CMAKE_BINARY_DIR}/conf/lcr.pc install(FILES ${CMAKE_BINARY_DIR}/conf/lcr.pc
......
...@@ -69,23 +69,23 @@ find_library(LIBYAJL_LIBRARY yajl ...@@ -69,23 +69,23 @@ find_library(LIBYAJL_LIBRARY yajl
HINTS ${PC_LIBYAJL_LIBDIR} ${PC_LIBYAJL_LIBRARY_DIRS}) HINTS ${PC_LIBYAJL_LIBDIR} ${PC_LIBYAJL_LIBRARY_DIRS})
_CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so") _CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so")
if (LCR_GCOV) pkg_check_modules(PC_GTEST "gtest")
pkg_check_modules(PC_GTEST "gtest") find_path(GTEST_INCLUDE_DIR gtest/gtest.h
find_path(GTEST_INCLUDE_DIR gtest/gtest.h HINTS ${PC_GTEST_INCLUDEDIR} ${PC_GTEST_INCLUDE_DIRS})
HINTS ${PC_GTEST_INCLUDEDIR} ${PC_GTEST_INCLUDE_DIRS}) _CHECK(GTEST_INCLUDE_DIR "GTEST_INCLUDE_DIR-NOTFOUND" "gtest.h")
_CHECK(GTEST_INCLUDE_DIR "GTEST_INCLUDE_DIR-NOTFOUND" "gtest.h") find_library(GTEST_LIBRARY gtest
find_library(GTEST_LIBRARY gtest HINTS ${PC_GTEST_LIBDIR} ${PC_GTEST_LIBRARY_DIRS})
HINTS ${PC_GTEST_LIBDIR} ${PC_GTEST_LIBRARY_DIRS}) _CHECK(GTEST_LIBRARY "GTEST_LIBRARY-NOTFOUND" "libgtest.so")
_CHECK(GTEST_LIBRARY "GTEST_LIBRARY-NOTFOUND" "libgtest.so")
pkg_check_modules(PC_GMOCK "gmock") pkg_check_modules(PC_GMOCK "gmock")
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h find_path(GMOCK_INCLUDE_DIR gmock/gmock.h
HINTS ${PC_GMOCK_INCLUDEDIR} ${PC_GMOCK_INCLUDE_DIRS}) HINTS ${PC_GMOCK_INCLUDEDIR} ${PC_GMOCK_INCLUDE_DIRS})
_CHECK(GMOCK_INCLUDE_DIR "GMOCK_INCLUDE_DIR-NOTFOUND" "gmock.h") _CHECK(GMOCK_INCLUDE_DIR "GMOCK_INCLUDE_DIR-NOTFOUND" "gmock.h")
find_library(GMOCK_LIBRARY z find_library(GMOCK_LIBRARY z
HINTS ${PC_GMOCK_LIBDIR} ${PC_GMOCK_LIBRARY_DIRS}) HINTS ${PC_GMOCK_LIBDIR} ${PC_GMOCK_LIBRARY_DIRS})
_CHECK(GMOCK_LIBRARY "GMOCK_LIBRARY-NOTFOUND" "libgmock.so") _CHECK(GMOCK_LIBRARY "GMOCK_LIBRARY-NOTFOUND" "libgmock.so")
if (ENABLE_GCOV)
find_program(CMD_GCOV gcov) find_program(CMD_GCOV gcov)
_CHECK(CMD_GCOV "CMD_GCOV-NOTFOUND" "gcov") _CHECK(CMD_GCOV "CMD_GCOV-NOTFOUND" "gcov")
......
...@@ -29,8 +29,8 @@ set(CMAKE_EXE_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -W ...@@ -29,8 +29,8 @@ set(CMAKE_EXE_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -W
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
option(LCR_GCOV "set lcr gcov option" OFF) option(ENABLE_GCOV "set lcr gcov option" OFF)
if (LCR_GCOV) if (ENABLE_GCOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
......
...@@ -103,10 +103,6 @@ if (CMAKE_TOOLCHAIN_FILE) ...@@ -103,10 +103,6 @@ if (CMAKE_TOOLCHAIN_FILE)
target_link_libraries(liblcr ${EXTRAL_LINK_LIBS}) target_link_libraries(liblcr ${EXTRAL_LINK_LIBS})
endif() endif()
if (LCR_GCOV)
target_link_libraries(liblcr -lgcov)
endif()
# install all files # install all files
install(TARGETS liblcr install(TARGETS liblcr
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE) LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
......
...@@ -37,8 +37,8 @@ macro(_DEFINE_NEW_TEST) ...@@ -37,8 +37,8 @@ macro(_DEFINE_NEW_TEST)
target_link_libraries(${ARGV0} target_link_libraries(${ARGV0}
isula_libutils isula_libutils
gtest ${GTEST_LIBRARY}
-lyajl ${LIBYAJL_LIBRARY}
pthread pthread
) )
...@@ -61,38 +61,48 @@ endmacro() ...@@ -61,38 +61,48 @@ endmacro()
# --------------- testcase add here ----------------- # --------------- testcase add here -----------------
# api testcase # api testcase
_DEFINE_NEW_TEST(log_llt log_testcase) _DEFINE_NEW_TEST(log_ut log_testcase)
_DEFINE_NEW_TEST(json_llt json_testcase) _DEFINE_NEW_TEST(libocispec_ut libocispec_testcase)
# mock test for run lcov to generate html # mock test for run lcov to generate html
add_executable(mock_llt main.cpp) add_executable(mock_ut main.cpp)
target_include_directories(mock_llt PUBLIC target_include_directories(mock_ut PUBLIC
${GTEST_INCLUDE_DIR} ${GTEST_INCLUDE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
) )
target_link_libraries(mock_llt target_link_libraries(mock_ut
gtest ${GTEST_LIBRARY}
pthread pthread
) )
add_dependencies(mock_llt log_llt json_llt) add_dependencies(mock_ut log_ut libocispec_ut)
set(result isula_libutils.info)
set(result_dir lcr_gcovs)
set(target_dir src/CMakeFiles/isula_libutils.dir)
# generate gcov # run ut and gcov
if (ENABLE_GCOV)
set(result isula_libutils.info)
set(result_dir lcr_gcovs)
set(target_dir src/CMakeFiles/isula_libutils.dir)
add_custom_command(TARGET mock_llt add_custom_command(TARGET mock_ut
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove -f ${result} COMMAND ${CMAKE_COMMAND} -E remove -f ${result}
COMMAND ${CMAKE_COMMAND} -E make_directory ${result_dir} COMMAND ${CMAKE_COMMAND} -E make_directory ${result_dir}
COMMAND "ctest" COMMAND ctest -VV
COMMAND ${CMD_LCOV} --gcov-tool ${CMD_GCOV} --exclude "/usr/*" --exclude "*/src/utils.c" --exclude "*/json/*" -d ${CMAKE_BINARY_DIR}/${target_dir} -c -o ${result} COMMAND ${CMD_LCOV} --gcov-tool ${CMD_GCOV} --exclude "/usr/*" --exclude "*/src/utils.c" --exclude "*/json/*" -d ${CMAKE_BINARY_DIR}/${target_dir} -c -o ${result}
COMMAND ${CMD_GENHTML} --ignore-errors source -o ${result_dir} ${result} COMMAND ${CMD_GENHTML} --ignore-errors source -o ${result_dir} ${result}
COMMAND ${CMAKE_COMMAND} -E echo LLT finish COMMAND ${CMAKE_COMMAND} -E echo run gcov finish
VERBATIM VERBATIM
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests
) )
else()
add_custom_command(TARGET mock_ut
PRE_BUILD
COMMAND ${CMAKE_CTEST_COMMAND} -VV
COMMAND ${CMAKE_COMMAND} -E echo UT finish
VERBATIM
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests
)
endif()
# --------------- testcase add finish ----------------- # --------------- testcase add finish -----------------
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "read_file.h" #include "read_file.h"
#include "oci_runtime_hooks.h" #include "oci_runtime_hooks.h"
TEST(json_testcase, test_oci_runtime_spec_hooks) TEST(libocispec_testcase, test_oci_runtime_spec_hooks)
{ {
const char *fname = "./ocihook.json"; const char *fname = "./ocihook.json";
oci_runtime_spec_hooks *hooks = nullptr; oci_runtime_spec_hooks *hooks = nullptr;
...@@ -79,7 +79,7 @@ TEST(json_testcase, test_oci_runtime_spec_hooks) ...@@ -79,7 +79,7 @@ TEST(json_testcase, test_oci_runtime_spec_hooks)
free(jstr); free(jstr);
} }
TEST(json_testcase, test_json_readfile) TEST(libocispec_testcase, test_json_readfile)
{ {
const char *fname = "./ocihook.json"; const char *fname = "./ocihook.json";
const char *not_exist = "/tmp/not_exist.json"; const char *not_exist = "/tmp/not_exist.json";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册