summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2011-07-27 17:29:38 -0700
committerIan Romanick <ian.d.romanick@intel.com>2011-08-19 09:24:32 -0700
commitb8d9633830c67f76e9a3cbc17b45c3f226259537 (patch)
treea746f5e6fc1e116215d9eb64dcf7a5dc161a0e05
parent8101d45b76523be5a1f065eb7fdc3a6e236e53d0 (diff)
Add piglit_set_rlimit utility function
This function sets the maximum amount of memory that a process can have in its address space. This is useful for tests that use "infinite" memory on failing implementations. Setting this low can prevent the test from exhausting system memory and adversely affecting other tests. Acked-by: José Fonseca <jfonseca@vmware.com>
-rw-r--r--CMakeLists.txt3
-rw-r--r--tests/util/config.h.in3
-rw-r--r--tests/util/piglit-util.c38
-rw-r--r--tests/util/piglit-util.h2
4 files changed, 46 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dab4cfdf7..aafe8b1b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,8 +96,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
check_function_exists(strchrnul HAVE_STRCHRNUL)
check_function_exists(fopen_s HAVE_FOPEN_S)
+check_function_exists(setrlimit HAVE_SETRLIMIT)
+check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
+check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(fcntl.h HAVE_FCNTL_H)
diff --git a/tests/util/config.h.in b/tests/util/config.h.in
index a012cc377..b664adc28 100644
--- a/tests/util/config.h.in
+++ b/tests/util/config.h.in
@@ -1,7 +1,10 @@
#cmakedefine HAVE_STRCHRNUL
#cmakedefine HAVE_FOPEN_S
+#cmakedefine HAVE_SETRLIMIT
#cmakedefine HAVE_FCNTL_H
#cmakedefine HAVE_SYS_STAT_H
#cmakedefine HAVE_SYS_TYPES_H
+#cmakedefine HAVE_SYS_TIME_H
+#cmakedefine HAVE_SYS_RESOURCE_H
#cmakedefine HAVE_UNISTD_H
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 78722d94b..22941fd7a 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -33,6 +33,14 @@
#include <errno.h>
#include <sys/stat.h>
+#include "config.h"
+#if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SETRLIMIT)
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#define USE_SETRLIMIT
+#endif
+
#include "piglit-util.h"
void piglit_glutInit(int argc, char **argv)
@@ -473,3 +481,33 @@ char *strchrnul(const char *s, int c)
return (t == NULL) ? ((char *) s + strlen(s)) : t;
}
#endif
+
+
+void
+piglit_set_rlimit(unsigned long lim)
+{
+#if defined(USE_SETRLIMIT)
+ struct rlimit rl;
+ if (getrlimit(RLIMIT_AS, &rl) != -1) {
+ printf("Address space limit = %lu, max = %lu\n",
+ (unsigned long) rl.rlim_cur,
+ (unsigned long) rl.rlim_max);
+
+ if (rl.rlim_max > lim) {
+ printf("Resetting limit to %lu.\n", lim);
+
+ rl.rlim_cur = lim;
+ rl.rlim_max = lim;
+ if (setrlimit(RLIMIT_AS, &rl) == -1) {
+ printf("Could not set rlimit "
+ "due to: %s (%d)\n",
+ strerror(errno), errno);
+ }
+ }
+ }
+
+ printf("\n");
+#else
+ printf("Cannot reset rlimit on this platform.\n\n");
+#endif
+}
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index a7b28fc04..da4c844d9 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -319,5 +319,7 @@ extern void piglit_require_vertex_shader(void);
char *strchrnul(const char *s, int c);
#endif
+extern void piglit_set_rlimit(unsigned long lim);
+
static const GLint PIGLIT_ATTRIB_POS = 0;
static const GLint PIGLIT_ATTRIB_TEX = 1;