This patch includes a library, which implements 
some helper functions.

Signed-off-by: Tang Chen <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/Makefile     |   25 ++++++++-
 testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile |   25 +++++++++
 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c |   58 ++++++++++++++++++++
 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h |   25 +++++++++
 4 files changed, 132 insertions(+), 1 deletions(-)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile 
b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index a1ba46e..5da30f9 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -23,5 +23,28 @@
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+
+LIBDIR                 := lib
+LIB                    := $(LIBDIR)/libmnt_hugetlb.a
+FILTER_OUT_DIRS                := $(LIBDIR)
+
+$(LIBDIR):
+       mkdir -p "$@"
+
+$(LIB): $(LIBDIR)
+       $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
+
+CPPFLAGS               += -I$(abs_srcdir)/$(LIBDIR)
+
+LDFLAGS                        += -L$(abs_builddir)/$(LIBDIR)
+
+LDLIBS                 += -lmnt_hugetlb
+
+MAKE_DEPS              := $(LIB)
+
+trunk-clean:: | lib-clean
+
+lib-clean:: $(LIBDIR)
+       $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
new file mode 100644
index 0000000..f37b87a
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
@@ -0,0 +1,25 @@
+#
+#  Copyright (c) International Business Machines  Corp., 2001
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program 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 General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir             ?= ../../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+LIB                    := libmnt_hugetlb.a
+
+include $(top_srcdir)/include/mk/lib.mk
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
new file mode 100644
index 0000000..3f722eb
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
@@ -0,0 +1,58 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <errno.h>
+
+#include "test.h"
+#include "libmnt.h"
+
+void
+hugepage_alloc(int num)
+{
+       FILE *file = fopen("/proc/sys/vm/nr_hugepages", "w+");
+       if (file == NULL) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "fopen failed on /proc/sys/vm/nr_hugepages");
+       }
+
+       if (fprintf(file, "%d", num) < 0) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "fprintf failed on /proc/sys/vm/nr_hugepages");
+       }
+
+       fclose(file);
+}
+
+void
+mount_hugetlbfs(char *mount_point)
+{
+       if (mount("none", mount_point, "hugetlbfs", 0, NULL) < 0) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "mount failed on %s", mount_point);
+       }
+}
+
+void
+umount_hugetlbfs(char *mount_point)
+{
+       umount(mount_point);
+}
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h
new file mode 100644
index 0000000..b4659ff
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h
@@ -0,0 +1,25 @@
+/*
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ *   libmnt.h - functions to mount hugetlbfs automatically.
+ */
+
+void hugepage_alloc(int num);
+void mount_hugetlbfs(char *mount_point);
+void umount_hugetlbfs(char *mount_point);
-- 
1.7.1


-- 
Best Regards,
Tang chen


>From 73cfee99818a6f0517ee544f3b55e43f38f0052a Mon Sep 17 00:00:00 2001
From: Tang Chen <[email protected]>
Date: Tue, 2 Aug 2011 10:30:49 +0800
Subject: [PATCH 1/6] A library used to mount hugetlbfs automatically.

This library includes a set of functions used to mount hugetlbfs automatically 
when doing the hugemmap tests.

Signed-off-by: Tang Chen <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/Makefile     |   25 ++++++++-
 testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile |   25 +++++++++
 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c |   58 ++++++++++++++++++++
 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h |   25 +++++++++
 4 files changed, 132 insertions(+), 1 deletions(-)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile 
b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index a1ba46e..5da30f9 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -23,5 +23,28 @@
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+
+LIBDIR                 := lib
+LIB                    := $(LIBDIR)/libmnt_hugetlb.a
+FILTER_OUT_DIRS                := $(LIBDIR)
+
+$(LIBDIR):
+       mkdir -p "$@"
+
+$(LIB): $(LIBDIR)
+       $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
+
+CPPFLAGS               += -I$(abs_srcdir)/$(LIBDIR)
+
+LDFLAGS                        += -L$(abs_builddir)/$(LIBDIR)
+
+LDLIBS                 += -lmnt_hugetlb
+
+MAKE_DEPS              := $(LIB)
+
+trunk-clean:: | lib-clean
+
+lib-clean:: $(LIBDIR)
+       $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
new file mode 100644
index 0000000..f37b87a
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/Makefile
@@ -0,0 +1,25 @@
+#
+#  Copyright (c) International Business Machines  Corp., 2001
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program 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 General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir             ?= ../../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+LIB                    := libmnt_hugetlb.a
+
+include $(top_srcdir)/include/mk/lib.mk
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
new file mode 100644
index 0000000..3f722eb
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.c
@@ -0,0 +1,58 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <errno.h>
+
+#include "test.h"
+#include "libmnt.h"
+
+void
+hugepage_alloc(int num)
+{
+       FILE *file = fopen("/proc/sys/vm/nr_hugepages", "w+");
+       if (file == NULL) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "fopen failed on /proc/sys/vm/nr_hugepages");
+       }
+
+       if (fprintf(file, "%d", num) < 0) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "fprintf failed on /proc/sys/vm/nr_hugepages");
+       }
+
+       fclose(file);
+}
+
+void
+mount_hugetlbfs(char *mount_point)
+{
+       if (mount("none", mount_point, "hugetlbfs", 0, NULL) < 0) {
+               tst_brkm(TBROK|TERRNO, NULL, 
+                       "mount failed on %s", mount_point);
+       }
+}
+
+void
+umount_hugetlbfs(char *mount_point)
+{
+       umount(mount_point);
+}
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h 
b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h
new file mode 100644
index 0000000..b4659ff
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/lib/libmnt.h
@@ -0,0 +1,25 @@
+/*
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ *   libmnt.h - functions to mount hugetlbfs automatically.
+ */
+
+void hugepage_alloc(int num);
+void mount_hugetlbfs(char *mount_point);
+void umount_hugetlbfs(char *mount_point);
-- 
1.7.1

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to