All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] mmap/munmap /dev/zero
@ 2010-10-12 14:07 CAI Qian
  2010-10-12 19:15 ` Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: CAI Qian @ 2010-10-12 14:07 UTC (permalink / raw)
  To: ltp-list

Add a new test to mmap/munmap /dev/zero.

Signed-off-by: CAI Qian <caiqian@redhat.com>

--- /dev/null
+++ b/testcases/kernel/syscalls/mmap/mmap10.c
@@ -0,0 +1,131 @@
+/*
+ * mmap/munmap /dev/zero
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "test.h"
+#include "usctest.h"
+#include <errno.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <stdio.h>
+
+#define SIZE (5*1024*1024)
+
+char *TCID = "mmap10";
+int TST_TOTAL = 1;
+extern int Tst_count;
+
+/* main setup function of test */
+void setup();
+/* cleanup function for the test */
+void cleanup();
+int mmapzero();
+
+
+int main(int ac, char **av)
+{
+	/* loop counter */
+	int lc;
+	/* message returned from parse_opts */
+	char *msg;
+
+	msg = parse_opts(ac, av, (option_t *) NULL, NULL);
+	if (msg != (char *)NULL) {
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+		tst_exit();
+	}
+
+	/* Perform global setup for test */
+	setup();
+
+	/* Check looping state if -i option given */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		/* Reset Tst_count in case we are looping. */
+		Tst_count = 0;
+
+		TEST(mmapzero());
+
+		if(TEST_RETURN != 0)
+			tst_resm(TFAIL, "mmapzero() failed with %ld.",
+				TEST_RETURN);
+		else
+			tst_resm(TPASS, "mmapzero() completed successfully.");
+	 }
+
+	 cleanup();
+	 return 0;
+ }
+
+ int mmapzero()
+ {
+	 char *x;
+
+	 x = mmap("/dev/zero", SIZE+SIZE-4096, PROT_READ|PROT_WRITE,
+		 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+	 if (x == MAP_FAILED) {
+		 perror("error");
+		 return 1;
+	 }
+	 x[SIZE] = 0;
+	 if (!fork()) {
+		 munmap(x + SIZE+4096, SIZE-4096*2);
+		 _exit(0);
+	 }
+	 if (!fork()) {
+		 if (!fork()) {
+			 munmap(x + SIZE+4096, SIZE-4096*2);
+			 _exit(0);
+		 }
+		 munmap(x + SIZE+4096, SIZE-4096*2);
+		 _exit(0);
+	 }
+	 munmap(x, SIZE+SIZE-4096);
+	 while (waitpid(-1, NULL, WNOHANG) > 0);
+	 return 0;
+ }
+
+ void cleanup()
+ {
+	 /*
+	  * remove the tmp directory and exit
+	  */
+	 TEST_CLEANUP;
+	 tst_rmdir();
+	 tst_exit();
+
+ }
+
+
+void setup()
+{
+	/*
+	 * setup a default signal hander and a
+	 * temporary working directory.
+	 */
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+	tst_tmpdir();
+}

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2010-10-13  2:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-12 14:07 [LTP] [PATCH] mmap/munmap /dev/zero CAI Qian
2010-10-12 19:15 ` Mike Frysinger
2010-10-12 20:06   ` Garrett Cooper
2010-10-13  2:06     ` CAI Qian
2010-10-13  2:06   ` CAI Qian
2010-10-13  2:28     ` Mike Frysinger
2010-10-13  2:37       ` CAI Qian

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.