Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/e499f5c08f27b0fa738f7...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/e499f5c08f27b0fa738f784...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/e499f5c08f27b0fa738f784db...
The branch, dsilvers/assert-coverage has been updated
via e499f5c08f27b0fa738f784dbb91d8fc28d8ca01 (commit)
from 4e750bdab60ab5007a108a6c99de321e21bcf4ce (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=e499f5c08f27b0fa738...
commit e499f5c08f27b0fa738f784dbb91d8fc28d8ca01
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Support coverage flushing on assert()
When assert() is called, which is not uncommon in utility code within NetSurf,
we lose coverage data for anything done before the assert() in the test. This
commit corrects that oversight but is at least slightly GCC specific and may
need tweaks for non-Linux platforms.
By default, 'make coverage' will enable assert coverage, and it can be
disabled
with 'make coverage NOASSERTCOVERAGE=yes' if necessary.
Signed-off-by: Daniel Silverstone <dsilvers(a)netsurf-browser.org>
diff --git a/test/Makefile b/test/Makefile
index 833e7d6..39953a3 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -81,10 +81,19 @@ ifeq ($(MAKECMDGOALS),coverage)
COV_CXXFLAGS ?= -fprofile-arcs -ftest-coverage -O0
COV_LDFLAGS ?= -lgcov -fprofile-arcs
TESTROOT := $(COV_ROOT)
+ ifeq ($(NOASSERTCOVERAGE),yes)
+ NOCOV_TESTSOURCES ?=
+ COV_CPPFLAGS ?=
+ else
+ NOCOV_TESTSOURCES ?= test/assert.c
+ COV_CPPFLAGS ?= -D__assert_fail=__ns_assert_fail
+ endif
else
COV_CFLAGS ?= -O0
COV_CXXFLAGS ?= -O0
+ COV_CPPFLAGS ?=
TESTROOT := build/$(HOST)-test
+ NOCOV_TESTSOURCES ?=
endif
@@ -123,7 +132,7 @@ ifneq ($(CC_MAJOR),2)
COMMON_WARNFLAGS += -Wno-unused-parameter
endif
-TESTCFLAGS := -std=c99 -g \
+BASE_TESTCFLAGS := -std=c99 -g \
$(COMMON_WARNFLAGS) \
-D_BSD_SOURCE \
-D_POSIX_C_SOURCE=200809L \
@@ -131,8 +140,10 @@ TESTCFLAGS := -std=c99 -g \
-Itest -Iinclude -Icontent/handlers -Ifrontends -I. -I.. \
-Dnsgtk \
$(shell pkg-config --cflags libcurl libparserutils libwapcaplet libdom libnsutils
libutf8proc) \
- $(LIB_CFLAGS) \
- $(COV_CFLAGS)
+ $(LIB_CFLAGS)
+TESTCFLAGS := $(BASE_TESTCFLAGS) \
+ $(COV_CFLAGS) \
+ $(COV_CPPFLAGS)
TESTLDFLAGS := -L$(TESTROOT) \
$(shell pkg-config --libs libcurl libparserutils libwapcaplet libdom libnsutils
libutf8proc) -lz \
@@ -149,7 +160,7 @@ TESTSOURCES :=
GCOV ?= gcov
define gen_test_target
-$$(TESTROOT)/$(1): $$(sort $$(addprefix $$(TESTROOT)/,$$(subst /,_,$$(patsubst
%.c,%.o,$$(patsubst %.cpp,%.o,$$(patsubst %.m,%.o,$$(patsubst
%.s,%.o,$$($(1)_SRCS))))))))
+$$(TESTROOT)/$(1): $$(sort $$(addprefix $$(TESTROOT)/,$$(subst /,_,$$(patsubst
%.c,%.o,$$(patsubst %.cpp,%.o,$$(patsubst %.m,%.o,$$(patsubst %.s,%.o,$$($(1)_SRCS)
$$(NOCOV_TESTSOURCES))))))))
$$(VQ)echo "LINKTEST: $$@"
$$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$($(1)_LD) $$(TESTLDFLAGS)
@@ -171,12 +182,22 @@ $$(TESTROOT)/$(2): $(1) $$(TESTROOT)/created
endef
+define compile_test_nocov_target_c
+$$(TESTROOT)/$(2): $(1) $$(TESTROOT)/created
+ $$(VQ)echo " COMPILE: $(1) (No coverage)"
+ $$(Q)$$(RM) $$(TESTROOT)/$(2)
+ $$(Q)$$(CC) $$(BASE_TESTCFLAGS) -o $$(TESTROOT)/$(2) -c $(1)
+
+endef
+
# Generate target for each test program and the list of objects it needs
$(eval $(foreach TST,$(TESTS), $(call gen_test_target,$(TST))))
# generate target rules for test objects
$(eval $(foreach SOURCE,$(sort $(filter %.c,$(TESTSOURCES))), \
$(call compile_test_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst
/,_,$(SOURCE:.c=.d)))))
+$(eval $(foreach SOURCE,$(sort $(filter %.c,$(NOCOV_TESTSOURCES))), \
+ $(call compile_test_nocov_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst
/,_,$(SOURCE:.c=.d)))))
.PHONY:test coverage
diff --git a/test/assert.c b/test/assert.c
new file mode 100644
index 0000000..d21926e
--- /dev/null
+++ b/test/assert.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 Daniel Silverstone <dsilvers(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf,
http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <
http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Hack for assertion coverage output
+ */
+
+/* Bring in the real __assert_fail */
+#include <assert.h>
+
+/* This is what everyone else calls */
+extern void
+__ns_assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function)
+ __THROW __attribute__ ((__noreturn__));
+
+/* We use this to flush coverage data */
+extern void __gcov_flush(void);
+
+/* And here's our entry point */
+void
+__ns_assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function)
+{
+ __gcov_flush();
+ __assert_fail(__assertion, __file, __line, __function);
+}
-----------------------------------------------------------------------
Summary of changes:
test/Makefile | 29 +++++++++++++++++++++++++----
frontends/windows/file.h => test/assert.c | 26 ++++++++++++++++++++------
2 files changed, 45 insertions(+), 10 deletions(-)
copy frontends/windows/file.h => test/assert.c (53%)
diff --git a/test/Makefile b/test/Makefile
index 833e7d6..39953a3 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -81,10 +81,19 @@ ifeq ($(MAKECMDGOALS),coverage)
COV_CXXFLAGS ?= -fprofile-arcs -ftest-coverage -O0
COV_LDFLAGS ?= -lgcov -fprofile-arcs
TESTROOT := $(COV_ROOT)
+ ifeq ($(NOASSERTCOVERAGE),yes)
+ NOCOV_TESTSOURCES ?=
+ COV_CPPFLAGS ?=
+ else
+ NOCOV_TESTSOURCES ?= test/assert.c
+ COV_CPPFLAGS ?= -D__assert_fail=__ns_assert_fail
+ endif
else
COV_CFLAGS ?= -O0
COV_CXXFLAGS ?= -O0
+ COV_CPPFLAGS ?=
TESTROOT := build/$(HOST)-test
+ NOCOV_TESTSOURCES ?=
endif
@@ -123,7 +132,7 @@ ifneq ($(CC_MAJOR),2)
COMMON_WARNFLAGS += -Wno-unused-parameter
endif
-TESTCFLAGS := -std=c99 -g \
+BASE_TESTCFLAGS := -std=c99 -g \
$(COMMON_WARNFLAGS) \
-D_BSD_SOURCE \
-D_POSIX_C_SOURCE=200809L \
@@ -131,8 +140,10 @@ TESTCFLAGS := -std=c99 -g \
-Itest -Iinclude -Icontent/handlers -Ifrontends -I. -I.. \
-Dnsgtk \
$(shell pkg-config --cflags libcurl libparserutils libwapcaplet libdom libnsutils
libutf8proc) \
- $(LIB_CFLAGS) \
- $(COV_CFLAGS)
+ $(LIB_CFLAGS)
+TESTCFLAGS := $(BASE_TESTCFLAGS) \
+ $(COV_CFLAGS) \
+ $(COV_CPPFLAGS)
TESTLDFLAGS := -L$(TESTROOT) \
$(shell pkg-config --libs libcurl libparserutils libwapcaplet libdom libnsutils
libutf8proc) -lz \
@@ -149,7 +160,7 @@ TESTSOURCES :=
GCOV ?= gcov
define gen_test_target
-$$(TESTROOT)/$(1): $$(sort $$(addprefix $$(TESTROOT)/,$$(subst /,_,$$(patsubst
%.c,%.o,$$(patsubst %.cpp,%.o,$$(patsubst %.m,%.o,$$(patsubst
%.s,%.o,$$($(1)_SRCS))))))))
+$$(TESTROOT)/$(1): $$(sort $$(addprefix $$(TESTROOT)/,$$(subst /,_,$$(patsubst
%.c,%.o,$$(patsubst %.cpp,%.o,$$(patsubst %.m,%.o,$$(patsubst %.s,%.o,$$($(1)_SRCS)
$$(NOCOV_TESTSOURCES))))))))
$$(VQ)echo "LINKTEST: $$@"
$$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$($(1)_LD) $$(TESTLDFLAGS)
@@ -171,12 +182,22 @@ $$(TESTROOT)/$(2): $(1) $$(TESTROOT)/created
endef
+define compile_test_nocov_target_c
+$$(TESTROOT)/$(2): $(1) $$(TESTROOT)/created
+ $$(VQ)echo " COMPILE: $(1) (No coverage)"
+ $$(Q)$$(RM) $$(TESTROOT)/$(2)
+ $$(Q)$$(CC) $$(BASE_TESTCFLAGS) -o $$(TESTROOT)/$(2) -c $(1)
+
+endef
+
# Generate target for each test program and the list of objects it needs
$(eval $(foreach TST,$(TESTS), $(call gen_test_target,$(TST))))
# generate target rules for test objects
$(eval $(foreach SOURCE,$(sort $(filter %.c,$(TESTSOURCES))), \
$(call compile_test_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst
/,_,$(SOURCE:.c=.d)))))
+$(eval $(foreach SOURCE,$(sort $(filter %.c,$(NOCOV_TESTSOURCES))), \
+ $(call compile_test_nocov_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst
/,_,$(SOURCE:.c=.d)))))
.PHONY:test coverage
diff --git a/frontends/windows/file.h b/test/assert.c
similarity index 53%
copy from frontends/windows/file.h
copy to test/assert.c
index 5262dde..d21926e 100644
--- a/frontends/windows/file.h
+++ b/test/assert.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ * Copyright 2017 Daniel Silverstone <dsilvers(a)netsurf-browser.org>
*
* This file is part of NetSurf,
http://www.netsurf-browser.org/
*
@@ -18,12 +18,26 @@
/**
* \file
- * Windows file operation table interface.
+ * Hack for assertion coverage output
*/
-#ifndef _NETSURF_WINDOWS_FILE_H_
-#define _NETSURF_WINDOWS_FILE_H_
+/* Bring in the real __assert_fail */
+#include <assert.h>
-struct gui_file_table *win32_file_table;
+/* This is what everyone else calls */
+extern void
+__ns_assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function)
+ __THROW __attribute__ ((__noreturn__));
-#endif
+/* We use this to flush coverage data */
+extern void __gcov_flush(void);
+
+/* And here's our entry point */
+void
+__ns_assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function)
+{
+ __gcov_flush();
+ __assert_fail(__assertion, __file, __line, __function);
+}
--
NetSurf Browser