2015-07-07 02:05:05 +03:00
|
|
|
#
|
|
|
|
# NetSurf unit tests
|
|
|
|
|
2016-08-11 20:43:31 +03:00
|
|
|
TESTS := \
|
|
|
|
nsurl \
|
|
|
|
urldbtest \
|
|
|
|
nsoption \
|
|
|
|
bloom \
|
|
|
|
hashtable \
|
|
|
|
urlescape \
|
|
|
|
utils \
|
|
|
|
messages \
|
2017-03-20 03:48:11 +03:00
|
|
|
time \
|
2017-03-22 11:50:09 +03:00
|
|
|
mimesniff \
|
|
|
|
corestrings #llcache
|
|
|
|
|
|
|
|
# sources necessary to use nsurl functionality
|
|
|
|
NSURL_SOURCES := utils/nsurl/nsurl.c utils/nsurl/parse.c utils/idna.c \
|
|
|
|
utils/punycode.c
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2015-07-12 13:24:20 +03:00
|
|
|
# nsurl sources
|
2017-03-22 11:50:09 +03:00
|
|
|
nsurl_SRCS := $(NSURL_SOURCES) utils/corestrings.c test/log.c test/nsurl.c
|
2015-07-09 00:17:20 +03:00
|
|
|
|
2015-07-12 13:24:20 +03:00
|
|
|
# url database test sources
|
2017-03-22 11:50:09 +03:00
|
|
|
urldbtest_SRCS := $(NSURL_SOURCES) \
|
|
|
|
utils/bloom.c utils/nsoption.c utils/corestrings.c utils/time.c \
|
|
|
|
utils/hashtable.c utils/messages.c utils/utils.c \
|
|
|
|
content/urldb.c \
|
|
|
|
test/log.c test/urldbtest.c
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2015-07-12 13:24:20 +03:00
|
|
|
# low level cache sources
|
2011-10-15 01:29:13 +04:00
|
|
|
llcache_SRCS := content/fetch.c content/fetchers/curl.c \
|
2017-03-22 11:50:09 +03:00
|
|
|
content/fetchers/about.c content/fetchers/data.c \
|
|
|
|
content/fetchers/resource.c content/llcache.c \
|
|
|
|
content/urldb.c \
|
|
|
|
image/image_cache.c \
|
|
|
|
$(NSURL_SOURCES) utils/base64.c utils/corestrings.c utils/hashtable.c \
|
|
|
|
utils/messages.c utils/url.c utils/useragent.c utils/utils.c \
|
|
|
|
test/log.c test/llcache.c
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2016-08-07 01:43:23 +03:00
|
|
|
# messages test sources
|
|
|
|
messages_SRCS := utils/messages.c utils/hashtable.c test/log.c test/messages.c
|
|
|
|
|
2015-07-12 13:24:20 +03:00
|
|
|
# nsoption test sources
|
|
|
|
nsoption_SRCS := utils/nsoption.c test/log.c test/nsoption.c
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2015-07-12 13:24:20 +03:00
|
|
|
# Bloom filter test sources
|
|
|
|
bloom_SRCS := utils/bloom.c test/bloom.c
|
|
|
|
|
|
|
|
# hash table test sources
|
|
|
|
hashtable_SRCS := utils/hashtable.c test/log.c test/hashtable.c
|
2013-05-27 12:35:16 +04:00
|
|
|
|
2016-07-31 15:24:26 +03:00
|
|
|
# url escape test sources
|
|
|
|
urlescape_SRCS := utils/url.c test/log.c test/urlescape.c
|
|
|
|
|
2016-08-04 02:19:48 +03:00
|
|
|
# utility test sources
|
2017-03-22 11:50:09 +03:00
|
|
|
utils_SRCS := $(NSURL_SOURCES) utils/utils.c utils/messages.c \
|
|
|
|
utils/hashtable.c utils/corestrings.c \
|
|
|
|
test/log.c test/utils.c
|
2016-08-04 02:19:48 +03:00
|
|
|
|
2016-08-11 20:43:31 +03:00
|
|
|
# time test sources
|
|
|
|
time_SRCS := utils/time.c test/log.c test/time.c
|
|
|
|
|
2017-03-20 03:48:11 +03:00
|
|
|
# mimesniff test sources
|
2017-03-22 11:50:09 +03:00
|
|
|
mimesniff_SRCS := $(NSURL_SOURCES) utils/hashtable.c utils/corestrings.c \
|
2017-03-20 03:48:11 +03:00
|
|
|
utils/http/generics.c utils/http/content-type.c \
|
|
|
|
utils/http/primitives.c utils/messages.c utils/http/parameter.c \
|
|
|
|
content/mimesniff.c \
|
|
|
|
test/log.c test/mimesniff.c
|
|
|
|
|
2017-03-22 11:50:09 +03:00
|
|
|
# corestrings test sources
|
|
|
|
corestrings_SRCS := $(NSURL_SOURCES) utils/corestrings.c \
|
|
|
|
test/log.c test/corestrings.c
|
|
|
|
corestrings_LD := -lmalloc_fig
|
|
|
|
|
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
# Coverage builds need additional flags
|
2017-01-06 02:00:41 +03:00
|
|
|
COV_ROOT := build/$(HOST)-coverage
|
2015-07-09 00:17:20 +03:00
|
|
|
ifeq ($(MAKECMDGOALS),coverage)
|
2016-04-14 23:08:10 +03:00
|
|
|
COV_CFLAGS ?= -fprofile-arcs -ftest-coverage -O0
|
|
|
|
COV_CXXFLAGS ?= -fprofile-arcs -ftest-coverage -O0
|
|
|
|
COV_LDFLAGS ?= -lgcov -fprofile-arcs
|
2017-01-06 02:00:41 +03:00
|
|
|
TESTROOT := $(COV_ROOT)
|
2017-03-31 20:53:52 +03:00
|
|
|
ifeq ($(NOASSERTCOVERAGE),yes)
|
|
|
|
NOCOV_TESTSOURCES ?=
|
|
|
|
COV_CPPFLAGS ?=
|
|
|
|
else
|
|
|
|
NOCOV_TESTSOURCES ?= test/assert.c
|
|
|
|
COV_CPPFLAGS ?= -D__assert_fail=__ns_assert_fail
|
|
|
|
endif
|
2015-07-09 00:17:20 +03:00
|
|
|
else
|
2016-04-14 23:08:10 +03:00
|
|
|
COV_CFLAGS ?= -O0
|
|
|
|
COV_CXXFLAGS ?= -O0
|
2017-03-31 20:53:52 +03:00
|
|
|
COV_CPPFLAGS ?=
|
2017-01-06 02:00:41 +03:00
|
|
|
TESTROOT := build/$(HOST)-test
|
2017-03-31 20:53:52 +03:00
|
|
|
NOCOV_TESTSOURCES ?=
|
2015-07-09 00:17:20 +03:00
|
|
|
endif
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2016-04-14 23:08:10 +03:00
|
|
|
|
|
|
|
# Extend flags with appropriate values from pkg-config for enabled features
|
|
|
|
#
|
|
|
|
# 1: pkg-config required modules for feature
|
|
|
|
# 2: Human-readable name for the feature
|
|
|
|
define pkg_cfg_detect_lib
|
|
|
|
ifeq ($$(PKG_CONFIG),)
|
|
|
|
$$(error pkg-config is required to auto-detect feature availability)
|
|
|
|
endif
|
|
|
|
|
|
|
|
PKG_CONFIG_$(1)_EXISTS := $$(shell $$(PKG_CONFIG) --exists $(1) && echo yes)
|
|
|
|
|
|
|
|
ifeq ($$(PKG_CONFIG_$(1)_EXISTS),yes)
|
|
|
|
LIB_CFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(1))
|
|
|
|
LIB_CXXFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(1))
|
|
|
|
LIB_LDFLAGS += $$(shell $$(PKG_CONFIG) --libs $(1))
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
$$(info PKG.CNFG: $(2) ($(1)) enabled)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
$$(info PKG.CNFG: $(2) ($(1)) disabled)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
$(eval $(call pkg_cfg_detect_lib,check,Check))
|
|
|
|
|
2016-08-08 15:52:54 +03:00
|
|
|
COMMON_WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wcast-align \
|
|
|
|
-Wwrite-strings -Wmissing-declarations -Wuninitialized
|
2016-04-14 23:08:10 +03:00
|
|
|
|
2016-08-08 15:52:54 +03:00
|
|
|
ifneq ($(CC_MAJOR),2)
|
|
|
|
COMMON_WARNFLAGS += -Wno-unused-parameter
|
|
|
|
endif
|
|
|
|
|
2017-03-31 20:53:52 +03:00
|
|
|
BASE_TESTCFLAGS := -std=c99 -g \
|
2017-03-22 11:50:09 +03:00
|
|
|
$(COMMON_WARNFLAGS) \
|
2017-08-28 13:15:06 +03:00
|
|
|
-D_DEFAULT_SOURCE \
|
2017-03-22 11:50:09 +03:00
|
|
|
-D_POSIX_C_SOURCE=200809L \
|
|
|
|
-D_XOPEN_SOURCE=600 \
|
|
|
|
-Itest -Iinclude -Icontent/handlers -Ifrontends -I. -I.. \
|
|
|
|
-Dnsgtk \
|
|
|
|
$(shell pkg-config --cflags libcurl libparserutils libwapcaplet libdom libnsutils libutf8proc) \
|
2017-03-31 20:53:52 +03:00
|
|
|
$(LIB_CFLAGS)
|
|
|
|
TESTCFLAGS := $(BASE_TESTCFLAGS) \
|
|
|
|
$(COV_CFLAGS) \
|
|
|
|
$(COV_CPPFLAGS)
|
2017-03-22 11:50:09 +03:00
|
|
|
|
|
|
|
TESTLDFLAGS := -L$(TESTROOT) \
|
|
|
|
$(shell pkg-config --libs libcurl libparserutils libwapcaplet libdom libnsutils libutf8proc) -lz \
|
|
|
|
$(LIB_LDFLAGS)\
|
|
|
|
$(COV_LDFLAGS)
|
|
|
|
|
|
|
|
# malloc faliure injection generator
|
|
|
|
$(TESTROOT)/libmalloc_fig.so:test/malloc_fig.c
|
|
|
|
$(CC) -shared -fPIC -I. -std=c99 $(COMMON_WARNFLAGS) $^ -o $@
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
# Source files for all tests being compiled
|
|
|
|
TESTSOURCES :=
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
GCOV ?= gcov
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
define gen_test_target
|
2017-03-31 20:53:52 +03:00
|
|
|
$$(TESTROOT)/$(1): $$(sort $$(addprefix $$(TESTROOT)/,$$(subst /,_,$$(patsubst %.c,%.o,$$(patsubst %.cpp,%.o,$$(patsubst %.m,%.o,$$(patsubst %.s,%.o,$$($(1)_SRCS) $$(NOCOV_TESTSOURCES))))))))
|
2015-07-09 00:17:20 +03:00
|
|
|
$$(VQ)echo "LINKTEST: $$@"
|
2017-03-22 11:50:09 +03:00
|
|
|
$$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$($(1)_LD) $$(TESTLDFLAGS)
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
.PHONY:$(1)_test
|
|
|
|
|
|
|
|
$(1)_test:$$(TESTROOT)/$(1)
|
|
|
|
$$(VQ)echo "RUN TEST: $(1)"
|
2017-03-22 11:50:09 +03:00
|
|
|
$$(Q)LD_LIBRARY_PATH=$$(TESTROOT)/ $$(TESTROOT)/$(1)
|
2015-07-09 00:17:20 +03:00
|
|
|
|
|
|
|
TESTSOURCES += $$($(1)_SRCS)
|
|
|
|
|
|
|
|
endef
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
define compile_test_target_c
|
|
|
|
$$(TESTROOT)/$(2): $(1) $$(TESTROOT)/created
|
|
|
|
$$(VQ)echo " COMPILE: $(1)"
|
|
|
|
$$(Q)$$(RM) $$(TESTROOT)/$(2)
|
|
|
|
$$(Q)$$(CC) $$(TESTCFLAGS) -o $$(TESTROOT)/$(2) -c $(1)
|
2015-07-07 18:02:54 +03:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
endef
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2017-03-31 20:53:52 +03:00
|
|
|
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
|
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
# Generate target for each test program and the list of objects it needs
|
|
|
|
$(eval $(foreach TST,$(TESTS), $(call gen_test_target,$(TST))))
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
# 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)))))
|
2017-03-31 20:53:52 +03:00
|
|
|
$(eval $(foreach SOURCE,$(sort $(filter %.c,$(NOCOV_TESTSOURCES))), \
|
|
|
|
$(call compile_test_nocov_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst /,_,$(SOURCE:.c=.d)))))
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
|
2015-07-09 00:17:20 +03:00
|
|
|
.PHONY:test coverage
|
2011-10-15 01:29:13 +04:00
|
|
|
|
2017-03-22 11:50:09 +03:00
|
|
|
test: $(TESTROOT)/created $(TESTROOT)/libmalloc_fig.so $(addsuffix _test,$(TESTS))
|
2015-07-09 00:17:20 +03:00
|
|
|
|
|
|
|
coverage: test
|
|
|
|
|
|
|
|
$(TESTROOT)/created:
|
|
|
|
$(VQ)echo " MKDIR: $(TESTROOT)"
|
2017-01-07 16:21:25 +03:00
|
|
|
$(Q)$(MKDIR) -p $(TESTROOT)
|
2015-07-09 00:17:20 +03:00
|
|
|
$(Q)$(TOUCH) $@
|
2013-05-27 12:35:16 +04:00
|
|
|
|
2015-07-07 18:02:54 +03:00
|
|
|
.PHONY: test-clean
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2015-07-07 18:02:54 +03:00
|
|
|
test-clean:
|
2015-07-09 00:17:20 +03:00
|
|
|
$(VQ)echo " CLEAN: $(TESTROOT)"
|
2017-01-06 02:00:41 +03:00
|
|
|
$(VQ)echo " CLEAN: $(COV_ROOT)"
|
|
|
|
$(Q)$(RM) -r $(TESTROOT) $(COV_ROOT)
|
2015-07-09 00:17:20 +03:00
|
|
|
CLEANS += test-clean
|