Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/c512b2f054ce14321c8f6fae66696f880a74bbf1
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/c512b2f054ce14321c8f6fae66696f880a74bbf1
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/c512b2f054ce14321c8f6fae66696f880a74bbf1

The branch, master has been updated
       via  c512b2f054ce14321c8f6fae66696f880a74bbf1 (commit)
      from  3df40959e368c99275767ae630956d16f541fb75 (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=c512b2f054ce14321c8f6fae66696f880a74bbf1
commit c512b2f054ce14321c8f6fae66696f880a74bbf1
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    Add heap fault injection generator into tests
    
    This builds a dynamic library which can cause heap allocation (malloc)
    faliures after a specified number of calls. This is useful to allow
    tesing of memory failure allocation paths within netsurf test suites.
    
    An example test for core strings test has been added which
    incrementaly fails alloctions allowing all error paths in
    initialisation to be exercised.

diff --git a/test/Makefile b/test/Makefile
index 65d74a8..833e7d6 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -11,33 +11,32 @@ TESTS := \
        utils \
        messages \
        time \
-       mimesniff #llcache
+       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
 
 # nsurl sources
-nsurl_SRCS := utils/corestrings.c utils/nsurl/nsurl.c \
-               utils/nsurl/parse.c \
-               utils/idna.c utils/punycode.c \
-               test/log.c test/nsurl.c
+nsurl_SRCS := $(NSURL_SOURCES) utils/corestrings.c test/log.c test/nsurl.c
 
 # url database test sources
-urldbtest_SRCS := content/urldb.c \
-               utils/idna.c utils/bloom.c utils/nsoption.c \
-               utils/nsurl/nsurl.c utils/nsurl/parse.c \
-               utils/corestrings.c utils/punycode.c \
-               utils/hashtable.c utils/messages.c utils/time.c utils/utils.c \
-               test/log.c test/urldbtest.c
+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
 
 # low level cache sources
 llcache_SRCS := content/fetch.c content/fetchers/curl.c \
-               content/fetchers/about.c content/fetchers/data.c \
-               content/fetchers/resource.c content/llcache.c \
-               content/urldb.c \
-               image/image_cache.c \
-               utils/base64.c utils/corestrings.c utils/hashtable.c \
-               utils/nsurl/nsurl.c utils/nsurl/parse.c \
-               utils/messages.c utils/url.c utils/useragent.c \
-               utils/utils.c \
-               test/log.c test/llcache.c
+       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
 
 # messages test sources
 messages_SRCS := utils/messages.c utils/hashtable.c test/log.c test/messages.c
@@ -55,22 +54,26 @@ hashtable_SRCS := utils/hashtable.c test/log.c 
test/hashtable.c
 urlescape_SRCS := utils/url.c test/log.c test/urlescape.c
 
 # utility test sources
-utils_SRCS := utils/utils.c utils/messages.c utils/hashtable.c \
-               utils/corestrings.c utils/nsurl/nsurl.c \
-               utils/nsurl/parse.c utils/idna.c utils/punycode.c \
-               test/log.c test/utils.c
+utils_SRCS := $(NSURL_SOURCES) utils/utils.c utils/messages.c \
+       utils/hashtable.c utils/corestrings.c  \
+       test/log.c test/utils.c
 
 # time test sources
 time_SRCS := utils/time.c test/log.c test/time.c
 
 # mimesniff test sources
-mimesniff_SRCS := utils/hashtable.c utils/nsurl/nsurl.c utils/hashtable.c \
-       utils/nsurl/parse.c utils/corestrings.c utils/idna.c utils/punycode.c \
+mimesniff_SRCS := $(NSURL_SOURCES) utils/hashtable.c utils/corestrings.c \
        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
 
+# corestrings test sources
+corestrings_SRCS := $(NSURL_SOURCES) utils/corestrings.c \
+       test/log.c test/corestrings.c
+corestrings_LD := -lmalloc_fig
+
+
 # Coverage builds need additional flags
 COV_ROOT := build/$(HOST)-coverage
 ifeq ($(MAKECMDGOALS),coverage)
@@ -121,20 +124,24 @@ ifneq ($(CC_MAJOR),2)
 endif
 
 TESTCFLAGS := -std=c99 -g \
-               $(COMMON_WARNFLAGS) \
-               -D_BSD_SOURCE \
-               -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) \
-               $(LIB_CFLAGS) \
-               $(COV_CFLAGS)
-
-TESTLDFLAGS := $(shell pkg-config --libs libcurl libparserutils libwapcaplet 
libdom libnsutils libutf8proc) -lz \
-               $(LIB_LDFLAGS)\
-               $(COV_LDFLAGS)
-
+       $(COMMON_WARNFLAGS) \
+       -D_BSD_SOURCE \
+       -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) \
+       $(LIB_CFLAGS) \
+       $(COV_CFLAGS)
+
+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 $@
 
 # Source files for all tests being compiled
 TESTSOURCES :=
