<div dir="ltr"><div><div>Hi,<br><br></div>sorry, ping~<br><br><a href="http://lists.linux.it/pipermail/ltp/2015-November/000563.html">http://lists.linux.it/pipermail/ltp/2015-November/000563.html</a><br><a href="http://lists.linux.it/pipermail/ltp/2015-November/000564.html">http://lists.linux.it/pipermail/ltp/2015-November/000564.html</a><br><a href="http://lists.linux.it/pipermail/ltp/2015-November/000565.html">http://lists.linux.it/pipermail/ltp/2015-November/000565.html</a><br><a href="http://lists.linux.it/pipermail/ltp/2015-November/000566.html">http://lists.linux.it/pipermail/ltp/2015-November/000566.html</a><br><br></div>any comments on above patches?<br><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 27, 2015 at 4:18 PM, Li Wang <span dir="ltr"><<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>><br>
---<br>
testcases/kernel/mem/hugetlb/Makefile | 2 +-<br>
testcases/kernel/mem/hugetlb/Makefile.inc | 4 +-<br>
.../kernel/mem/hugetlb/hugeshmat/hugeshmat01.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmat/hugeshmat02.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmat/hugeshmat03.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 2 +-<br>
.../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c | 2 +-<br>
testcases/kernel/mem/hugetlb/lib/Makefile | 2 +-<br>
testcases/kernel/mem/hugetlb/lib/hugetlb.c | 116 +++++++++++++++++++++<br>
testcases/kernel/mem/hugetlb/lib/hugetlb.h | 61 +++++++++++<br>
testcases/kernel/mem/hugetlb/lib/ipcshm.h | 61 -----------<br>
testcases/kernel/mem/hugetlb/lib/libipc.c | 116 ---------------------<br>
18 files changed, 192 insertions(+), 192 deletions(-)<br>
create mode 100644 testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
create mode 100644 testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
delete mode 100644 testcases/kernel/mem/hugetlb/lib/ipcshm.h<br>
delete mode 100644 testcases/kernel/mem/hugetlb/lib/libipc.c<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/Makefile b/testcases/kernel/mem/hugetlb/Makefile<br>
index 1e8f8f8..ea7867f 100644<br>
--- a/testcases/kernel/mem/hugetlb/Makefile<br>
+++ b/testcases/kernel/mem/hugetlb/Makefile<br>
@@ -21,7 +21,7 @@ top_srcdir ?= ../../../..<br>
include $(top_srcdir)/include/mk/<a href="http://env_pre.mk" rel="noreferrer" target="_blank">env_pre.mk</a><br>
<br>
LIBDIR := lib<br>
-LIB := $(LIBDIR)/libipc_hugetlb.a<br>
+LIB := $(LIBDIR)/libhugetlb.a<br>
FILTER_OUT_DIRS := $(LIBDIR)<br>
<br>
$(LIBDIR):<br>
diff --git a/testcases/kernel/mem/hugetlb/Makefile.inc b/testcases/kernel/mem/hugetlb/Makefile.inc<br>
index cc0ada6..c07d600 100644<br>
--- a/testcases/kernel/mem/hugetlb/Makefile.inc<br>
+++ b/testcases/kernel/mem/hugetlb/Makefile.inc<br>
@@ -22,7 +22,7 @@<br>
<br>
# DO NOT USE THIS FILE FOR hugetlb / lib!!!<br>
LIBIPCDIR := ../lib<br>
-LIBIPC := $(LIBIPCDIR)/libipc_hugetlb.a<br>
+LIBIPC := $(LIBIPCDIR)/libhugetlb.a<br>
<br>
$(LIBIPCDIR):<br>
mkdir -p "$@"<br>
@@ -31,7 +31,7 @@ $(LIBIPC): $(LIBIPCDIR)<br>
<br>
CPPFLAGS += -I$(abs_srcdir)/$(LIBIPCDIR)<br>
LDFLAGS += -L$(abs_builddir)/$(LIBIPCDIR)<br>
-LDLIBS += -lipc_hugetlb<br>
+LDLIBS += -lhugetlb<br>
MAKE_DEPS += $(LIBIPC)<br>
<br>
include $(top_srcdir)/testcases/kernel/mem/include/<a href="http://libmem.mk" rel="noreferrer" target="_blank">libmem.mk</a><br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c<br>
index 851d4cf..35e7216 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c<br>
@@ -56,7 +56,7 @@<br>
* none<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c<br>
index 52348f1..2bac9c2 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c<br>
@@ -51,7 +51,7 @@<br>
*/<br>
<br>
#include <pwd.h><br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c<br>
index 723c8b5..fe74810 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c<br>
@@ -57,7 +57,7 @@<br>
* test must be run at root<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c<br>
index 66ad1b5..d7990c7 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c<br>
@@ -61,7 +61,7 @@<br>
* none<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c<br>
index 4aeb638..f79ee83 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c<br>
@@ -53,7 +53,7 @@<br>
*/<br>
<br>
#include <pwd.h><br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c<br>
index 9f5c2c9..e553a2a 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c<br>
@@ -60,7 +60,7 @@<br>
<br>
#include <sys/types.h><br>
#include <sys/wait.h><br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c<br>
index 9770e87..c8592b3 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c<br>
@@ -58,7 +58,7 @@<br>
*/<br>
<br>
#include <setjmp.h><br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c<br>
index ee82de3..5d45aaa 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c<br>
@@ -58,7 +58,7 @@<br>
* none<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c<br>
index b995ef8..0ac4a29 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c<br>
@@ -51,7 +51,7 @@<br>
* none<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
index 9284669..9a2a0b2 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
@@ -52,7 +52,7 @@<br>
* none<br>
*/<br>
<br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
index 7b8f6b4..567b02d 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
@@ -60,7 +60,7 @@<br>
<br>
#include <sys/types.h><br>
#include <sys/wait.h><br>
-#include "ipcshm.h"<br>
+#include "hugetlb.h"<br>
#include "safe_macros.h"<br>
#include "mem.h"<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/Makefile b/testcases/kernel/mem/hugetlb/lib/Makefile<br>
index 4cdd142..96e8e37 100644<br>
--- a/testcases/kernel/mem/hugetlb/lib/Makefile<br>
+++ b/testcases/kernel/mem/hugetlb/lib/Makefile<br>
@@ -20,6 +20,6 @@ top_srcdir ?= ../../../../..<br>
<br>
include $(top_srcdir)/include/mk/<a href="http://env_pre.mk" rel="noreferrer" target="_blank">env_pre.mk</a><br>
<br>
-LIB := libipc_hugetlb.a<br>
+LIB := libhugetlb.a<br>
<br>
include $(top_srcdir)/include/mk/<a href="http://lib.mk" rel="noreferrer" target="_blank">lib.mk</a><br>
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
new file mode 100644<br>
index 0000000..4b2a3d2<br>
--- /dev/null<br>
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
@@ -0,0 +1,116 @@<br>
+/*<br>
+ *<br>
+ * Copyright (c) International Business Machines Corp., 2001<br>
+ *<br>
+ * This program is free software; you can redistribute it and/or modify<br>
+ * it under the terms of the GNU General Public License as published by<br>
+ * the Free Software Foundation; either version 2 of the License, or<br>
+ * (at your option) any later version.<br>
+ *<br>
+ * This program is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See<br>
+ * the GNU General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU General Public License<br>
+ * along with this program; if not, write to the Free Software<br>
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
+ */<br>
+<br>
+/*<br>
+ * NAME<br>
+ * hugetlb.c<br>
+ *<br>
+ * DESCRIPTION<br>
+ * common routines for the hugepage tests.<br>
+ *<br>
+ * The library contains the following routines:<br>
+ *<br>
+ * getipckey()<br>
+ * getuserid()<br>
+ * rm_shm()<br>
+ * help()<br>
+ */<br>
+<br>
+#include <sys/types.h><br>
+#include <sys/ipc.h><br>
+#include <sys/shm.h><br>
+#include <sys/timeb.h><br>
+#include <pwd.h><br>
+#include "hugetlb.h"<br>
+<br>
+/*<br>
+ * getipckey() - generates and returns a message key used by the "get"<br>
+ * calls to create an IPC resource.<br>
+ */<br>
+int getipckey(void)<br>
+{<br>
+ const char a = 'a';<br>
+ int ascii_a = (int)a;<br>
+ char *curdir = NULL;<br>
+ size_t size = 0;<br>
+ key_t ipc_key;<br>
+ struct timeb time_info;<br>
+<br>
+ curdir = getcwd(curdir, size);<br>
+ if (curdir == NULL)<br>
+ tst_brkm(TBROK | TERRNO, cleanup, "getcwd(curdir)");<br>
+<br>
+ /*<br>
+ * Get a Sys V IPC key<br>
+ *<br>
+ * ftok() requires a character as a second argument. This is<br>
+ * refered to as a "project identifier" in the man page. In<br>
+ * order to maximize the chance of getting a unique key, the<br>
+ * project identifier is a "random character" produced by<br>
+ * generating a random number between 0 and 25 and then adding<br>
+ * that to the ascii value of 'a'. The "seed" for the random<br>
+ * number is the millisecond value that is set in the timeb<br>
+ * structure after calling ftime().<br>
+ */<br>
+ ftime(&time_info);<br>
+ srandom((unsigned int)time_info.millitm);<br>
+<br>
+ ipc_key = ftok(curdir, ascii_a + random() % 26);<br>
+ if (ipc_key == -1)<br>
+ tst_brkm(TBROK | TERRNO, cleanup, "ftok");<br>
+<br>
+ return ipc_key;<br>
+}<br>
+<br>
+/*<br>
+ * getuserid() - return the integer value for the "user" id<br>
+ */<br>
+int getuserid(char *user)<br>
+{<br>
+ struct passwd *ent;<br>
+<br>
+ ent = getpwnam(user);<br>
+ if (ent == NULL)<br>
+ tst_brkm(TBROK | TERRNO, cleanup, "getpwnam");<br>
+<br>
+ return ent->pw_uid;<br>
+}<br>
+<br>
+/*<br>
+ * rm_shm() - removes a shared memory segment.<br>
+ */<br>
+void rm_shm(int shm_id)<br>
+{<br>
+ if (shm_id == -1)<br>
+ return;<br>
+<br>
+ /*<br>
+ * check for # of attaches ?<br>
+ */<br>
+ if (shmctl(shm_id, IPC_RMID, NULL) == -1) {<br>
+ tst_resm(TINFO, "WARNING: shared memory deletion failed.");<br>
+ tst_resm(TINFO, "This could lead to IPC resource problems.");<br>
+ tst_resm(TINFO, "id = %d", shm_id);<br>
+ }<br>
+}<br>
+<br>
+void help(void)<br>
+{<br>
+ printf(" -s NUM Set the number of hugepages to be allocated\n");<br>
+}<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
new file mode 100644<br>
index 0000000..6d73e9c<br>
--- /dev/null<br>
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
@@ -0,0 +1,61 @@<br>
+/*<br>
+ *<br>
+ * Copyright (c) International Business Machines Corp., 2001<br>
+ *<br>
+ * This program is free software; you can redistribute it and/or modify<br>
+ * it under the terms of the GNU General Public License as published by<br>
+ * the Free Software Foundation; either version 2 of the License, or<br>
+ * (at your option) any later version.<br>
+ *<br>
+ * This program is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See<br>
+ * the GNU General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU General Public License<br>
+ * along with this program; if not, write to the Free Software<br>
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
+ */<br>
+<br>
+/*<br>
+ * hugetlb.h - common definitions for the hugepage tests<br>
+ */<br>
+<br>
+#ifndef __HUGETLB_H<br>
+#define __HUGETLB_H<br>
+<br>
+#include <sys/ipc.h><br>
+#include <sys/shm.h><br>
+#include <errno.h><br>
+#include <wait.h><br>
+#include "test.h"<br>
+<br>
+#define SHM_RD 0400<br>
+#define SHM_WR 0200<br>
+#define SHM_RW (SHM_RD|SHM_WR)<br>
+<br>
+#ifndef SHM_HUGETLB<br>
+#define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */<br>
+#endif<br>
+<br>
+/*<br>
+ * to get the lower nine permission bits<br>
+ * from shmid_ds.ipc_perm.mode<br>
+ */<br>
+#define MODE_MASK 0x01FF<br>
+<br>
+key_t shmkey; /* an IPC key generated by ftok() */<br>
+<br>
+int getipckey(void);<br>
+int getuserid(char *user);<br>
+void rm_shm(int shm_id);<br>
+<br>
+void cleanup(void);<br>
+void setup(void);<br>
+<br>
+char *nr_opt;<br>
+int sflag;<br>
+long orig_hugepages;<br>
+void help(void);<br>
+<br>
+#endif /* hugetlb.h */<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/ipcshm.h b/testcases/kernel/mem/hugetlb/lib/ipcshm.h<br>
deleted file mode 100644<br>
index 194d14b..0000000<br>
--- a/testcases/kernel/mem/hugetlb/lib/ipcshm.h<br>
+++ /dev/null<br>
@@ -1,61 +0,0 @@<br>
-/*<br>
- *<br>
- * Copyright (c) International Business Machines Corp., 2001<br>
- *<br>
- * This program is free software; you can redistribute it and/or modify<br>
- * it under the terms of the GNU General Public License as published by<br>
- * the Free Software Foundation; either version 2 of the License, or<br>
- * (at your option) any later version.<br>
- *<br>
- * This program is distributed in the hope that it will be useful,<br>
- * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See<br>
- * the GNU General Public License for more details.<br>
- *<br>
- * You should have received a copy of the GNU General Public License<br>
- * along with this program; if not, write to the Free Software<br>
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
- */<br>
-<br>
-/*<br>
- * ipcshm.h - common definitions for the IPC shared memory tests<br>
- */<br>
-<br>
-#ifndef __IPCSHM_H<br>
-#define __IPCSHM_H<br>
-<br>
-#include <sys/ipc.h><br>
-#include <sys/shm.h><br>
-#include <errno.h><br>
-#include <wait.h><br>
-#include "test.h"<br>
-<br>
-#define SHM_RD 0400<br>
-#define SHM_WR 0200<br>
-#define SHM_RW (SHM_RD|SHM_WR)<br>
-<br>
-#ifndef SHM_HUGETLB<br>
-#define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */<br>
-#endif<br>
-<br>
-/*<br>
- * to get the lower nine permission bits<br>
- * from shmid_ds.ipc_perm.mode<br>
- */<br>
-#define MODE_MASK 0x01FF<br>
-<br>
-key_t shmkey; /* an IPC key generated by ftok() */<br>
-<br>
-int getipckey(void);<br>
-int getuserid(char *user);<br>
-void rm_shm(int shm_id);<br>
-<br>
-void cleanup(void);<br>
-void setup(void);<br>
-<br>
-char *nr_opt;<br>
-int sflag;<br>
-long orig_hugepages;<br>
-void help(void);<br>
-<br>
-#endif /* ipcshm.h */<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/libipc.c b/testcases/kernel/mem/hugetlb/lib/libipc.c<br>
deleted file mode 100644<br>
index 1f16f22..0000000<br>
--- a/testcases/kernel/mem/hugetlb/lib/libipc.c<br>
+++ /dev/null<br>
@@ -1,116 +0,0 @@<br>
-/*<br>
- *<br>
- * Copyright (c) International Business Machines Corp., 2001<br>
- *<br>
- * This program is free software; you can redistribute it and/or modify<br>
- * it under the terms of the GNU General Public License as published by<br>
- * the Free Software Foundation; either version 2 of the License, or<br>
- * (at your option) any later version.<br>
- *<br>
- * This program is distributed in the hope that it will be useful,<br>
- * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See<br>
- * the GNU General Public License for more details.<br>
- *<br>
- * You should have received a copy of the GNU General Public License<br>
- * along with this program; if not, write to the Free Software<br>
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
- */<br>
-<br>
-/*<br>
- * NAME<br>
- * libipc.c<br>
- *<br>
- * DESCRIPTION<br>
- * common routines for the IPC system call tests.<br>
- *<br>
- * The library contains the following routines:<br>
- *<br>
- * getipckey()<br>
- * getuserid()<br>
- * rm_shm()<br>
- * help()<br>
- */<br>
-<br>
-#include <sys/types.h><br>
-#include <sys/ipc.h><br>
-#include <sys/shm.h><br>
-#include <sys/timeb.h><br>
-#include <pwd.h><br>
-#include "ipcshm.h"<br>
-<br>
-/*<br>
- * getipckey() - generates and returns a message key used by the "get"<br>
- * calls to create an IPC resource.<br>
- */<br>
-int getipckey(void)<br>
-{<br>
- const char a = 'a';<br>
- int ascii_a = (int)a;<br>
- char *curdir = NULL;<br>
- size_t size = 0;<br>
- key_t ipc_key;<br>
- struct timeb time_info;<br>
-<br>
- curdir = getcwd(curdir, size);<br>
- if (curdir == NULL)<br>
- tst_brkm(TBROK | TERRNO, cleanup, "getcwd(curdir)");<br>
-<br>
- /*<br>
- * Get a Sys V IPC key<br>
- *<br>
- * ftok() requires a character as a second argument. This is<br>
- * refered to as a "project identifier" in the man page. In<br>
- * order to maximize the chance of getting a unique key, the<br>
- * project identifier is a "random character" produced by<br>
- * generating a random number between 0 and 25 and then adding<br>
- * that to the ascii value of 'a'. The "seed" for the random<br>
- * number is the millisecond value that is set in the timeb<br>
- * structure after calling ftime().<br>
- */<br>
- ftime(&time_info);<br>
- srandom((unsigned int)time_info.millitm);<br>
-<br>
- ipc_key = ftok(curdir, ascii_a + random() % 26);<br>
- if (ipc_key == -1)<br>
- tst_brkm(TBROK | TERRNO, cleanup, "ftok");<br>
-<br>
- return ipc_key;<br>
-}<br>
-<br>
-/*<br>
- * getuserid() - return the integer value for the "user" id<br>
- */<br>
-int getuserid(char *user)<br>
-{<br>
- struct passwd *ent;<br>
-<br>
- ent = getpwnam(user);<br>
- if (ent == NULL)<br>
- tst_brkm(TBROK | TERRNO, cleanup, "getpwnam");<br>
-<br>
- return ent->pw_uid;<br>
-}<br>
-<br>
-/*<br>
- * rm_shm() - removes a shared memory segment.<br>
- */<br>
-void rm_shm(int shm_id)<br>
-{<br>
- if (shm_id == -1)<br>
- return;<br>
-<br>
- /*<br>
- * check for # of attaches ?<br>
- */<br>
- if (shmctl(shm_id, IPC_RMID, NULL) == -1) {<br>
- tst_resm(TINFO, "WARNING: shared memory deletion failed.");<br>
- tst_resm(TINFO, "This could lead to IPC resource problems.");<br>
- tst_resm(TINFO, "id = %d", shm_id);<br>
- }<br>
-}<br>
-<br>
-void help(void)<br>
-{<br>
- printf(" -s NUM Set the number of hugepages to be allocated\n");<br>
-}<br>
<span class=""><font color="#888888">--<br>
1.8.3.1<br>
<br>
<br>
--<br>
Mailing list info: <a href="http://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">http://lists.linux.it/listinfo/ltp</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Regards,<br></div>Li Wang<br></div><div>Email: <a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a><br></div></div></div></div></div></div>
</div></div></div>