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

Fix #251: cgreen-runner handle non-lib files #255

Merged
merged 22 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8692d76
Fix #251: cgreen-runner handle non-lib files
fnadeau May 9, 2021
afb00f4
Add travis dependency
fnadeau May 9, 2021
ec2d46c
Adapt discoverer unit test
fnadeau May 13, 2021
956dc6f
Document build instruction and dependency
fnadeau May 16, 2021
2d7e2b8
Valgrind test are now part of cmake/ctest
fnadeau May 30, 2021
1eb64d1
[build] Restore 'make unit' caused by wrong path to runner
thoni56 Dec 26, 2021
411658b
[cmake] Move setting CGREEN_LIBRARY to top-level so it can be used ev…
thoni56 Dec 26, 2021
0203062
[cmake] Move setting CGREEN_LIBRARY to top-level so it can be used ev…
thoni56 Dec 26, 2021
00e1004
[build] Fix one linking issue on Cygwin for discoverer unit tests
thoni56 Dec 26, 2021
586cd00
[build][cygwin] Explicitly add LIBINTL on (probably package dependenc…
thoni56 Dec 26, 2021
f3ae074
[cygwin][intl] Add INTL library only if Cygwin
thoni56 Dec 26, 2021
7945aea
[build][valgrind] Remove finding Valgrind from MacroAddValgrindTest
thoni56 Dec 26, 2021
3aa379e
[build] Build library (in src) before setting CGREEN_LIBRARY
thoni56 Dec 26, 2021
aac095e
[build][cygwin] Rename CMake variable for explicit intlib
thoni56 Dec 27, 2021
3742c88
[build][tools] Add missing test_item.c to discoverer unit test build
thoni56 Dec 27, 2021
9767e2f
[runner] Differentiate between returning 0 and error when getting symtab
thoni56 Dec 27, 2021
968a6b3
[tools][unittests] Re-imagine to avoid using the runner for unittesti…
thoni56 Dec 27, 2021
92fbd8c
[tools][refactor] Extract a given_a_file_with_dynamic_symbol_table()
thoni56 Dec 28, 2021
d078e83
[tools][runner] Add check for dynamic symbol table format
thoni56 Dec 28, 2021
326c5a5
[tools][bfd] Add non-dynamic versions of symtab_upper_bounds & canoni…
thoni56 Dec 28, 2021
12d3699
[tools][runner] Re-merge dynamic and non-dynamic symbol reading
thoni56 Dec 28, 2021
873c5c9
Merge branch 'master' into bugfix/cgreen-runner_nm_parsing
thoni56 Dec 28, 2021
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ addons:
- cmake
- lcov
- g++
- binutils-dev
- valgrind

before_install:
- if [[ $CC == gcc ]] ; then export CXX=g++ ; else export CXX=clang++ ; fi
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ include(ConfigureChecks.cmake)
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

# check subdirectories
add_subdirectory(src)
# Dependency on our own library so we can use CGREEN_LIBRARY in all subdirectories
if (CGREEN_WITH_STATIC_LIBRARY)
set(CGREEN_LIBRARY ${CGREEN_STATIC_LIBRARY})
else ()
set(CGREEN_LIBRARY ${CGREEN_SHARED_LIBRARY})
endif()

add_subdirectory(doc)
add_subdirectory(include)
add_subdirectory(src)
if (UNIX OR MSYS)
# reflective runner only supported on UNIX/binutils platforms
add_subdirectory(tools)
Expand All @@ -91,6 +98,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
91 changes: 34 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif

# Removing ninja support as it does not build the same way and somehow
# trashes the output comparison tests with different paths and library names
#NINJA_EXISTS := $(shell command -v ninja 2>/dev/null)
ifdef NINJA_EXISTS
BUILDER = ninja
GENERATOR = -G Ninja
else
BUILDER = $(MAKE)
endif

all: build/Makefile
cd build; $(BUILDER)
.PHONY:all
all: build-it

.PHONY:debug
debug: build
Expand Down Expand Up @@ -100,30 +90,33 @@ DIFF_TOOL_ARGUMENTS = $(1)_tests \
../../tests \
$(1)_tests.expected

.PHONY: unit
unit: build-it
cd build ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_c_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_cpp_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tools/tests -name $(PREFIX)cgreen_runner_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
cd tests ; \
$(LDPATH) $(XML_DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,xml_output) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,assertion_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,mock_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,custom_constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,ignore_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) CGREEN_PER_TEST_TIMEOUT=1 $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,failure_messages) ; \
r=$$((r + $$?)) ; \
exit $$r
if [ -f build/tools/cgreen-runner ]; then \
cd build ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_c_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_cpp_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tools/tests -name $(PREFIX)cgreen_runner_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
cd tests ; \
$(LDPATH) $(XML_DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,xml_output) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,assertion_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,mock_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,custom_constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,ignore_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) CGREEN_PER_TEST_TIMEOUT=1 $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,failure_messages) ; \
r=$$((r + $$?)) ; \
exit $$r; \
fi