@@ -144,13 +151,13 @@ 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))))))))
        $$(VQ)echo "LINKTEST: $$@"
-       $$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$(TESTLDFLAGS)
+       $$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$($(1)_LD) $$(TESTLDFLAGS)
 
 .PHONY:$(1)_test
 
 $(1)_test:$$(TESTROOT)/$(1)
        $$(VQ)echo "RUN TEST: $(1)"
-       $$(Q)$$(TESTROOT)/$(1)
+       $$(Q)LD_LIBRARY_PATH=$$(TESTROOT)/ $$(TESTROOT)/$(1)
 
 TESTSOURCES += $$($(1)_SRCS)
 
@@ -174,7 +181,7 @@ $(eval $(foreach SOURCE,$(sort $(filter 
%.c,$(TESTSOURCES))), \
 
 .PHONY:test coverage
 
-test: $(TESTROOT)/created $(addsuffix _test,$(TESTS))
+test: $(TESTROOT)/created $(TESTROOT)/libmalloc_fig.so $(addsuffix 
_test,$(TESTS))
 
 coverage: test
 
diff --git a/test/corestrings.c b/test/corestrings.c
new file mode 100644
index 0000000..e8f68c0
--- /dev/null
+++ b/test/corestrings.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * 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
+ * Tests for corestrings.
+ */
+
+#include "utils/config.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <check.h>
+#include <limits.h>
+
+#include "utils/corestrings.h"
+
+#include "test/malloc_fig.h"
+
+START_TEST(corestrings_test)
+{
+       nserror ires;
+       nserror res;
+
+       malloc_limit(_i);
+
+       ires = corestrings_init();
+       res = corestrings_fini();
+
+       malloc_limit(UINT_MAX);
+
+       ck_assert_int_eq(ires, NSERROR_NOMEM);
+       ck_assert_int_eq(res, NSERROR_OK);
+}
+END_TEST
+
+
+static TCase *corestrings_case_create(void)
+{
+       TCase *tc;
+       tc = tcase_create("corestrings");
+
+       tcase_add_loop_test(tc, corestrings_test, 0, 437);
+
+       return tc;
+}
+
+
+/*
+ * corestrings test suite creation
+ */
+static Suite *corestrings_suite_create(void)
+{
+       Suite *s;
+       s = suite_create("Corestrings API");
+
+       suite_add_tcase(s, corestrings_case_create());
+
+       return s;
+}
+
+int main(int argc, char **argv)
+{
+       int number_failed;
+       SRunner *sr;
+
+       sr = srunner_create(corestrings_suite_create());
+
+       srunner_run_all(sr, CK_ENV);
+
+       number_failed = srunner_ntests_failed(sr);
+       srunner_free(sr);
+
+       return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/malloc_fig.c b/test/malloc_fig.c
new file mode 100644
index 0000000..19ff91e
--- /dev/null
+++ b/test/malloc_fig.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017 Vincent Sanders <[email protected]>
+ *
+ * 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
+ *
+ * heap fault injection generation.
+ *
+ * This library inject allocation faults into NetSurf tests
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdint.h>
+#include <limits.h>
+#include <dlfcn.h>
+
+#include "test/malloc_fig.h"
+
+static unsigned int count = UINT_MAX;
+
+void malloc_limit(unsigned int newcount)
+{
+       count = newcount;
+       //fprintf(stderr, "malloc_limit %d\n", count);
+}
+
+void* malloc(size_t size)
+{
+       static void* (*real_malloc)(size_t) = NULL;
+       void *p = NULL;
+
+       if (real_malloc == NULL) {
+               real_malloc = dlsym(RTLD_NEXT, "malloc");
+       }
+
+       if (count > 0) {
+               p = real_malloc(size);
+               count--;
+       }
+       //fprintf(stderr, "malloc(%d) = %p remian:%d\n", size, p, count);
+       return p;
+}
diff --git a/test/malloc_fig.h b/test/malloc_fig.h
new file mode 100644
index 0000000..3871f62
--- /dev/null
+++ b/test/malloc_fig.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 Vincent Sanders <[email protected]>
+ *
+ * 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
+ *
+ * Interface to heap fault injection generation.
+ *
+ * This library is used to inject allocation faults into NetSurf tests
+ */
+
+#ifndef NETSURF_TEST_MALLOC_FIG_H
+#define NETSURF_TEST_MALLOC_FIG_H
+
+void malloc_limit(unsigned int count);
+
+void* malloc(size_t size);
+
+#endif


-----------------------------------------------------------------------

Summary of changes:
 test/Makefile                                |   93 ++++++++++++++------------
 test/corestrings.c                           |   93 ++++++++++++++++++++++++++
 include/netsurf/types.h => test/malloc_fig.c |   47 ++++++++-----
 include/netsurf/types.h => test/malloc_fig.h |   23 ++-----
 4 files changed, 179 insertions(+), 77 deletions(-)
 create mode 100644 test/corestrings.c
 copy include/netsurf/types.h => test/malloc_fig.c (54%)
 copy include/netsurf/types.h => test/malloc_fig.h (69%)

diff --git a/test/Makefile b/test/Makefile
index 65d74a8..833e7d6 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -11,33 +11,32 @@ TESTS := \
        utils \
        messages \
        time \
-       mimesniff #llcache
+       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
 
 # nsurl sources
-nsurl_SRCS := utils/corestrings.c utils/nsurl/nsurl.c \
-               utils/nsurl/parse.c \
-               utils/idna.c utils/punycode.c \
-               test/log.c test/nsurl.c
+nsurl_SRCS := $(NSURL_SOURCES) utils/corestrings.c test/log.c test/nsurl.c
 
 # url database test sources
-urldbtest_SRCS := content/urldb.c \
-               utils/idna.c utils/bloom.c utils/nsoption.c \
-               utils/nsurl/nsurl.c utils/nsurl/parse.c \
-               utils/corestrings.c utils/punycode.c \
-               utils/hashtable.c utils/messages.c utils/time.c utils/utils.c \
-               test/log.c test/urldbtest.c
+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
 
 # low level cache sources
 llcache_SRCS := content/fetch.c content/fetchers/curl.c \
-               content/fetchers/about.c content/fetchers/data.c \
-               content/fetchers/resource.c content/llcache.c \
-               content/urldb.c \
-               image/image_cache.c \
-               utils/base64.c utils/corestrings.c utils/hashtable.c \
-               utils/nsurl/nsurl.c utils/nsurl/parse.c \
-               utils/messages.c utils/url.c utils/useragent.c \
-               utils/utils.c \
-               test/log.c test/llcache.c
+       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
 
 # messages test sources
 messages_SRCS := utils/messages.c utils/hashtable.c test/log.c test/messages.c
@@ -55,22 +54,26 @@ hashtable_SRCS := utils/hashtable.c test/log.c 
test/hashtable.c
 urlescape_SRCS := utils/url.c test/log.c test/urlescape.c
 
 # utility test sources
-utils_SRCS := utils/utils.c utils/messages.c utils/hashtable.c \
-               utils/corestrings.c utils/nsurl/nsurl.c \
-               utils/nsurl/parse.c utils/idna.c utils/punycode.c \
-               test/log.c test/utils.c
+utils_SRCS := $(NSURL_SOURCES) utils/utils.c utils/messages.c \
+       utils/hashtable.c utils/corestrings.c  \
+       test/log.c test/utils.c
 
 # time test sources
 time_SRCS := utils/time.c test/log.c test/time.c
 
 # mimesniff test sources
-mimesniff_SRCS := utils/hashtable.c utils/nsurl/nsurl.c utils/hashtable.c \
-       utils/nsurl/parse.c utils/corestrings.c utils/idna.c utils/punycode.c \
+mimesniff_SRCS := $(NSURL_SOURCES) utils/hashtable.c utils/corestrings.c \
        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
 
+# corestrings test sources
+corestrings_SRCS := $(NSURL_SOURCES) utils/corestrings.c \
+       test/log.c test/corestrings.c
+corestrings_LD := -lmalloc_fig
+
+
 # Coverage builds need additional flags
 COV_ROOT := build/$(HOST)-coverage
 ifeq ($(MAKECMDGOALS),coverage)
@@ -121,20 +124,24 @@ ifneq ($(CC_MAJOR),2)
 endif
 
 TESTCFLAGS := -std=c99 -g \
-               $(COMMON_WARNFLAGS) \
-               -D_BSD_SOURCE \
-               -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) \
-               $(LIB_CFLAGS) \
-               $(COV_CFLAGS)
-
-TESTLDFLAGS := $(shell pkg-config --libs libcurl libparserutils libwapcaplet 
libdom libnsutils libutf8proc) -lz \
-               $(LIB_LDFLAGS)\
-               $(COV_LDFLAGS)
-
+       $(COMMON_WARNFLAGS) \
+       -D_BSD_SOURCE \
+       -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) \
+       $(LIB_CFLAGS) \
+       $(COV_CFLAGS)
+
+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 $@
 
 # Source files for all tests being compiled
 TESTSOURCES :=
@@ -144,13 +151,13 @@ 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))))))))
        $$(VQ)echo "LINKTEST: $$@"
