All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
@ 2013-07-02  1:56 DAN LI
  2013-07-02 13:00 ` chrubis
  2013-07-02 13:05 ` Jan Stancek
  0 siblings, 2 replies; 4+ messages in thread
From: DAN LI @ 2013-07-02  1:56 UTC (permalink / raw)
  To: LTP list



Create test case for MAP_LOCKED of mmap.

Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.


Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
 runtest/syscalls                        |   1 +
 testcases/kernel/syscalls/.gitignore    |   1 +
 testcases/kernel/syscalls/mmap/mmap14.c | 145 ++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap14.c

Hi Jan,

v3:
  Add root check.
  Add mmap14 to ../.gitignore.

Regards,
DAN LI



diff --git a/runtest/syscalls b/runtest/syscalls
index 3ab19f5..beb8782 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -563,6 +563,7 @@ mmap08 mmap08
 mmap09 mmap09
 mmap12 mmap12
 mmap13 mmap13
+mmap14 mmap14
 # test is broken, mask it for now.
 #mmap11 mmap11 -i 30000

diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index fede145..18d03d4 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -515,6 +515,7 @@
 /mmap/mmap11
 /mmap/mmap12
 /mmap/mmap13
+/mmap/mmap14
 /modify_ldt/modify_ldt01
 /modify_ldt/modify_ldt02
 /mount/mount01
