aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-05-25 15:09:03 +0100
committerGitHub <noreply@github.com>2021-05-25 15:09:03 +0100
commitdf72df510f4696fb4835fd42e8f4de2dcb7cf428 (patch)
tree52f70c075cf9d1794a5c480535fffb091d23e094
parent6e8ffd28978f068741122f7894780f614e85ff12 (diff)
downloadlibvfio-user-df72df510f4696fb4835fd42e8f4de2dcb7cf428.zip
libvfio-user-df72df510f4696fb4835fd42e8f4de2dcb7cf428.tar.gz
libvfio-user-df72df510f4696fb4835fd42e8f4de2dcb7cf428.tar.bz2
add a gcov target (#498)
"make gcov" is sufficient to run the tests in DEBUG mode and generate gcov output for each .c file in lib/, to give us some idea of our coverage. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt3
-rw-r--r--Makefile29
-rw-r--r--lib/CMakeLists.txt27
4 files changed, 34 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index c4a5874..372611c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
build
cscope.out
tags
+lib/*.gcov
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8715625..10086ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,9 @@ include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSON REQUIRED json-c)
+# for the benefit of the gcov rules
+set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
+
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${JSON_INCLUDE_DIRS})
diff --git a/Makefile b/Makefile
index aae9071..f3b7779 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,11 @@ ifdef WITH_ASAN
LDFLAGS += -fsanitize=address
endif
+ifeq ($(MAKECMDGOALS), gcov)
+ CFLAGS += --coverage
+ LDFLAGS += --coverage
+endif
+
ifeq ($(VERBOSE),)
MAKEFLAGS += -s
endif
@@ -54,10 +59,10 @@ BUILD_DIR = $(BUILD_DIR_BASE)/$(BUILD_TYPE)
INSTALL_PREFIX ?= /usr/local
-PHONY_TARGETS := all pytest pytest-valgrind test pre-push realclean buildclean force_cmake tags
-.PHONY: $(PHONY_TARGETS)
+.PHONY: all test pytest pytest-valgrind
+.PHONY: pre-push clean realclean tags gcov
-all $(filter-out $(PHONY_TARGETS), $(MAKECMDGOALS)): $(BUILD_DIR)/Makefile
+all: $(BUILD_DIR)/Makefile
+$(MAKE) -C $(BUILD_DIR) $@
#
@@ -106,7 +111,11 @@ pytest-valgrind: all
endif
+ifdef WITH_GCOV
+test: all pytest
+else
test: all pytest
+endif
cd $(BUILD_DIR)/test; ctest --verbose
pre-push: realclean
@@ -119,13 +128,16 @@ pre-push: realclean
make test CC=gcc
make pytest-valgrind
-realclean:
- rm -rf $(BUILD_DIR_BASE)
+GCOVS=$(patsubst %.c,%.c.gcov, $(wildcard lib/*.c))
+
+gcov: realclean test $(GCOVS)
-buildclean:
+clean:
rm -rf $(BUILD_DIR)
-force_cmake: $(BUILD_DIR)/Makefile
+realclean:
+ rm -rf $(BUILD_DIR_BASE)
+ rm -rf $(GCOVS)
$(BUILD_DIR)/Makefile:
mkdir -p $(BUILD_DIR)
@@ -139,3 +151,6 @@ $(BUILD_DIR)/Makefile:
tags:
ctags -R --exclude=$(BUILD_DIR)
+
+lib/%.c.gcov: lib/%.c
+ cd lib && gcov -o ../build/$(BUILD_TYPE)/lib/CMakeFiles/$*.dir/$*.gcno $<
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 874c622..5605a9f 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -46,6 +46,14 @@ set(LIBOBJS
$<TARGET_OBJECTS:pci>
$<TARGET_OBJECTS:tran_sock>)
+add_library(pci_caps OBJECT pci_caps.c)
+add_library(dma OBJECT dma.c)
+add_library(irq OBJECT irq.c)
+add_library(libvfio-user OBJECT libvfio-user.c)
+add_library(migration OBJECT migration.c)
+add_library(pci OBJECT pci.c)
+add_library(tran_sock OBJECT tran_sock.c)
+
add_library(vfio-user-shared SHARED ${LIBOBJS})
target_link_libraries(vfio-user-shared json-c pthread)
set_target_properties(vfio-user-shared PROPERTIES
@@ -65,25 +73,6 @@ set_target_properties(vfio-user-static PROPERTIES
OUTPUT_NAME vfio-user
CLEAN_DIRECT_OUTPUT 1)
-set(UT_CFLAGS "-O0 -ggdb --coverage")
-set(UT_LFLAGS "--coverage")
-
-function(add_library_ut lib)
- add_library(${lib} OBJECT ${ARGN})
- set(lib_ut ${lib}_ut)
- add_library(${lib_ut} ${ARGN})
- set_target_properties(${lib_ut} PROPERTIES COMPILE_FLAGS ${UT_CFLAGS})
- set_target_properties(${lib_ut} PROPERTIES LINK_FLAGS ${UT_LFLAGS})
-endfunction(add_library_ut)
-
-add_library_ut(pci_caps pci_caps.c)
-add_library_ut(dma dma.c)
-add_library_ut(irq irq.c)
-add_library_ut(libvfio-user libvfio-user.c)
-add_library_ut(migration migration.c)
-add_library_ut(pci pci.c)
-add_library_ut(tran_sock tran_sock.c)
-
install(TARGETS vfio-user-shared
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})