-       $$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$(TESTLDFLAGS)
+       $$(Q)$$(CC) $$(TESTCFLAGS) $$^ -o $$@ $$($(1)_LD) $$(TESTLDFLAGS)
 
 .PHONY:$(1)_test
 
 $(1)_test:$$(TESTROOT)/$(1)
        $$(VQ)echo "RUN TEST: $(1)"
-       $$(Q)$$(TESTROOT)/$(1)
+       $$(Q)LD_LIBRARY_PATH=$$(TESTROOT)/ $$(TESTROOT)/$(1)
 
 TESTSOURCES += $$($(1)_SRCS)
 
@@ -174,7 +181,7 @@ $(eval $(foreach SOURCE,$(sort $(filter 
%.c,$(TESTSOURCES))), \
 
 .PHONY:test coverage
 
-test: $(TESTROOT)/created $(addsuffix _test,$(TESTS))
+test: $(TESTROOT)/created $(TESTROOT)/libmalloc_fig.so $(addsuffix 
_test,$(TESTS))
 
 coverage: test
 
diff --git a/test/corestrings.c b/test/corestrings.c
new file mode 100644
index 0000000..e8f68c0
--- /dev/null
+++ b/test/corestrings.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016 Vincent Sanders <[email protected]>
+ *
+ * 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
+ * Tests for corestrings.
+ */
+
+#include "utils/config.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <check.h>
+#include <limits.h>
+
+#include "utils/corestrings.h"
+
+#include "test/malloc_fig.h"
+
+START_TEST(corestrings_test)
+{
+       nserror ires;
+       nserror res;
+
+       malloc_limit(_i);
+
+       ires = corestrings_init();
+       res = corestrings_fini();
+
+       malloc_limit(UINT_MAX);
+
+       ck_assert_int_eq(ires, NSERROR_NOMEM);
+       ck_assert_int_eq(res, NSERROR_OK);
+}
+END_TEST
+
+
+static TCase *corestrings_case_create(void)
+{
+       TCase *tc;
+       tc = tcase_create("corestrings");
+
+       tcase_add_loop_test(tc, corestrings_test, 0, 437);
+
+       return tc;
+}
+
+
+/*
+ * corestrings test suite creation
+ */
+static Suite *corestrings_suite_create(void)
+{
+       Suite *s;
+       s = suite_create("Corestrings API");
+
+       suite_add_tcase(s, corestrings_case_create());
+
+       return s;
+}
+
+int main(int argc, char **argv)
+{
+       int number_failed;
+       SRunner *sr;
+
+       sr = srunner_create(corestrings_suite_create());
+
+       srunner_run_all(sr, CK_ENV);
+
+       number_failed = srunner_ntests_failed(sr);
+       srunner_free(sr);
+
+       return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/include/netsurf/types.h b/test/malloc_fig.c
similarity index 54%
copy from include/netsurf/types.h
copy to test/malloc_fig.c
index 5c9501b..19ff91e 100644
--- a/include/netsurf/types.h
+++ b/test/malloc_fig.c
@@ -19,27 +19,40 @@
 /**
  * \file
  *
- * NetSurf types.
+ * heap fault injection generation.
  *
- * These are convenience types used throughout the browser.
+ * This library inject allocation faults into NetSurf tests
  */
 
-#ifndef NETSURF_TYPES_H
-#define NETSURF_TYPES_H
-
+#define _GNU_SOURCE
+#include <stdio.h>
 #include <stdint.h>
+#include <limits.h>
+#include <dlfcn.h>
 
-/**
- * Colour type: XBGR
- */
-typedef uint32_t colour;
+#include "test/malloc_fig.h"
 
-/**
- * Rectangle coordinates
- */
-typedef struct rect {
-       int x0, y0; /**< Top left */
-       int x1, y1; /**< Bottom right */
-} rect;
+static unsigned int count = UINT_MAX;
+
+void malloc_limit(unsigned int newcount)
+{
+       count = newcount;
+       //fprintf(stderr, "malloc_limit %d\n", count);
+}
+
+void* malloc(size_t size)
+{
+       static void* (*real_malloc)(size_t) = NULL;
+       void *p = NULL;
+
+       if (real_malloc == NULL) {
+               real_malloc = dlsym(RTLD_NEXT, "malloc");
+       }
 
-#endif
+       if (count > 0) {
+               p = real_malloc(size);
+               count--;
+       }
+       //fprintf(stderr, "malloc(%d) = %p remian:%d\n", size, p, count);
+       return p;
+}
diff --git a/include/netsurf/types.h b/test/malloc_fig.h
similarity index 69%
copy from include/netsurf/types.h
copy to test/malloc_fig.h
index 5c9501b..3871f62 100644
--- a/include/netsurf/types.h
+++ b/test/malloc_fig.h
@@ -19,27 +19,16 @@
 /**
  * \file
  *
- * NetSurf types.
+ * Interface to heap fault injection generation.
  *
- * These are convenience types used throughout the browser.
+ * This library is used to inject allocation faults into NetSurf tests
  */
 
-#ifndef NETSURF_TYPES_H
-#define NETSURF_TYPES_H
+#ifndef NETSURF_TEST_MALLOC_FIG_H
+#define NETSURF_TEST_MALLOC_FIG_H
 
-#include <stdint.h>
+void malloc_limit(unsigned int count);
 
-/**
- * Colour type: XBGR
- */
-typedef uint32_t colour;
-
-/**
- * Rectangle coordinates
- */
-typedef struct rect {
-       int x0, y0; /**< Top left */
-       int x1, y1; /**< Bottom right */
-} rect;
+void* malloc(size_t size);
 
 #endif


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to