From: <ro...@us...> - 2003-03-25 22:57:12
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/fcntl In directory sc8-pr-cvs1:/tmp/cvs-serv2592 Modified Files: fcntl14.c fcntl15.c Log Message: warnings cleanup Index: fcntl14.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/fcntl/fcntl14.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- fcntl14.c 25 Mar 2003 21:53:42 -0000 1.3 +++ fcntl14.c 25 Mar 2003 22:57:02 -0000 1.4 @@ -541,9 +541,6 @@ int TST_TOTAL = 1; /* Total number of test cases */ extern int Tst_count; /* Test case counter */ -void setup(void); -void cleanup(void); - /* * cleanup() Index: fcntl15.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/fcntl/fcntl15.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- fcntl15.c 18 Feb 2002 22:10:07 -0000 1.2 +++ fcntl15.c 25 Mar 2003 22:57:05 -0000 1.3 @@ -54,6 +54,7 @@ #include <fcntl.h> #include <test.h> #include <usctest.h> +#include <sys/wait.h> #define DATA "ABCDEFGHIJ" #define DUP 0 @@ -69,207 +70,21 @@ static char tmpname[40]; struct flock flock; -void child_sig(), parent_sig(), alarm_sig(); -void setup(void); -void cleanup(void); - -main(int ac, char **av) -{ - int lc; /* loop counter */ - char *msg; /* message returned from parse_opts */ - - int fail = 0; - - /* parse standard options */ - if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ - tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); - } - - setup(); - - /* Check for looping state if -i option is given */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset Tst_count in case we are looping */ - Tst_count = 0; - - /* Set up to catch alarm signal */ - if ((signal(SIGALRM, alarm_sig)) == SIG_ERR) { - perror("SIGALRM signal set up failed"); - exit(1); - } - -block1: - tst_resm(TINFO, "Entering block 1"); - if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, DUP)) { - tst_resm(TINFO, "Test 1: test with \"dup\" FAILED"); - fail = 1; - } else { - tst_resm(TINFO, "Test 1: test with \"dup\" PASSED"); - } - tst_resm(TINFO, "Exiting block 1"); - -block2: - tst_resm(TINFO, "Entering block 2"); - if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, OPEN)) { - tst_resm(TINFO, "Test 2: test with \"open\" FAILED"); - fail = 1; - } else { - tst_resm(TINFO, "Test 2: test with \"open\" PASSED"); - } - tst_resm(TINFO, "Exiting block 2"); - -block3: - tst_resm(TINFO, "Entering block 3"); - if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, FORK_)) { - tst_resm(TINFO, "Test 3: test with \"fork\" FAILED"); - fail = 1; - } else { - tst_resm(TINFO, "Test 3: test with \"fork\" PASSED"); - } - tst_resm(TINFO, "Exiting block 3"); - } - cleanup(); -} - -int -run_test(int file_flag, int file_mode, int dup_flag) +/* + * cleanup() - performs all ONE TIME cleanup for this test at + * completion or premature exit. + */ +void +cleanup() { - int fd_A, fd_B; - - /* setup to catch SIGUSR1 signal from child process */ - if ((signal(SIGUSR1, child_sig)) == SIG_ERR) { - perror("Signal setup for SIGUSR1 failed"); - } - - /* setup to catch SIGUSR2 signal from parent */ - if ((signal(SIGUSR2, parent_sig)) == SIG_ERR) { - perror("Signal setup for SIGUSR1 failed"); - } - - parent = getpid(); - - tst_tmpdir(); - /* setup temporary file name */ - sprintf(tmpname, "fcntl15.%d", parent); - - /* initialize signal flags */ - child_flag = parent_flag = 0; - - if ((fd_A = open(tmpname, file_flag, file_mode)) < 0) { - perror("open first parent file failed"); - tst_rmdir(); - return(1); - } - - /* write some data to the file */ - (void)write(fd_A, DATA, 10); - - if (dup_flag) { - if (dup_flag == FORK_) { - dofork(file_flag, file_mode); - } else { - if ((fd_B = open(tmpname, file_flag, file_mode)) < 0) { - perror("open second parent file failed"); - tst_rmdir(); - return(1); - } - } - } else { - /* create a second file descriptor from first file */ - if ((fd_B = fcntl(fd_A, F_DUPFD, 0)) < 0) { - perror("dup of second parent file failed"); - tst_rmdir(); - return(1); - } - } - - /* - * initialize lock structure for first lock on first - * 5 bytes of file - */ - flock.l_type = F_WRLCK; - flock.l_whence = 0; - flock.l_start = 0L; - flock.l_len = 5L; - - /* set lock on first file descriptor */ - if ((fcntl(fd_A, F_SETLK, &flock)) < 0) { - perror("Attempt to set first parent lock failed"); - tst_rmdir(); - return(1); - } - - if (dup_flag != FORK_) { - /* initialize lock structure for last 5 bytes of file */ - flock.l_type = F_WRLCK; - flock.l_whence = 0; - flock.l_start = 5L; - flock.l_len = 5L; - - /* set lock on second file descriptor */ - if ((fcntl(fd_B, F_SETLK, &flock)) < 0) { - perror("Attempt to set second parent lock failed"); - tst_rmdir(); - return(1); - } - } - - /* create child process */ - if ((child2 = fork()) < 0) { - perror("Fork failure"); - tst_rmdir(); - return(1); - } else if (child2 == 0) { /* child */ - dochild2(file_flag, file_mode, dup_flag); - } - - /* parent */ - /* - * Set alarm to break pause if child fails to signal then spin till - * child is ready + * print timing stats if that option was specified. + * print errno log if that option was specified. */ - if (child_flag == 0) { - alarm(60); - pause(); - alarm((unsigned)0); - if (child_flag != 1) { - perror("Pause terminated without SIGUSR1 " - "signal from child"); - tst_rmdir(); - return(1); - } - } - - /* close the first file then signal child to test locks */ - close(fd_A); - if ((kill(child2, SIGUSR2)) < 0) { - perror("Signal to child2 failed"); - tst_rmdir(); - return(1); - } + TEST_CLEANUP; - if (dup_flag == FORK_) { - if ((kill(child1, SIGUSR2)) < 0) { - perror("Signal to child1 failed"); - tst_rmdir(); - return(1); - } - } - /* wait for child to complete then cleanup */ - while ((wait(&status)) > 0) { - if (status >> 8 != 0) { - tst_resm(TFAIL, "Expected 0 got %d", status >> 8); - tst_rmdir(); - return(1); - } - } - if (dup_flag != FORK_) { - close(fd_B); - } - unlink(tmpname); - tst_rmdir(); - return(0); + /* exit with return code appropriate for results */ + tst_exit(); } void @@ -297,37 +112,7 @@ parent_flag++; } -dofork(int file_flag, int file_mode) -{ - /* create child process */ - if ((child1 = fork()) < 0) { - perror("Fork failure"); - return(1); - } - - /* child1 */ - if (child1 == 0) { - dochild1(file_flag, file_mode); - } else { - /* - * need to wait for child1 to open, and lock the area of the - * file prior to continuing on from here - */ - if (child_flag == 0) { - alarm(60); - pause(); - alarm((unsigned)0); - if (child_flag == 0) { - perror("parent paused without SIGUSR1 " - "from child"); - return(1); - } - child_flag = 0; /* reset the child flag for child2 */ - } - } -} - -dochild1(int file_flag, int file_mode) +int dochild1(int file_flag, int file_mode) { int fd_B; @@ -377,7 +162,38 @@ exit(0); } -dochild2(int file_flag, int file_mode, int dup_flag) +int dofork(int file_flag, int file_mode) +{ + /* create child process */ + if ((child1 = fork()) < 0) { + perror("Fork failure"); + return(1); + } + + /* child1 */ + if (child1 == 0) { + dochild1(file_flag, file_mode); + } else { + /* + * need to wait for child1 to open, and lock the area of the + * file prior to continuing on from here + */ + if (child_flag == 0) { + alarm(60); + pause(); + alarm((unsigned)0); + if (child_flag == 0) { + perror("parent paused without SIGUSR1 " + "from child"); + return(1); + } + child_flag = 0; /* reset the child flag for child2 */ + } + } + return(0); +} + +int dochild2(int file_flag, int file_mode, int dup_flag) { int fd_C; @@ -481,20 +297,202 @@ } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void -cleanup() +int +run_test(int file_flag, int file_mode, int dup_flag) { + int fd_A, fd_B; + + /* setup to catch SIGUSR1 signal from child process */ + if ((signal(SIGUSR1, child_sig)) == SIG_ERR) { + perror("Signal setup for SIGUSR1 failed"); + } + + /* setup to catch SIGUSR2 signal from parent */ + if ((signal(SIGUSR2, parent_sig)) == SIG_ERR) { + perror("Signal setup for SIGUSR1 failed"); + } + + parent = getpid(); + + tst_tmpdir(); + /* setup temporary file name */ + sprintf(tmpname, "fcntl15.%d", parent); + + /* initialize signal flags */ + child_flag = parent_flag = 0; + + if ((fd_A = open(tmpname, file_flag, file_mode)) < 0) { + perror("open first parent file failed"); + tst_rmdir(); + return(1); + } + + /* write some data to the file */ + (void)write(fd_A, DATA, 10); + + if (dup_flag) { + if (dup_flag == FORK_) { + dofork(file_flag, file_mode); + } else { + if ((fd_B = open(tmpname, file_flag, file_mode)) < 0) { + perror("open second parent file failed"); + tst_rmdir(); + return(1); + } + } + } else { + /* create a second file descriptor from first file */ + if ((fd_B = fcntl(fd_A, F_DUPFD, 0)) < 0) { + perror("dup of second parent file failed"); + tst_rmdir(); + return(1); + } + } + + /* + * initialize lock structure for first lock on first + * 5 bytes of file + */ + flock.l_type = F_WRLCK; + flock.l_whence = 0; + flock.l_start = 0L; + flock.l_len = 5L; + + /* set lock on first file descriptor */ + if ((fcntl(fd_A, F_SETLK, &flock)) < 0) { + perror("Attempt to set first parent lock failed"); + tst_rmdir(); + return(1); + } + + if (dup_flag != FORK_) { + /* initialize lock structure for last 5 bytes of file */ + flock.l_type = F_WRLCK; + flock.l_whence = 0; + flock.l_start = 5L; + flock.l_len = 5L; + + /* set lock on second file descriptor */ + if ((fcntl(fd_B, F_SETLK, &flock)) < 0) { + perror("Attempt to set second parent lock failed"); + tst_rmdir(); + return(1); + } + } + + /* create child process */ + if ((child2 = fork()) < 0) { + perror("Fork failure"); + tst_rmdir(); + return(1); + } else if (child2 == 0) { /* child */ + dochild2(file_flag, file_mode, dup_flag); + } + + /* parent */ + /* - * print timing stats if that option was specified. - * print errno log if that option was specified. + * Set alarm to break pause if child fails to signal then spin till + * child is ready */ - TEST_CLEANUP; + if (child_flag == 0) { + alarm(60); + pause(); + alarm((unsigned)0); + if (child_flag != 1) { + perror("Pause terminated without SIGUSR1 " + "signal from child"); + tst_rmdir(); + return(1); + } + } - /* exit with return code appropriate for results */ - tst_exit(); + /* close the first file then signal child to test locks */ + close(fd_A); + if ((kill(child2, SIGUSR2)) < 0) { + perror("Signal to child2 failed"); + tst_rmdir(); + return(1); + } + + if (dup_flag == FORK_) { + if ((kill(child1, SIGUSR2)) < 0) { + perror("Signal to child1 failed"); + tst_rmdir(); + return(1); + } + } + /* wait for child to complete then cleanup */ + while ((wait(&status)) > 0) { + if (status >> 8 != 0) { + tst_resm(TFAIL, "Expected 0 got %d", status >> 8); + tst_rmdir(); + return(1); + } + } + if (dup_flag != FORK_) { + close(fd_B); + } + unlink(tmpname); + tst_rmdir(); + return(0); } +int main(int ac, char **av) +{ + int lc; /* loop counter */ + char *msg; /* message returned from parse_opts */ + + int fail = 0; + + /* parse standard options */ + if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ + tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); + } + + setup(); + + /* Check for looping state if -i option is given */ + for (lc = 0; TEST_LOOPING(lc); lc++) { + /* reset Tst_count in case we are looping */ + Tst_count = 0; + + /* Set up to catch alarm signal */ + if ((signal(SIGALRM, alarm_sig)) == SIG_ERR) { + perror("SIGALRM signal set up failed"); + exit(1); + } + +//block1: + tst_resm(TINFO, "Entering block 1"); + if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, DUP)) { + tst_resm(TINFO, "Test 1: test with \"dup\" FAILED"); + fail = 1; + } else { + tst_resm(TINFO, "Test 1: test with \"dup\" PASSED"); + } + tst_resm(TINFO, "Exiting block 1"); + +//block2: + tst_resm(TINFO, "Entering block 2"); + if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, OPEN)) { + tst_resm(TINFO, "Test 2: test with \"open\" FAILED"); + fail = 1; + } else { + tst_resm(TINFO, "Test 2: test with \"open\" PASSED"); + } + tst_resm(TINFO, "Exiting block 2"); + +//block3: + tst_resm(TINFO, "Entering block 3"); + if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, FORK_)) { + tst_resm(TINFO, "Test 3: test with \"fork\" FAILED"); + fail = 1; + } else { + tst_resm(TINFO, "Test 3: test with \"fork\" PASSED"); + } + tst_resm(TINFO, "Exiting block 3"); + } + cleanup(); + return(0); +} |