public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] sbrk/sbrk01.c: cleanup
@ 2014-04-22  9:40 Zeng Linggang
  2014-04-22  9:41 ` [LTP] [PATCH 2/2] sbrk/sbrk02.c: add ENOMEM errno test Zeng Linggang
  2014-04-22 12:38 ` [LTP] [PATCH " Jan Stancek
  0 siblings, 2 replies; 12+ messages in thread
From: Zeng Linggang @ 2014-04-22  9:40 UTC (permalink / raw)
  To: ltp-list

* Delete some useless commtents.
* Move the test body from main() to sbrk_verify().
* Remove tst_tmpdir().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/sbrk/sbrk01.c | 236 +++++++-------------------------
 1 file changed, 52 insertions(+), 184 deletions(-)

diff --git a/testcases/kernel/syscalls/sbrk/sbrk01.c b/testcases/kernel/syscalls/sbrk/sbrk01.c
index b2db42c..f2b09f4 100644
--- a/testcases/kernel/syscalls/sbrk/sbrk01.c
+++ b/testcases/kernel/syscalls/sbrk/sbrk01.c
@@ -1,5 +1,7 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *  AUTHOR		: William Roske
+ *  CO-PILOT		: Dave Fenner
  *
  * 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
@@ -30,84 +32,11 @@
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
  */
-/* $Id: sbrk01.c,v 1.8 2009/06/09 16:01:21 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: sbrk01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sbrk(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 2
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 06/05/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) sbrk(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the sbrk(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	sbrk(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+/*
+ * DESCRIPTION
+ *	1.) test sbrk(8192) should return successfully.
+ *	2.) test sbrk(-8192) should return successfully.
+ */
 
 #include <unistd.h>
 #include <errno.h>
@@ -118,146 +47,85 @@
 #include "test.h"
 #include "usctest.h"
 
-void setup();
-void cleanup();
-
 char *TCID = "sbrk01";
-int TST_TOTAL = 2;
-
-int Increment;			/* Amount to make change size by */
 
 #if !defined(UCLINUX)
 
+static struct test_case_t {
+	long increment;
+} test_cases[] = {
+	{8192},
+	{-8192},
+};
+
+static void setup(void);
+static void sbrk_verify(const struct test_case_t *);
+static void cleanup(void);
+
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+
 int main(int ac, char **av)
 {
 	int lc;
 	char *msg;
-	void *tret;
+	int i;
 
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
 	setup();
 
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
 		tst_count = 0;
 
-		/*
-		 * TEST CASE:
-		 * Increase by 8192 bytes
-		 */
-		Increment = 8192;
-
-		/* Call sbrk(2) */
-		errno = 0;
-		tret = sbrk(Increment);	/* Remove -64 IRIX compiler warning */
-		TEST_ERRNO = errno;
-
-		/* check return code */
-		if (tret == (void *)-1) {
-			TEST_ERROR_LOG(TEST_ERRNO);
-			tst_resm(TFAIL,
-				 "sbrk - Increase by 8192 bytes failed, errno=%d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
-			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
-				tst_resm(TPASS,
-					 "sbrk - Increase by 8192 bytes returned %p",
-					 tret);
-			}
-		}
-
-		/*
-		 * TEST CASE:
-		 * Decrease to original size
-		 */
-		Increment = (Increment * -1);
-
-		/* Call sbrk(2) */
-		errno = 0;
-		tret = sbrk(Increment);
-		TEST_ERRNO = errno;
-
-		/* check return code */
-		if (tret == (void *)-1) {
-			TEST_ERROR_LOG(TEST_ERRNO);
-			tst_resm(TFAIL,
-				 "sbrk - Decrease to original size failed, errno=%d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
-			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
-				tst_resm(TPASS,
-					 "sbrk - Decrease to original size returned %p",
-					 tret);
-			}
-		}
-
+		for (i = 0; i < TST_TOTAL; i++)
+			sbrk_verify(&test_cases[i]);
 	}
 
-    /***************************************************************
-     * cleanup and exit
-     ***************************************************************/
 	cleanup();
 	tst_exit();
 
 }
 
-#else
-
-int main(void)
+static void setup(void)
 {
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
-#endif /* if !defined(UCLINUX) */
+	TEST_PAUSE;
+}
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void sbrk_verify(const struct test_case_t *test)
 {
+	void *tret;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	tret = sbrk(test->increment);
+	TEST_ERRNO = errno;
 
-	/* make a temp dir and cd to it */
-	tst_tmpdir();
+	if (tret == (void *)-1) {
+		tst_resm(TFAIL | TTERRNO,
+			 "sbrk - Increase by %ld bytes failed, errno=%d : %s",
+			 test->increment, TEST_ERRNO, strerror(TEST_ERRNO));
+	} else {
+		tst_resm(TPASS, "sbrk - Increase by %ld bytes returned %p",
+			 test->increment, tret);
+	}
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
+}
 
-	tst_rmdir();
+#else
+
+int TST_TOTAL = 1;
 
+int main(void)
+{
+	tst_resm(TINFO, "test is not available on uClinux");
+	tst_exit();
 }
+
+#endif /* if !defined(UCLINUX) */
-- 
1.8.4.2




------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-05-20 16:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-22  9:40 [LTP] [PATCH 1/2] sbrk/sbrk01.c: cleanup Zeng Linggang
2014-04-22  9:41 ` [LTP] [PATCH 2/2] sbrk/sbrk02.c: add ENOMEM errno test Zeng Linggang
2014-04-22 13:14   ` Jan Stancek
2014-04-23  1:23     ` Zeng Linggang
2014-04-23  3:51     ` [LTP] [PATCH v2 1/2] sbrk/sbrk01.c: cleanup Zeng Linggang
2014-04-23  3:52       ` [LTP] [PATCH v2 2/2] sbrk/sbrk02.c: add ENOMEM errno test Zeng Linggang
2014-04-23 11:29         ` Jan Stancek
2014-04-25  9:29           ` Zeng Linggang
2014-05-20 15:50           ` chrubis
2014-05-20 15:56         ` chrubis
2014-05-20 16:03       ` [LTP] [PATCH v2 1/2] sbrk/sbrk01.c: cleanup chrubis
2014-04-22 12:38 ` [LTP] [PATCH " Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox