mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 18:15:18 -07:00
Limit resources when running tests
The default memory limit matches the limit already used when running the javascript and webassembly tests. Original diff by @pilou- Fixes #837
This commit is contained in:
parent
e24847c364
commit
9567bbe65f
@ -554,7 +554,7 @@ AC_SUBST(CFLAGS_AESNI)
|
||||
AC_SUBST(CFLAGS_PCLMUL)
|
||||
AC_SUBST(CFLAGS_RDRAND)
|
||||
|
||||
AC_CHECK_HEADERS([sys/mman.h sys/random.h intrin.h])
|
||||
AC_CHECK_HEADERS([sys/mman.h sys/random.h sys/resource.h intrin.h])
|
||||
|
||||
AC_MSG_CHECKING([if _xgetbv() is available])
|
||||
AC_LINK_IFELSE(
|
||||
@ -796,6 +796,7 @@ AC_FUNC_ALLOCA
|
||||
AS_IF([test "x$EMSCRIPTEN" = "x"],[
|
||||
AC_CHECK_FUNCS([arc4random arc4random_buf])
|
||||
AC_CHECK_FUNCS([mmap mlock madvise mprotect])
|
||||
AC_CHECK_FUNCS([setrlimit])
|
||||
|
||||
AC_MSG_CHECKING(for getrandom with a standard API)
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
|
@ -14,9 +14,19 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SETRLIMIT)
|
||||
# include <sys/types.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include "sodium.h"
|
||||
#include "quirks.h"
|
||||
|
||||
#ifndef TOTAL_MEMORY_TESTS
|
||||
# define TOTAL_MEMORY_TESTS 16777216
|
||||
#endif
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
# undef TEST_SRCDIR
|
||||
# define TEST_SRCDIR "/test-data"
|
||||
@ -37,6 +47,25 @@ int xmain(void);
|
||||
|
||||
static unsigned char *guard_page;
|
||||
|
||||
static int set_resource_limits(void)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
#if defined(RLIM_INFINITY) && defined(HAVE_SETRLIMIT)
|
||||
struct rlimit limits;
|
||||
|
||||
limits.rlim_cur = limits.rlim_max = TOTAL_MEMORY_TESTS;
|
||||
# ifdef RLIMIT_AS
|
||||
res |= setrlimit(RLIMIT_AS, &limits);
|
||||
# endif
|
||||
# ifdef RLIMIT_DATA
|
||||
res |= setrlimit(RLIMIT_DATA, &limits);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef BENCHMARKS
|
||||
|
||||
# include <sys/time.h>
|
||||
@ -136,6 +165,8 @@ int main(void)
|
||||
unsigned long long ts_end;
|
||||
unsigned int i;
|
||||
|
||||
(void) set_resource_limits();
|
||||
|
||||
if (sodium_init() != 0) {
|
||||
return 99;
|
||||
}
|
||||
@ -171,6 +202,8 @@ int main(void)
|
||||
unsigned char *_guard_page;
|
||||
int c;
|
||||
|
||||
(void) set_resource_limits();
|
||||
|
||||
if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
|
||||
perror("fopen(" TEST_NAME_RES ")");
|
||||
return 99;
|
||||
|
Loading…
Reference in New Issue
Block a user