aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils.c
diff options
context:
space:
mode:
authorAndrew Hastings <abh@cray.com>2008-03-04 11:48:56 -0600
committerNishanth Aravamudan <nacc@us.ibm.com>2008-03-04 16:34:42 -0800
commit3180d3cc07133a5b10dd0a4e410c3044c14caaa9 (patch)
treebe01af31546f1c25325b93b600d3d1a4fbbaba3b /tests/testutils.c
parent1a7ce61cc740a8be334afc1a573dac3d1a7fafa6 (diff)
downloadlibhugetlbfs-3180d3cc07133a5b10dd0a4e410c3044c14caaa9.tar.gz
change tests to read /proc/meminfo
Move read_meminfo() from tests/counters.c to tests/testutils.c. Change these tests to use read_meminfo("HugePages_Free:") instead of expecting a command line argument for the number of free hugepages: alloc-instantiate-race chunk-overcommit truncate_sigbus_versus_oom Signed-off-by: Andrew Hastings <abh@cray.com> Acked-by: Adam Litke <agl@us.ibm.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index 2ae80ab..0cd7809 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -25,6 +25,7 @@
#include <limits.h>
#include <string.h>
#include <errno.h>
+#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
@@ -32,10 +33,12 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include "hugetests.h"
#define HUGETLBFS_MAGIC 0x958458f6
+#define BUF_SZ 1024
int verbose_test = 1;
char *test_name;
@@ -158,6 +161,48 @@ int test_addr_huge(void *p)
return (sb.f_type == HUGETLBFS_MAGIC);
}
+/* XXX: Copied from hugeutils.c. Need to figure out how to share this */
+long read_meminfo(const char *tag)
+{
+ int fd;
+ char buf[BUF_SZ];
+ int len, readerr;
+ char *p, *q;
+ long val;
+
+ fd = open("/proc/meminfo", O_RDONLY);
+ if (fd < 0) {
+ ERROR("Couldn't open /proc/meminfo (%s)\n", strerror(errno));
+ return -1;
+ }
+
+ len = read(fd, buf, sizeof(buf));
+ readerr = errno;
+ close(fd);
+ if (len < 0) {
+ ERROR("Error reading /proc/meminfo (%s)\n", strerror(readerr));
+ return -1;
+ }
+ if (len == sizeof(buf)) {
+ ERROR("/proc/meminfo is too large\n");
+ return -1;
+ }
+ buf[len] = '\0';
+
+ p = strstr(buf, tag);
+ if (!p)
+ return -1; /* looks like the line we want isn't there */
+
+ p += strlen(tag);
+ val = strtol(p, &q, 0);
+ if (! isspace(*q)) {
+ ERROR("Couldn't parse /proc/meminfo value\n");
+ return -1;
+ }
+
+ return val;
+}
+
ino_t get_addr_inode(void *p)
{
char name[256];