.PHONY: doc
doc: build
Expand All @@ -136,35 +129,19 @@ 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
.PHONY:build-it
build-it: build/Makefile
$(BUILDER) -C build
$(MAKE) -C build

build:
mkdir build
mkdir -p build

build/Makefile: build
build/Makefile: | build
ifeq ($(OS),Darwin)
cd build; cmake -DCMAKE_OSX_ARCHITECTURES="arm64e;x86_64" $(GENERATOR) ..
cd build; cmake -DCMAKE_OSX_ARCHITECTURES="arm64e;x86_64" ..
else
cd build; cmake $(GENERATOR) ..
cd build; cmake ..
endif

.SILENT:
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,43 @@ You can also clone the repository or download the source zip from [GitHub](http:
You need the [CMake](http://www.cmake.org) build system.
Most standard C/C++ compilers should work. GCC definitely does.

Perl, diff, find and sed are quired to run unit-tests. Most distro will have
those already installed.

To build cgreen-runner, you need binutils development package. At runtime,
cgreen-runner only requires binutils library. Some distro do not distinguish the
two.

|Distro | Build | Run |
--- | --- | ---
|Arch|bintuils|bintuils|
|Cygwin|cygwin64-libbfd|cygwin64-libbfd|
|Debian|binutils-dev|libbinutils|
|Fedora|bintuils-devel|bintuils-devel|
|OpenSUSE|bintuils-devel|bintuils-devel|

In the root directory run ``make``. That will configure and build the
library and the `cgreen-runner`, both supporting both C and C++. See
also the documentation.
also the documentation. The later will only be build if build requirements are met.

Here are some example of how to build using docker for various distro:

```
# debian build (will not clean)
$ docker run --rm -v $PWD:/cgreen debian bash -c \
"apt update && apt -y install git cmake gcc g++ binutils-dev && cd /cgreen && make unit test"
# debian run (we cannot use make unit test since cmake will want to recompile)
$ docker run --rm -v $PWD:/cgreen debian bash -c \
'apt update && apt -y install libbinutils && cd /cgreen && ./build/tools/cgreen-runner $(find . -name *.so) rm -rf build'

# Fedora
$ docker run -t --rm -v $PWD:/cgreen fedora bash -c \
"/usr/bin/yum -y install cmake gcc g++ git diffutils findutils && cd /cgreen && make unit test && make clean"

# OpenSUSE
$ docker run --rm -v $PWD:/cgreen opensuse/tumbleweed bash -c \
'/usr/bin/zypper refresh && /usr/bin/zypper --non-interactive install git cmake gcc gcc-c++ git binutils-devel diffutils findutils && cd /cgreen && make unit test && make clean'
```

## Using It

Expand Down
87 changes: 87 additions & 0 deletions cmake/Modules/FindLibBfd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# - Try to find libbfd
# Once done this will define
#
# LIBBFD_FOUND - system has libbfd
# LIBBFD_INCLUDE_DIRS - the libbfd include directory
# LIBBFD_LIBRARIES - Link these to use libbfd
# LIBBFD_DEFINITIONS - Compiler switches required for using libbfd
#
# Based on:
#
# Copyright (c) 2008 Bernhard Walle <bernhard.walle@gmx.de>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#


if (LIBBFD_LIBRARIES AND LIBBFD_INCLUDE_DIRS)
set (LIBBFD_FIND_QUIETLY TRUE)
endif ()

find_path (LIBBFD_INCLUDE_DIRS
NAMES
bfd.h
dis-asm.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/opt/include
ENV CPATH)

# Ugly, yes ugly...
find_library (LIBBFD_BFD_LIBRARY
NAMES
bfd
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/usr/include
/opt/local/lib
/opt/usr/lib64
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)

find_library (LIBIBERTY_LIBRARY
NAMES
iberty
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/usr/include
/opt/local/lib
/opt/usr/lib64
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)

find_library (LIBZ_LIBRARY
NAMES
z
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/usr/include
/opt/local/lib
/opt/usr/lib64
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)

include (FindPackageHandleStandardArgs)

# handle the QUIETLY and REQUIRED arguments and set LIBBFD_FOUND to TRUE if all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBfd DEFAULT_MSG
LIBBFD_BFD_LIBRARY
LIBBFD_INCLUDE_DIRS
LIBIBERTY_LIBRARY
LIBZ_LIBRARY)

set(LIBBFD_LIBRARIES "${LIBBFD_BFD_LIBRARY}" "${LIBIBERTY_LIBRARY}" "${LIBZ_LIBRARY}")
mark_as_advanced(LIBBFD_INCLUDE_DIRS LIBBFD_LIBRARIES LIBBFD_BFD_LIBRARY LIBIBERTY_LIBRARY LIBZ_LIBRARY)
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 ()
28 changes: 28 additions & 0 deletions cmake/Modules/MacroAddValgrindTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# - 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)
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)
Loading