diff --git a/testcases/kernel/syscalls/mmap/mmap14.c b/testcases/kernel/syscalls/mmap/mmap14.c
new file mode 100644
index 0000000..25bc48d
--- /dev/null
+++ b/testcases/kernel/syscalls/mmap/mmap14.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2013 FNST, DAN LI <li.dan@cn.fujitsu.com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Test Description:
+ *  Verify MAP_LOCKED works fine.
+ *  "Lock the pages of the mapped region into memory in the manner of mlock(2)."
+ *
+ * Expected Result:
+ *  mmap() should succeed returning the address of the mapped region,
+ *  and this region should be locked into memory.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <signal.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/shm.h>
+
+#include "test.h"
+#include "usctest.h"
+
+#define TEMPFILE        "mmapfile"
+#define MMAPSIZE        (1UL<<20)
+#define LINELEN         256
+
+char *TCID = "mmap14";
+int TST_TOTAL = 1;
+
+static char *addr;
+
+static void getvmlck(unsigned int *lock_sz);
+static void setup(void);
+static void cleanup(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+	unsigned int sz_before;
+	unsigned int sz_after;
+	unsigned int sz_ch;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+
+		tst_count = 0;
+
+		getvmlck(&sz_before);
+
+		addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
+			    MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
+			    -1, 0);
+
+		if (addr == MAP_FAILED) {
+			tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
+			continue;
+		}
+
+		if (STD_FUNCTIONAL_TEST) {
+
+			getvmlck(&sz_after);
+
+			sz_ch = sz_after - sz_before;
+			if (sz_ch == MMAPSIZE / 1024)
+				tst_resm(TPASS, "Functionality of mmap() "
+						"successful");
+			else
+				tst_resm(TFAIL, "Expected %luK locked, "
+						"get %uK locked",
+						MMAPSIZE / 1024, sz_ch);
+
+		} else {
+			tst_resm(TPASS, "call succeeded");
+		}
+
+		if (munmap(addr, MMAPSIZE) != 0)
+			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");
+	}
+
+	cleanup();
+	tst_exit();
+
+}
+
+void getvmlck(unsigned int *lock_sz)
+{
+	int ret;
+	char line[LINELEN];
+	FILE *fstatus = NULL;
+
+	fstatus = fopen("/proc/self/status", "r");
+	if (fstatus == NULL)
+		tst_brkm(TFAIL | TERRNO, NULL, "Open dev status failed");
+
+	while (fgets(line, LINELEN, fstatus) != NULL)
+		if (strstr(line, "VmLck") != NULL)
+			break;
+
+	ret = sscanf(line, "%*[^0-9]%d%*[^0-9]", lock_sz);
+	if (ret != 1)
+		tst_brkm(TFAIL | TERRNO, NULL, "Get lock size failed");
+
+	fclose(fstatus);
+}
+
+static void setup(void)
+{
+	tst_require_root(NULL);
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+}
-- 
1.8.1

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
  2013-07-02  1:56 [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap DAN LI
@ 2013-07-02 13:00 ` chrubis
  2013-07-02 13:05 ` Jan Stancek
  1 sibling, 0 replies; 4+ messages in thread
From: chrubis @ 2013-07-02 13:00 UTC (permalink / raw)
  To: DAN LI; +Cc: LTP list

Hi!
> Create test case for MAP_LOCKED of mmap.
> 
> Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.
> 

Revieved-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
  2013-07-02  1:56 [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap DAN LI
  2013-07-02 13:00 ` chrubis
@ 2013-07-02 13:05 ` Jan Stancek
  2013-07-02 13:59   ` chrubis
  1 sibling, 1 reply; 4+ messages in thread
From: Jan Stancek @ 2013-07-02 13:05 UTC (permalink / raw)
  To: DAN LI; +Cc: LTP list





----- Original Message -----
> From: "DAN LI" <li.dan@cn.fujitsu.com>
> To: "LTP list" <ltp-list@lists.sourceforge.net>
> Cc: "Jan Stancek" <jstancek@redhat.com>
> Sent: Tuesday, 2 July, 2013 3:56:17 AM
> Subject: [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
> 
> 
> 
> Create test case for MAP_LOCKED of mmap.
> 
> Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.
> 
> 
> Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>

Reviewed-by: Jan Stancek <jstancek@redhat.com>

Looks good to me. You could probably remove some of those includes, but
that's just minor nit.

Regards,
Jan

> ---
>  runtest/syscalls                        |   1 +
>  testcases/kernel/syscalls/.gitignore    |   1 +
>  testcases/kernel/syscalls/mmap/mmap14.c | 145
>  ++++++++++++++++++++++++++++++++
>  3 files changed, 147 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/mmap/mmap14.c
> 
> Hi Jan,
> 
> v3:
>   Add root check.
>   Add mmap14 to ../.gitignore.
> 
> Regards,
> DAN LI
> 
> 
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 3ab19f5..beb8782 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -563,6 +563,7 @@ mmap08 mmap08
>  mmap09 mmap09
>  mmap12 mmap12
>  mmap13 mmap13
> +mmap14 mmap14
>  # test is broken, mask it for now.
>  #mmap11 mmap11 -i 30000
> 
> diff --git a/testcases/kernel/syscalls/.gitignore
> b/testcases/kernel/syscalls/.gitignore
> index fede145..18d03d4 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -515,6 +515,7 @@
>  /mmap/mmap11
>  /mmap/mmap12
>  /mmap/mmap13
> +/mmap/mmap14
>  /modify_ldt/modify_ldt01
>  /modify_ldt/modify_ldt02
>  /mount/mount01
> diff --git a/testcases/kernel/syscalls/mmap/mmap14.c
> b/testcases/kernel/syscalls/mmap/mmap14.c
> new file mode 100644
> index 0000000..25bc48d
> --- /dev/null
> +++ b/testcases/kernel/syscalls/mmap/mmap14.c
> @@ -0,0 +1,145 @@
> +/*
> + * Copyright (c) 2013 FNST, DAN LI <li.dan@cn.fujitsu.com>
> + *
> + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +/*
> + * Test Description:
> + *  Verify MAP_LOCKED works fine.
> + *  "Lock the pages of the mapped region into memory in the manner of
> mlock(2)."
> + *
> + * Expected Result:
> + *  mmap() should succeed returning the address of the mapped region,
> + *  and this region should be locked into memory.
> + */
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/types.h>
> +#include <errno.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <string.h>
> +#include <signal.h>
> +#include <stdint.h>
> +#include <sys/stat.h>
> +#include <sys/mman.h>
> +#include <sys/shm.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +
> +#define TEMPFILE        "mmapfile"
> +#define MMAPSIZE        (1UL<<20)
> +#define LINELEN         256
> +
> +char *TCID = "mmap14";
> +int TST_TOTAL = 1;
> +
> +static char *addr;
> +
> +static void getvmlck(unsigned int *lock_sz);
> +static void setup(void);
> +static void cleanup(void);
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	char *msg;
> +	unsigned int sz_before;
> +	unsigned int sz_after;
> +	unsigned int sz_ch;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +
> +		tst_count = 0;
> +
> +		getvmlck(&sz_before);
> +
> +		addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
> +			    MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
> +			    -1, 0);
> +
> +		if (addr == MAP_FAILED) {
> +			tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
> +			continue;
> +		}
> +
> +		if (STD_FUNCTIONAL_TEST) {
> +
> +			getvmlck(&sz_after);
> +
> +			sz_ch = sz_after - sz_before;
> +			if (sz_ch == MMAPSIZE / 1024)
> +				tst_resm(TPASS, "Functionality of mmap() "
> +						"successful");
> +			else
> +				tst_resm(TFAIL, "Expected %luK locked, "
> +						"get %uK locked",
> +						MMAPSIZE / 1024, sz_ch);
> +
> +		} else {
> +			tst_resm(TPASS, "call succeeded");
> +		}
> +
> +		if (munmap(addr, MMAPSIZE) != 0)
> +			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +
> +}
> +
> +void getvmlck(unsigned int *lock_sz)
> +{
> +	int ret;
> +	char line[LINELEN];
> +	FILE *fstatus = NULL;
> +
> +	fstatus = fopen("/proc/self/status", "r");
> +	if (fstatus == NULL)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Open dev status failed");
> +
> +	while (fgets(line, LINELEN, fstatus) != NULL)
> +		if (strstr(line, "VmLck") != NULL)
> +			break;
> +
> +	ret = sscanf(line, "%*[^0-9]%d%*[^0-9]", lock_sz);
> +	if (ret != 1)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Get lock size failed");
> +
> +	fclose(fstatus);
> +}
> +
> +static void setup(void)
> +{
> +	tst_require_root(NULL);
> +
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
> +
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	TEST_CLEANUP;
> +}
> --
> 1.8.1
> 

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
  2013-07-02 13:05 ` Jan Stancek
@ 2013-07-02 13:59   ` chrubis
  0 siblings, 0 replies; 4+ messages in thread
From: chrubis @ 2013-07-02 13:59 UTC (permalink / raw)
  To: Jan Stancek; +Cc: LTP list

Hi!
> > Create test case for MAP_LOCKED of mmap.
> > 
> > Verify pages are locked by checking section "VmLck" of /proc/<pid>/status.
> > 
> > 
> > Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
> 
> Reviewed-by: Jan Stancek <jstancek@redhat.com>
> 
> Looks good to me. You could probably remove some of those includes, but
> that's just minor nit.

Heh, it turned out that the only needed (among ltp test includes) are
stdio.h and sys/mman.h. Pushed with this change, thanks all involved.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-02 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-02  1:56 [LTP] [PATCH v3] mmap/mmap14.c: new case to test MAP_LOCKED of mmap DAN LI
2013-07-02 13:00 ` chrubis
2013-07-02 13:05 ` Jan Stancek
2013-07-02 13:59   ` chrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.