Display test coverage information during building 32/163132/3
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 7 Dec 2017 07:13:31 +0000 (08:13 +0100)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Tue, 12 Dec 2017 11:35:32 +0000 (12:35 +0100)
Change-Id: I380fa6fc614150c6ff6e286a5e791ae1291bcd93
Signed-off-by: Konrad Kuchciak <k.kuchciak@samsung.com>
Makefile.am
tests/generate_coverage.sh [new file with mode: 0755]

index 2245594725bda5b6de37b30227e65fc578bad1b9..2324694486168abf0f4753a4ff25bbb81cd3b5b9 100644 (file)
@@ -83,7 +83,8 @@ serviceconfig_DATA = \
     conf.d/display-manager.service.conf
 
 sbin_PROGRAMS = faultd
-faultd_SOURCES = \
+
+faultdlib_SOURCES = \
     src/action/action_executed_handler.c \
     src/action/action_executor.c \
     src/core/action.c \
@@ -99,7 +100,6 @@ faultd_SOURCES = \
     src/event_types/service_failed_event.c \
     src/event_types/faultd_started_event.c \
     src/event_types/system_booted_event.c \
-    src/faultd.c \
     src/util/common.c \
     src/util/log.c \
     src/util/notify_queue.c \
@@ -108,9 +108,13 @@ faultd_SOURCES = \
     src/util/systemd_dbus.c
 
 if GLIB_MAINLOOP
-faultd_SOURCES += src/core/faultd-glib.c
+faultdlib_SOURCES += src/core/faultd-glib.c
 endif
 
+faultd_SOURCES = \
+    $(faultdlib_SOURCES) \
+    src/faultd.c
+
 # Add here source files of modules that must have ability to enable/disable during build
 # This variable is parsed by Autoconf
 EXTRA_faultd_SOURCES = \
@@ -207,12 +211,16 @@ check_PROGRAMS = test
 
 test_LDFLAGS = -ldl
 
-test_LDADD = $(CMOCKA_LIBS) $(LIBSYSTEMD_LIBS) $(AUDIT_LIBS) \
-    $(LIBEJDB_LIBS) $(JSON_C_LIBS)
+test_LDADD = \
+    $(faultd_LDADD) \
+    $(CMOCKA_LIBS) \
+    $(AUDIT_LIBS) \
+    $(LIBEJDB_LIBS)
 
 test_CFLAGS = -I${top_srcdir}/src/util \
        -D"FAULTD_MODNAME_T=$(call name_fix,$(modname))" \
-       -DTEST_BUILD
+       -DTEST_BUILD \
+       --coverage
 
 test_SOURCES = \
     tests/unit/ejdb_tests.c \
@@ -226,24 +234,10 @@ test_SOURCES = \
     tests/unit/runner.c \
     tests/unit/helpers.c \
     tests/unit/test_dbadapter.c \
-    src/core/event.c \
-    src/core/database.c \
-    src/core/service.c \
-    src/core/module.c \
-    src/core/faultd-config.c \
-    src/util/systemd_dbus.c \
-    src/util/log.c \
-    src/util/common.c \
-    src/util/json-config.c \
-    src/database/ejdb.c \
-    src/event_types/action_executed_event.c \
-    src/event_types/decision_made_event.c \
-    src/event_types/faultd_started_event.c \
-    src/event_types/resource_violation_event.c \
-    src/event_types/service_failed_event.c \
-    src/event_types/system_booted_event.c
+    $(faultdlib_SOURCES) \
+    $(EXTRA_faultd_SOURCES)
 
-TESTS = $(check_PROGRAMS)
+TESTS = $(check_PROGRAMS) tests/generate_coverage.sh
 endif
 
 generatorsdir = $(prefix)/lib/systemd/system-generators
diff --git a/tests/generate_coverage.sh b/tests/generate_coverage.sh
new file mode 100755 (executable)
index 0000000..2f2c0ce
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo -e "\nCALCULATING TEST COVERAGE...\n"
+
+report=`find src -name "*.gcno" -print0 | xargs -0 gcov -r`
+final_percentage=`echo "$report" | tail -1 | cut -d ":" -f 2`
+
+echo "$report" | sed '$ d' | grep -v 'Creating'
+echo -e "TOTAL COVERAGE: $final_percentage lines were executed\n"