This test ensures that we can still find the hugetlb mount point when it occurs after the 4kb mark in /proc/mounts.
Signed-off-by: Eric B Munson <[EMAIL PROTECTED]>
---
tests/Makefile | 4 +-
tests/large_mounts.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/run_tests.sh | 1 +
3 files changed, 175 insertions(+), 2 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 322aae1..b06bda1 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,8 +1,8 @@
PREFIX = /usr/local
LIB_TESTS = gethugepagesize test_root find_path unlinked_fd misalign \
- readback truncate shared private empty_mounts meminfo_nohuge \
- ptrace-write-hugepage icache-hygiene slbpacaflush \
+ readback truncate shared private empty_mounts large_mounts \
+ meminfo_nohuge ptrace-write-hugepage icache-hygiene slbpacaflush \
chunk-overcommit mprotect alloc-instantiate-race mlock \
truncate_reserve_wraparound truncate_sigbus_versus_oom \
map_high_truncate_2 truncate_above_4GB direct \
diff --git a/tests/large_mounts.c b/tests/large_mounts.c
new file mode 100644
index 0000000..c56a518
--- /dev/null
+++ b/tests/large_mounts.c
@@ -0,0 +1,172 @@
+/*
+ * libhugetlbfs - Easy use of Linux hugepages
+ * Copyright (C) 2008 Eric Munson, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <stdarg.h>
+#include <errno.h>
+
+#include <hugetlbfs.h>
+
+#include "hugetests.h"
+
+#define TEST_MOUNTS "/tmp/fake_mounts"
+#define BUF_SIZE 4096
+#define FILLER "tmpfs /var/run tmpfs rw,nosuid,nodev,noexec,mode=755 0 0\n"
+
+int in_test; /* = 0; */
+
+
+/* We override the normal open, so libhugetlbfs gets our modified
+ * mounts file */
+int open(const char *path, int flags, ...)
+{
+ int (*old_open)(const char *, int, ...);
+ int fd;
+
+ if (in_test && (strcmp(path, "/proc/mounts") == 0))
+ path = TEST_MOUNTS;
+
+ old_open = dlsym(RTLD_NEXT, "open");
+ if (flags & O_CREAT) {
+ va_list ap;
+
+ va_start(ap, flags);
+ fd = (*old_open)(path, flags, va_arg(ap, mode_t));
+ va_end(ap);
+ return fd;
+ } else {
+ return (*old_open)(path, flags);
+ }
+}
+
+char *read_mounts()
+{
+ char *buffer;
+ int len = 0, ret = 0, buf_count = 1, fd;
+ int error;
+
+ fd = open("/proc/mounts", O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ buffer = (char*)malloc(BUF_SIZE);
+ if (!buffer) {
+ close(fd);
+ return NULL;
+ }
+
+ memset(buffer, '\0', BUF_SIZE);
+ do {
+ ret = read(fd, buffer + len, (BUF_SIZE * buf_count) - len);
+ error = errno;
+ if (ret < 0) {
+ if (error == EAGAIN || error == EINTR) {
+ ret = 1;
+ continue;
+ }
+ free(buffer);
+ close(fd);
+ ERROR("Unable to read from /proc/mounts\n");
+ }
+
+ len += ret;
+ if (len >= (BUF_SIZE * buf_count) - 128) {
+ buf_count++;
+ buffer = realloc(buffer, BUF_SIZE * buf_count);
+ if (!buffer) {
+ close(fd);
+ return NULL;
+ }
+ memset(buffer + len, '\0',
+ (BUF_SIZE * buf_count) - len);
+ }
+ } while (ret != 0);
+ return buffer;
+}
+
+void write_buffer(int fd, char *buf)
+{
+ int ret, written = 0, len, error;
+
+ len = strlen(buf);
+ do {
+ ret = write(fd, buf + written, len - written);
+ error = errno;
+ if (ret < 0) {
+ if (error == EAGAIN || error == EINTR)
+ continue;
+ close(fd);
+ ERROR("Unable to write to given file descriptor: %s\n",
+ strerror(error));
+ }
+ written += ret;
+ } while (written < len);
+}
+
+void make_large_mounts()
+{
+ char *mounts_text;
+ int num_filler, i, len, fd;
+
+ mounts_text = read_mounts();
+ if (!mounts_text)
+ CONFIG("Unable to read /proc/mounts\n");
+
+ fd = creat(TEST_MOUNTS, S_IRUSR | S_IWUSR);
+ if (fd < 0)
+ CONFIG("Unable to create file %s\n", TEST_MOUNTS);
+
+ len = strlen(FILLER);
+ num_filler = (BUF_SIZE - strlen(mounts_text)) / len;
+ for (i = 0; i <= num_filler + 1; i++)
+ write_buffer(fd, FILLER);
+
+ write_buffer(fd, mounts_text);
+ free(mounts_text);
+ close(fd);
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ make_large_mounts();
+
+ in_test = 1;
+
+ test_init(argc, argv);
+ check_hugepagesize();
+
+ fd = hugetlbfs_unlinked_fd();
+
+ unlink(TEST_MOUNTS);
+ if (fd < 0)
+ FAIL("Unable to find mount point\n");
+
+ PASS();
+}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 8f8dc11..da301c1 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -152,6 +152,7 @@ functional_tests () {
# Library tests requiring kernel hugepage support
run_test gethugepagesize
run_test HUGETLB_VERBOSE=1 empty_mounts
+ run_test HUGETLB_VERBOSE=1 large_mounts
# Tests requiring an active and usable hugepage mount
run_test find_path
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Libhugetlbfs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
