From: Cyril H. <su...@li...> - 2013-06-05 15:37:57
|
The branch, master, has been updated via 8a575d291217d366b6d1f04b5608d3258ebde9cf (commit) from ec22fb23398c1d276316db4aeb184cc9464b28be (commit) - Log ----------------------------------------------------------------- commit 8a575d291217d366b6d1f04b5608d3258ebde9cf Author: Cyril Hrubis <ch...@su...> Date: Wed Jun 5 17:28:11 2013 +0200 syscalls/chmod02: Fix test file creation + cleanup 1. Cleanup the code, remove useless comments. 2. The code to create the file is broken and overly complicated, replace it with SAFE_FILE_PRINTF(). Reported-by: jungsoo.son <jun...@lg...> Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/chmod/chmod02.c | 133 +++++------------------------ 1 files changed, 22 insertions(+), 111 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod02.c b/testcases/kernel/syscalls/chmod/chmod02.c index 242cbd3..b324899 100644 --- a/testcases/kernel/syscalls/chmod/chmod02.c +++ b/testcases/kernel/syscalls/chmod/chmod02.c @@ -29,85 +29,14 @@ * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ */ -/* $Id: chmod02.c,v 1.5 2009/08/28 11:49:07 vapier Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : chmod02 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for chmod(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 8 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) chmod(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 - * The libcuts.a and libsys.a libraries must be included in - * the compilation of this test. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the chmod(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 - * chmod(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 - * + +/* + * AUTHOR : William Roske + * CO-PILOT : Dave Fenner + * DATE STARTED : 03/30/92 * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ + * Calls chmod(2) with different modes and expects success. + */ #include <sys/types.h> #include <sys/stat.h> @@ -115,28 +44,25 @@ #include <errno.h> #include <string.h> #include <signal.h> + #include "test.h" #include "usctest.h" +#include "safe_macros.h" -void setup(); -void cleanup(); +static int modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 }; char *TCID = "chmod02"; -int TST_TOTAL = 1; +int TST_TOTAL = ARRAY_SIZE(modes); -char fname[255]; -char *buf = "file contents\n"; +#define FNAME "test_file" -int Modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 }; +static void setup(void); +static void cleanup(void); int main(int ac, char **av) { - int lc; + int lc, i; char *msg; - int ind; - int mode; - - TST_TOTAL = sizeof(Modes) / sizeof(int); if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); @@ -147,20 +73,19 @@ int main(int ac, char **av) tst_count = 0; - for (ind = 0; ind < TST_TOTAL; ind++) { - mode = Modes[ind]; + for (i = 0; i < TST_TOTAL; i++) { - TEST(chmod(fname, mode)); + TEST(chmod(FNAME, modes[i])); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, - "chmod(%s, %#o) failed", fname, mode); + "chmod(%s, %#o) failed", FNAME, modes[i]); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "chmod(%s, %#o) returned %ld", - fname, mode, TEST_RETURN); + FNAME, modes[i], TEST_RETURN); } else tst_count++; } @@ -169,36 +94,22 @@ int main(int ac, char **av) } cleanup(); - tst_exit(); } -void setup() +static void setup(void) { - int fd; - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; tst_tmpdir(); - strcat(fname, "tfile"); - if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "open(%s, O_RDWR|O_CREAT,0700) failed", fname); - } else if (write(fd, &buf, strlen(buf)) == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "write(%s, &buf, strlen(buf)) failed", fname); - } else if (close(fd) == -1) { - tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", fname); - } + SAFE_FILE_PRINTF(cleanup, FNAME, "File content\n"); } -void cleanup() +static void cleanup(void) { TEST_CLEANUP; - tst_rmdir(); - } hooks/post-receive -- ltp |