robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) International Business Machines Corp., 2003. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
| 19 | * TEST IDENTIFIER : clone07 |
| 20 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 21 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 23 | * TEST TITLE : glibc bug test for clone(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 27 | * AUTHOR : Robbie Williamson <robbiew@us.ibm.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 29 | * SIGNALS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 32 | * |
| 33 | * DESCRIPTION |
| 34 | * This is a test for a glibc bug for the clone(2) system call. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 35 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 36 | * Setup: |
| 37 | * Setup signal handling. |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 38 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 39 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 40 | * Test: |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 41 | * Loop if the proper options are given. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Call clone() with only SIGCHLD flag |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 43 | * |
| 44 | * CHILD: |
| 45 | * return 0; |
| 46 | * |
| 47 | * PARENT: |
| 48 | * wait for child to finish |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * If a SIGSEGV is not received by the child for using return() |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 50 | * test passed |
| 51 | * else |
| 52 | * test failed |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 54 | * Cleanup: |
| 55 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 56 | * |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 57 | * USAGE: <for command-line> |
| 58 | * clone01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] |
| 59 | * where, -c n : Run n copies concurrently. |
| 60 | * -e : Turn on errno logging. |
| 61 | * -h : Show help screen |
| 62 | * -f : Turn off functional testing |
| 63 | * -i n : Execute test n times. |
| 64 | * -I x : Execute test for x seconds. |
| 65 | * -p : Pause for SIGUSR1 before starting |
| 66 | * -P x : Pause for x seconds between iterations. |
| 67 | * -t : Turn on syscall timing. |
| 68 | * |
| 69 | ****************************************************************/ |
| 70 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 71 | #if defined UCLINUX && !__THROW |
| 72 | /* workaround for libc bug */ |
| 73 | #define __THROW |
| 74 | #endif |
| 75 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 76 | #include <errno.h> |
| 77 | #include <sched.h> |
| 78 | #include <sys/wait.h> |
| 79 | #include "test.h" |
| 80 | #include "usctest.h" |
robbiew | f41288e | 2003-10-10 15:32:03 +0000 | [diff] [blame] | 81 | #include "clone_platform.h" |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 82 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 83 | #define TRUE 1 |
| 84 | #define FALSE 0 |
| 85 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 86 | static void setup(); |
| 87 | static void cleanup(); |
| 88 | static int do_child(); |
| 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | char *TCID = "clone07"; /* Test program identifier. */ |
| 91 | int TST_TOTAL = 1; /* Total number of test cases. */ |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 92 | |
| 93 | void sigsegv_handler(int); |
| 94 | void sigusr2_handler(int); |
| 95 | static int child_pid; |
| 96 | static int fail = FALSE; |
| 97 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | int main(int ac, char **av) |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 99 | { |
| 100 | |
Jan Stancek | 443d16e | 2012-12-03 13:19:57 +0100 | [diff] [blame^] | 101 | int lc, status; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 102 | char *msg; |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 103 | void *child_stack; /* stack for child */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 105 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 106 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 107 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 108 | setup(); |
| 109 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 111 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | Tst_count = 0; |
subrata_modak | 9d71839 | 2009-04-13 14:35:12 +0000 | [diff] [blame] | 113 | /* Allocate stack for child */ |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 114 | if ((child_stack = (void *) malloc(CHILD_STACK_SIZE)) == NULL) { |
subrata_modak | 9d71839 | 2009-04-13 14:35:12 +0000 | [diff] [blame] | 115 | tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); |
| 116 | } |
| 117 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 118 | /* |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 119 | * Call clone(2) |
| 120 | */ |
vapier | f6d7f09 | 2009-11-03 20:07:35 +0000 | [diff] [blame] | 121 | child_pid = ltp_clone(SIGCHLD, do_child, NULL, |
| 122 | CHILD_STACK_SIZE, child_stack); |
Jan Stancek | 443d16e | 2012-12-03 13:19:57 +0100 | [diff] [blame^] | 123 | if ((wait(&status)) == -1) |
| 124 | tst_brkm(TBROK|TERRNO, cleanup, |
| 125 | "wait failed, status: %d", status); |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 126 | free(child_stack); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 127 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 128 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | if (fail == FALSE) |
| 130 | tst_resm(TPASS, |
| 131 | "Use of return() in child did not cause SIGSEGV"); |
| 132 | else { |
| 133 | tst_resm(TFAIL, "Use of return() in child caused SIGSEGV"); |
| 134 | } |
| 135 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 136 | cleanup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 137 | |
Garrett Cooper | fbb2014 | 2010-12-17 01:57:48 -0800 | [diff] [blame] | 138 | tst_exit(); |
| 139 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 140 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 141 | |
| 142 | /* setup() - performs all ONE TIME setup for this test */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 143 | void setup() |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 144 | { |
| 145 | struct sigaction def_act; |
| 146 | struct sigaction act; |
| 147 | |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 148 | TEST_PAUSE; |
| 149 | |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 150 | act.sa_handler = sigsegv_handler; |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 151 | act.sa_flags = SA_RESTART; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 152 | if ((sigaction(SIGSEGV, &act, NULL)) == -1) { |
vapier | 0874e6f | 2009-08-28 12:07:53 +0000 | [diff] [blame] | 153 | tst_resm(TWARN|TERRNO, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | "sigaction() for SIGSEGV failed in test_setup()"); |
| 155 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 156 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 157 | /* Setup signal handler for SIGUSR2 */ |
| 158 | def_act.sa_handler = sigusr2_handler; |
| 159 | def_act.sa_flags = SA_RESTART | SA_RESETHAND; |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 160 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | if ((sigaction(SIGUSR2, &def_act, NULL)) == -1) { |
vapier | 0874e6f | 2009-08-28 12:07:53 +0000 | [diff] [blame] | 162 | tst_resm(TWARN|TERRNO, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 163 | "sigaction() for SIGUSR2 failed in test_setup()"); |
| 164 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 165 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 166 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 167 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 168 | /* |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 169 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 170 | * completion or premature exit. |
| 171 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | void cleanup() |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 173 | { |
| 174 | |
| 175 | /* |
| 176 | * print timing stats if that option was specified. |
| 177 | * print errno log if that option was specified. |
| 178 | */ |
| 179 | TEST_CLEANUP; |
| 180 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | kill(child_pid, SIGKILL); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 182 | |
| 183 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * do_child() - function executed by child |
| 187 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 188 | int do_child(void) |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 189 | { |
| 190 | return 0; |
| 191 | } |
| 192 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 193 | void sigsegv_handler(int sig) |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 194 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | if (child_pid == 0) { |
| 196 | kill(getppid(), SIGUSR2); |
| 197 | _exit(42); |
| 198 | } |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* sig_default_handler() - Default handler for parent */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 202 | void sigusr2_handler(int sig) |
robbiew | c72e43f | 2003-08-01 15:46:23 +0000 | [diff] [blame] | 203 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 204 | if (child_pid != 0) { |
| 205 | fail = TRUE; |
| 206 | } |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 207 | } |