Skip to content

Commit

Permalink
Valgrind test are now part of cmake/ctest
Browse files Browse the repository at this point in the history
This change allow dependency validation and parallel testing.
  • Loading branch information
fnadeau committed May 30, 2021
1 parent 2548e9d commit fc91427
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ addons:
- lcov
- g++
- binutils-dev
- valgrind

before_install:
- if [[ $CC == gcc ]] ; then export CXX=g++ ; else export CXX=clang++ ; fi
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ endif(UNIX OR MSYS)
if (CGREEN_WITH_UNIT_TESTS)
include(MacroAddUnitTest)
include(MacroAddTest)
include(MacroAddValgrindTest)
add_subdirectory(tests)
if (UNIX OR MSYS)
# reflective runner only supported on UNIX/binutils platforms
Expand Down
15 changes: 0 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ chunked: doc
asciidoctor-chunker build/doc/cgreen-guide-en.html -o docs
echo open $(PWD)/docs/index.html

.PHONY:valgrind
valgrind: build-it
@echo -n "Running all tests under Valgrind "
@> valgrind.log
@for lib in `ls build/tests/$(PREFIX)*_tests$(SUFFIX)` ; \
do \
echo -n "." ; \
LD_LIBRARY_PATH=build/src valgrind --leak-check=full build/tools/cgreen-runner $$lib >> valgrind.log 2>&1 ; \
done
@echo
grep --with-filename --line-number " lost: " valgrind.log | grep -v " 0 bytes" ; \
if [ $$? -eq 1 ] ; then echo "Nothing lost" ; fi



############# Internal
.PHONY:build-it
build-it: build/Makefile
Expand Down
11 changes: 11 additions & 0 deletions cmake/Modules/FindValgrind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (NOT Valgrind_FOUND)

find_program(Valgrind_EXECUTABLE valgrind)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Valgrind DEFAULT_MSG Valgrind_EXECUTABLE)

set(Valgrind_FOUND ${Valgrind_FOUND} CACHE BOOL "Flag whether Valgrind package was found")
mark_as_advanced(Valgrind_FOUND Valgrind_EXECUTABLE)

endif ()
29 changes: 29 additions & 0 deletions cmake/Modules/MacroAddValgrindTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# - MACRO_ADD_VALGRIND_TEST(<args>)
#
# Calls add_test() with all the <args> but if on Win32 or Cygwin also adds the
# directory where the Cgreen library is generated to the path so that it will
# be used when running the test
#
# @thoni56/Thomas Nilefalk 2015-09-13

macro (macro_add_valgrind_test)
find_package(Valgrind)
if (Valgrind_FOUND)
set(
libname
${CMAKE_FIND_LIBRARY_PREFIXES}${ARGN}${CMAKE_SHARED_LIBRARY_SUFFIX}
)
add_test(
NAME valgrind_${libname}
COMMAND sh -c "LD_LIBRARY_PATH=build/src valgrind --leak-check=full tools/cgreen-runner ${CMAKE_CURRENT_BINARY_DIR}/${libname} 2>1&"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
set_tests_properties(
valgrind_${libname} PROPERTIES
FAIL_REGULAR_EXPRESSION "(definitely|indirectly|possible) lost: [1-9]"
)
if (CYGWIN OR WIN32)
set_tests_properties(${ARGV1} PROPERTIES ENVIRONMENT PATH=${PROJECT_BINARY_DIR}/src:$ENV{PATH})
endif ()
endif ()
endmacro(macro_add_valgrind_test)
12 changes: 12 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ set(CGREEN_C_TESTS_LIBRARY

add_library(${CGREEN_C_TESTS_LIBRARY} SHARED ${c_tests_library_SRCS})
target_link_libraries(${CGREEN_C_TESTS_LIBRARY} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${CGREEN_C_TESTS_LIBRARY})


set(c_tests_SRCS
all_c_tests.c
Expand Down Expand Up @@ -102,6 +104,8 @@ set(CGREEN_CPP_TESTS_LIBRARY
)
add_library(${CGREEN_CPP_TESTS_LIBRARY} SHARED ${cpp_tests_library_SRCS})
target_link_libraries(${CGREEN_CPP_TESTS_LIBRARY} ${CGREEN_LIBRARY} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
macro_add_valgrind_test(${CGREEN_CPP_TESTS_LIBRARY})


set(cpp_tests_SRCS
all_cpp_tests.cpp
Expand Down Expand Up @@ -148,6 +152,7 @@ if(LibBfd_FOUND)
)
add_library(${${case}_tests_library} SHARED ${${case}_tests_SRCS})
target_link_libraries(${${case}_tests_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${${case}_tests_library})
endforeach(case)


Expand All @@ -157,36 +162,43 @@ if(LibBfd_FOUND)
set(constraint_messages_library_SRCS constraint_messages_tests.c)
add_library(${constraint_messages_library} SHARED ${constraint_messages_library_SRCS})
target_link_libraries(${constraint_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${constraint_messages_library})

set(custom_constraint_messages_library custom_constraint_messages_tests)
set(custom_constraint_messages_library_SRCS custom_constraint_messages_tests.c)
add_library(${custom_constraint_messages_library} SHARED ${custom_constraint_messages_library_SRCS})
target_link_libraries(${custom_constraint_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${custom_constraint_messages_library})

set(mock_messages_library mock_messages_tests)
set(mock_messages_library_SRCS mock_messages_tests.c)
add_library(${mock_messages_library} SHARED ${mock_messages_library_SRCS})
target_link_libraries(${mock_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${mock_messages_library})

set(failure_messages_library failure_messages_tests)
set(failure_messages_library_SRCS failure_messages_tests.c)
add_library(${failure_messages_library} SHARED ${failure_messages_library_SRCS})
target_link_libraries(${failure_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${failure_messages_library})

set(assertion_messages_library assertion_messages_tests)
set(assertion_messages_library_SRCS assertion_messages_tests.c)
add_library(${assertion_messages_library} SHARED ${assertion_messages_library_SRCS})
target_link_libraries(${assertion_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${assertion_messages_library})

set(ignore_messages_library ignore_messages_tests)
set(ignore_messages_library_SRCS ignore_messages_tests.c)
add_library(${ignore_messages_library} SHARED ${ignore_messages_library_SRCS})
target_link_libraries(${ignore_messages_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${ignore_messages_library})

set(xml_output_library xml_output_tests)
set(xml_output_library_SRCS xml_output_tests.c)
add_library(${xml_output_library} SHARED ${xml_output_library_SRCS})
target_link_libraries(${xml_output_library} ${CGREEN_LIBRARY})
macro_add_valgrind_test(${xml_output_library})

set(TEST_TARGET_LIBRARIES ${CGREEN_LIBRARY})

Expand Down

0 comments on commit fc91427

Please sign in to comment.