Skip to contentSkip to conversation

shmget/shmget01.c: cleanup

PATCH In review DAN LI 2 participants 4 messages Jun 4, 2013

lore
Share & tools
lore

DAN LI

author
#0 lore raw

PATCH v2 1/1 shmget/shmget01.c: cleanup

1. Remove useless comments

2. Revise code to follow ltp-code-style

---
 testcases/kernel/syscalls/ipc/shmget/shmget01.c |   86 ++++++-----------------
 1 files changed, 21 insertions(+), 65 deletions(-)
testcases/kernel/syscalls/ipc/shmget/shmget01.c +21 -65
index 38dbee7..aa2c78b 100644
@@ -1,20 +1,19 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * 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 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.
  *
- *   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
+ * 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
  */
 
 /*
@@ -33,27 +32,12 @@
  *	  if doing functionality testing
  *		stat the shared memory resource
  *		check the size, creator pid and mode
- *	  	if correct,
+ *		if correct,
  *			issue a PASS message
  *		otherwise
  *			issue a FAIL message
  *	  else issue a PASS message
  *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
 #include "ipcshm.h"
@@ -61,31 +45,24 @@
 char *TCID = "shmget01";
 int TST_TOTAL = 1;
 
-int shm_id_1 = -1;
+static int shm_id_1 = -1;
 
-int main(int ac, char **av)
+int main(int argc, char *argv[])
 {
 	int lc;
 	char *msg;
 	struct shmid_ds buf;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	}
 
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
-		/*
-		 * Use TEST macro to make the call
-		 */
-
-		TEST(shmget(shmkey, SHM_SIZE, (IPC_CREAT | IPC_EXCL | SHM_RW)));
+		TEST(shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW));
 
 		if (TEST_RETURN == -1) {
 			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
@@ -131,11 +108,10 @@ int main(int ac, char **av)
 		/*
 		 * clean up things in case we are looping
 		 */
-		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1) {
+		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1)
 			tst_resm(TBROK, "couldn't remove shared memory");
-		} else {
+		else
 			shm_id_1 = -1;
-		}
 	}
 
 	cleanup();
@@ -143,42 +119,22 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
 void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
 	tst_tmpdir();
 
-	/* get an IPC resource key */
 	shmkey = getipckey();
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
 void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
 	rm_shm(shm_id_1);
 
 	tst_rmdir();
 
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
-
 }
Signature · 12 lines
1.7.1

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
author
#1 lore raw

PATCH v2 1/1 shmget/shmget01.c: attach SHM_NORESERVE to shmflg

Add SHM_NORESERVE to shmflg to test

---
 testcases/kernel/syscalls/ipc/shmget/shmget01.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
testcases/kernel/syscalls/ipc/shmget/shmget01.c +2 -1
index aa2c78b..a4ac172 100644
@@ -62,7 +62,8 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		TEST(shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW));
+		TEST(shmget(shmkey, SHM_SIZE,
+			    IPC_CREAT | IPC_EXCL | SHM_RW | SHM_NORESERVE));
 
 		if (TEST_RETURN == -1) {
 			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
Signature · 12 lines
1.7.1

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw
In reply to DAN LI
Quoted 5 lines · DAN LI

1. Remove useless comments

2. Revise code to follow ltp-code-style

overall looks good to me, yet I think there are some more comments could be removed. like:

/* if we get here, everything looks good */

and

108 /*
109 * clean up things in case we are looping
110 */

Thoughts?

Caspar

Quoted 156 lines
---
  testcases/kernel/syscalls/ipc/shmget/shmget01.c |   86 ++++++-----------------
  1 files changed, 21 insertions(+), 65 deletions(-)
testcases/kernel/syscalls/ipc/shmget/shmget01.c +21 -60
index 38dbee7..aa2c78b 100644
@@ -1,20 +1,19 @@
  /*
+ * Copyright (c) International Business Machines  Corp., 2001
   *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * 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 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.
   *
- *   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
+ * 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
   */
 
  /*
@@ -33,27 +32,12 @@
   *	  if doing functionality testing
   *		stat the shared memory resource
   *		check the size, creator pid and mode
- *	  	if correct,
+ *		if correct,
   *			issue a PASS message
   *		otherwise
   *			issue a FAIL message
   *	  else issue a PASS message
   *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
   */
 
  #include "ipcshm.h"
@@ -61,31 +45,24 @@
  char *TCID = "shmget01";
  int TST_TOTAL = 1;
 
-int shm_id_1 = -1;
+static int shm_id_1 = -1;
 
-int main(int ac, char **av)
+int main(int argc, char *argv[])
  {
  	int lc;
  	char *msg;
  	struct shmid_ds buf;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
  		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	}
 
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+	setup();
 
  	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
  		tst_count = 0;
 
-		/*
-		 * Use TEST macro to make the call
-		 */
-
-		TEST(shmget(shmkey, SHM_SIZE, (IPC_CREAT | IPC_EXCL | SHM_RW)));
+		TEST(shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW));
 
  		if (TEST_RETURN == -1) {
  			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
@@ -131,11 +108,10 @@ int main(int ac, char **av)
  		/*
  		 * clean up things in case we are looping
  		 */
-		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1) {
+		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1)
  			tst_resm(TBROK, "couldn't remove shared memory");
