summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/util/config.h.in3
-rw-r--r--tests/util/piglit-util.c38
-rw-r--r--tests/util/piglit-util.h2
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/util/config.h.in b/tests/util/config.h.in
index a012cc37..b664adc2 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 78722d94..22941fd7 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 a7b28fc0..da4c844d 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;