mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09: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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user