diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-04-20 12:04:09 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-04-20 13:37:15 +0200 |
commit | d6516bde93e438fa380143b4dd76c542f08a791b (patch) | |
tree | db3fc15ef3f15d47da6ca6dbf8a04e94c8cc804f | |
parent | 73a6451b3a58452c804c0bdab844eec76163c38a (diff) | |
download | gnutls-freebsd.tar.gz |
tests: use mmap() for large memory allocations in systems that support itfreebsd
That allows the hash-large test to run on systems which its calloc()
is attempting to allocate an impossible amount of memory.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | tests/slow/hash-large.c | 28 |
2 files changed, 27 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index c04b39da34..ec08be8eb4 100644 --- a/configure.ac +++ b/configure.ac @@ -215,7 +215,7 @@ AC_C_BIGENDIAN dnl No fork on MinGW, disable some self-tests until we fix them. dnl Check clock_gettime and pthread_mutex_lock in libc (avoid linking to other libs) -AC_CHECK_FUNCS([fork inet_ntop inet_pton getrusage getpwuid_r nanosleep daemon getpid clock_gettime iconv localtime fmemopen vasprintf],,) +AC_CHECK_FUNCS([fork inet_ntop inet_pton getrusage getpwuid_r nanosleep daemon getpid clock_gettime iconv localtime fmemopen vasprintf mmap],,) if test "$ac_cv_func_vasprintf" != "yes";then AC_MSG_CHECKING([for va_copy]) AC_LINK_IFELSE([AC_LANG_PROGRAM([ diff --git a/tests/slow/hash-large.c b/tests/slow/hash-large.c index 41c2bd5012..96ebd53765 100644 --- a/tests/slow/hash-large.c +++ b/tests/slow/hash-large.c @@ -33,6 +33,29 @@ /* Test hashing on large buffers */ +#ifdef HAVE_MMAP + +#include <sys/mman.h> + +static size_t _mmap_size; +static void *get_mem(size_t size) +{ + _mmap_size = size; + return mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_ANONYMOUS, -1, 0); +} + +static void put_mem(void *mem) +{ + munmap(mem, _mmap_size); +} + +#else + +# define get_mem(x) calloc(1, x) +# define put_mem(x) free(x) + +#endif + void doit(void) { unsigned char digest[32]; @@ -47,7 +70,7 @@ void doit(void) global_init(); size = (ssize_t)UINT_MAX + (ssize_t)64*1024; - buf = calloc(1, size); + buf = get_mem(size); if (buf == NULL) exit(77); @@ -129,6 +152,7 @@ void doit(void) } } - free(buf); + put_mem(buf); gnutls_global_deinit(); } + |