-		} else {
+		else
  			shm_id_1 = -1;
-		}
  	}
 
  	cleanup();
@@ -143,42 +119,22 @@ int main(int ac, char **av)
  	tst_exit();
  }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
  void setup(void)
  {
-
  	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
  	TEST_PAUSE;
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
  	tst_tmpdir();
 
-	/* get an IPC resource key */
  	shmkey = getipckey();
  }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
  void cleanup(void)
  {
-	/* if it exists, remove the shared memory resource */
  	rm_shm(shm_id_1);

testcases/kernel/syscalls/ipc/shmget/shmget01.c int main(int ac, char **av) · line 140

Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget01.c +0 -5
 
  	tst_rmdir();
 
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
  	TEST_CLEANUP;
-
  }

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#3 lore raw
Quoted 12 lines · Caspar Zhang
Quoted 5 lines · DAN LI

1. Remove useless comments

2. Revise code to follow ltp-code-style

overall looks good to me, yet I think there are some more comments could be removed. like:

/* if we get here, everything looks good */

Quoted 8 lines

and

108 /*
109 * clean up things in case we are looping
110 */

Thoughts?

Agree.

DAN LI

Quoted 160 lines

Caspar

Quoted 158 lines
---
  testcases/kernel/syscalls/ipc/shmget/shmget01.c |   86 ++++++-----------------
  1 files changed, 21 insertions(+), 65 deletions(-)
testcases/kernel/syscalls/ipc/shmget/shmget01.c +21 -60
index 38dbee7..aa2c78b 100644
@@ -1,20 +1,19 @@
  /*
+ * Copyright (c) International Business Machines  Corp., 2001
   *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * 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 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.
   *
- *   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
+ * 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
   */
 
  /*
@@ -33,27 +32,12 @@
   *      if doing functionality testing
   *        stat the shared memory resource
   *        check the size, creator pid and mode
- *          if correct,
+ *        if correct,
   *            issue a PASS message
   *        otherwise
   *            issue a FAIL message
   *      else issue a PASS message
   *    call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *           -i n : Execute test n times.
- *           -I x : Execute test for x seconds.
- *           -P x : Pause for x seconds between iterations.
- *           -t   : Turn on syscall timing.
- *
- * HISTORY
- *    03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *    none
   */
 
  #include "ipcshm.h"
@@ -61,31 +45,24 @@
  char *TCID = "shmget01";
  int TST_TOTAL = 1;
 
-int shm_id_1 = -1;
+static int shm_id_1 = -1;
 
-int main(int ac, char **av)
+int main(int argc, char *argv[])
  {
      int lc;
      char *msg;
      struct shmid_ds buf;
 
-    if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+    msg = parse_opts(argc, argv, NULL, NULL);
+    if (msg != NULL)
          tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-    }
 
-    setup();        /* global setup */
-
-    /* The following loop checks looping state if -i option given */
+    setup();
 
      for (lc = 0; TEST_LOOPING(lc); lc++) {
-        /* reset tst_count in case we are looping */
          tst_count = 0;
 
-        /*
-         * Use TEST macro to make the call
-         */
-
-        TEST(shmget(shmkey, SHM_SIZE, (IPC_CREAT | IPC_EXCL | SHM_RW)));
+        TEST(shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW));
 
          if (TEST_RETURN == -1) {
              tst_resm(TFAIL, "%s call failed - errno = %d : %s",
@@ -131,11 +108,10 @@ int main(int ac, char **av)
          /*
           * clean up things in case we are looping
           */
-        if (shmctl(shm_id_1, IPC_RMID, NULL) == -1) {
+        if (shmctl(shm_id_1, IPC_RMID, NULL) == -1)
              tst_resm(TBROK, "couldn't remove shared memory");
-        } else {
+        else
              shm_id_1 = -1;
-        }
      }
 
      cleanup();
@@ -143,42 +119,22 @@ int main(int ac, char **av)
      tst_exit();
  }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
  void setup(void)
  {
-
      tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
      TEST_PAUSE;
 
-    /*
-     * Create a temporary directory and cd into it.
-     * This helps to ensure that a unique msgkey is created.
-     * See ../lib/libipc.c for more information.
-     */
      tst_tmpdir();
 
-    /* get an IPC resource key */
      shmkey = getipckey();
  }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- *            or premature exit.
- */
  void cleanup(void)
  {
-    /* if it exists, remove the shared memory resource */
      rm_shm(shm_id_1);
 
      tst_rmdir();
 
Quoted 10 lines

testcases/kernel/syscalls/ipc/shmget/shmget01.c int main(int ac, char **av) · line 140

Quoted 8 lines
testcases/kernel/syscalls/ipc/shmget/shmget01.c +0 -5
-    /*
-     * print timing stats if that option was specified.
-     * print errno log if that option was specified.
-     */
      TEST_CLEANUP;
-
  }

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list