All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] mlock/mlock02.c: cleanup
@ 2014-02-14 10:10 Zeng Linggang
  2014-02-14 10:12 ` [LTP] [PATCH 2/2] mlock/mlock02.c: add EPERM errno test Zeng Linggang
  0 siblings, 1 reply; 24+ messages in thread
From: Zeng Linggang @ 2014-02-14 10:10 UTC (permalink / raw)
  To: ltp-list

* Delete some useless commtents.
* Use SAFE_* macros.
* Move the test body form main() to mlock_verify().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/mlock/mlock02.c | 110 +++++++++++-------------------
 1 file changed, 38 insertions(+), 72 deletions(-)

diff --git a/testcases/kernel/syscalls/mlock/mlock02.c b/testcases/kernel/syscalls/mlock/mlock02.c
index edd9e45..a635d24 100644
--- a/testcases/kernel/syscalls/mlock/mlock02.c
+++ b/testcases/kernel/syscalls/mlock/mlock02.c
@@ -1,6 +1,6 @@
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2002
+ *	06/2002 Written by Paul Larson
  *
  *   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
@@ -13,69 +13,40 @@
  *   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
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * NAME
- * 	mlock02.c
- *
- * DESCRIPTION
- * 	Test to see the proper errors are returned by mlock
- *$
  * ALGORITHM
  * 	test 1:
  *		Call mlock with a NULL address.  ENOMEM should be returned
- *
- * USAGE:  <for command-line>
- *         -c n    Run n copies concurrently
- *         -e      Turn on errno logging
- *         -f      Turn off functional testing
- *         -h      Show this help screen
- *         -i n    Execute test n times
- *         -I x    Execute test for x seconds
- *         -p      Pause for SIGUSR1 before starting
- *         -P x    Pause for x seconds between iterations
- *         -t      Turn on syscall timing
- *
- * HISTORY
- *	06/2002 Written by Paul Larson
- *
- * RESTRICTIONS
- * 	None
  */
+
 #include <errno.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void setup1();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "mlock02";
-int TST_TOTAL = 1;
-
-int exp_enos[] = { ENOMEM, 0 };
 
-void *addr1;
+static void *addr1;
+static void setup(void);
+static void mlock_verify(int);
+static void cleanup(void);
 
-struct test_case_t {
+static struct test_case_t {
 	void **addr;
 	int len;
 	int error;
-	void (*setupfunc) ();
 } TC[] = {
-	/* mlock should return ENOMEM when some or all of the address
-	 * range pointed to by addr and len are not valid mapped pages
-	 * in the address space of the process
-	 */
-	{
-	&addr1, 1024, ENOMEM, setup1}
+	{&addr1, 1024, ENOMEM},
 };
 
+int TST_TOTAL = ARRAY_SIZE(TC);
+static int exp_enos[] = { ENOMEM, 0 };
+
 #if !defined(UCLINUX)
 
 int main(int ac, char **av)
@@ -94,50 +65,28 @@ int main(int ac, char **av)
 
 		tst_count = 0;
 
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			if (TC[i].setupfunc != NULL)
-				TC[i].setupfunc();
-
-			TEST(mlock(*(TC[i].addr), TC[i].len));
-
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO != TC[i].error)
-					tst_brkm(TFAIL | TTERRNO, cleanup,
-						 "mlock didn't fail as expected; "
-						 "expected - %d : %s",
-						 TC[i].error,
-						 strerror(TC[i].error));
-				else
-					tst_resm(TPASS | TTERRNO,
-						 "mlock failed as expected");
-			} else
-				tst_brkm(TFAIL, cleanup,
-					 "mlock succeeded unexpectedly");
-		}
+		for (i = 0; i < TST_TOTAL; i++)
+
+			mlock_verify(i);
 	}
 
 	cleanup();
-
 	tst_exit();
 }
 
 #else
 
-int main()
+int main(void)
 {
 	tst_brkm(TCONF, NULL, "test is not available on uClinux");
 }
 
 #endif /* if !defined(UCLINUX) */
 
-void setup()
+static void setup(void)
 {
 	TEST_PAUSE;
-}
 
-void setup1()
-{
 #ifdef __ia64__
 	TC[0].len = getpagesize() + 1;
 #else
@@ -145,8 +94,25 @@ void setup1()
 #endif
 }
 
-void cleanup()
+static void mlock_verify(int i)
 {
-	TEST_CLEANUP;
+	TEST(mlock(*(TC[i].addr), TC[i].len));
+
+	if (TEST_RETURN != -1) {
+		tst_resm(TFAIL, "mlock succeeded unexpectedly");
+		return;
+	}
+
+	if (TEST_ERRNO != TC[i].error) {
+		tst_resm(TFAIL | TTERRNO,
+			 "mlock didn't fail as expected; expected - %d : %s",
+			 TC[i].error, strerror(TC[i].error));
+	} else {
+		tst_resm(TPASS | TTERRNO, "mlock failed as expected");
+	}
+}
 
+static void cleanup(void)
+{
+	TEST_CLEANUP;
 }
-- 
1.8.4.2




------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-03-04  6:17 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 10:10 [LTP] [PATCH] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-14 10:12 ` [LTP] [PATCH 2/2] mlock/mlock02.c: add EPERM errno test Zeng Linggang
2014-02-14 10:54   ` Jan Stancek
2014-02-19  9:38     ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-19  9:40       ` [LTP] [PATCH v2 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:29         ` Jan Stancek
2014-02-20  9:40           ` [LTP] [PATCH v3 1/2] mlock/mlock02.c: cleanup Zeng Linggang
2014-02-20  9:50             ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-20 11:05               ` Jan Stancek
2014-02-20 13:03                 ` Jan Stancek
2014-02-21  9:03                   ` Zeng Linggang
2014-03-03  7:47                   ` [LTP] [PATCH v4 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03  7:50                     ` [LTP] [PATCH v4 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03  7:51                     ` [LTP] [PATCH v4 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03  9:07                       ` Jan Stancek
2014-03-03 11:22                         ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Zeng Linggang
2014-03-03 11:23                           ` [LTP] [PATCH v5 2/3] mlock/mlock02.c: cleanup Zeng Linggang
2014-03-03 11:25                           ` [LTP] [PATCH v5 3/3] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-03-03 20:28                             ` Jan Stancek
2014-03-04  5:02                               ` Zeng Linggang
2014-03-04  5:33                           ` [LTP] [PATCH v5 1/3] safe_macros: Add SAFE_GETRLIMIT and SAFE_SETRLIMIT Wanlong Gao
2014-03-04  6:17                             ` Zeng Linggang
2014-02-21  1:04                 ` [LTP] [PATCH v3 2/2] mlock/mlock02.c: add EPERM and ENOMEM errno tests Zeng Linggang
2014-02-19 11:02       ` [LTP] [PATCH v2 1/2] mlock/mlock02.c: cleanup Jan Stancek

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.