subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
| 4 | /* This program is free software; you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU General Public License as published by */ |
| 6 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 7 | /* (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* This program is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 12 | /* the GNU General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU General Public License */ |
| 15 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 17 | /* */ |
| 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
| 20 | /* */ |
| 21 | /* File: exit_group01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the exit_group() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* exit_group01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 27 | /* where, -c n : Run n copies concurrently. */ |
| 28 | /* -e : Turn on errno logging. */ |
| 29 | /* -i n : Execute test n times. */ |
| 30 | /* -I x : Execute test for x seconds. */ |
| 31 | /* -P x : Pause for x seconds between iterations. */ |
| 32 | /* -t : Turn on syscall timing. */ |
| 33 | /* */ |
| 34 | /* Total Tests: 1 */ |
| 35 | /* */ |
| 36 | /* Test Name: exit_group01 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 39 | /******************************************************************************/ |
| 40 | |
| 41 | #include <stdio.h> |
| 42 | #include <errno.h> |
| 43 | #include <linux/unistd.h> |
| 44 | #include <sys/wait.h> |
| 45 | |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 46 | #include "test.h" |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 47 | #include "linux_syscall_numbers.h" |
| 48 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 49 | char *TCID = "exit_group01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 50 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 51 | int TST_TOTAL = 1; |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 52 | |
| 53 | /* Extern Global Functions */ |
| 54 | /******************************************************************************/ |
| 55 | /* */ |
| 56 | /* Function: cleanup */ |
| 57 | /* */ |
| 58 | /* Description: Performs all one time clean up for this test on successful */ |
| 59 | /* completion, premature exit or failure. Closes all temporary */ |
| 60 | /* files, removes all temporary directories exits the test with */ |
| 61 | /* appropriate return code by calling tst_exit() function. */ |
| 62 | /* */ |
| 63 | /* Input: None. */ |
| 64 | /* */ |
| 65 | /* Output: None. */ |
| 66 | /* */ |
| 67 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 68 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 69 | /* */ |
| 70 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 71 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 72 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 73 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 74 | tst_rmdir(); |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* Local Functions */ |
| 78 | /******************************************************************************/ |
| 79 | /* */ |
| 80 | /* Function: setup */ |
| 81 | /* */ |
| 82 | /* Description: Performs all one time setup for this test. This function is */ |
| 83 | /* typically used to capture signals, create temporary dirs */ |
| 84 | /* and temporary files that may be used in the course of this */ |
| 85 | /* test. */ |
| 86 | /* */ |
| 87 | /* Input: None. */ |
| 88 | /* */ |
| 89 | /* Output: None. */ |
| 90 | /* */ |
| 91 | /* Return: On failure - Exits by calling cleanup(). */ |
| 92 | /* On success - returns 0. */ |
| 93 | /* */ |
| 94 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 95 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 96 | { |
| 97 | /* Capture signals if any */ |
| 98 | /* Create temporary directories */ |
| 99 | TEST_PAUSE; |
| 100 | tst_tmpdir(); |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | int main(int ac, char **av) |
| 104 | { |
| 105 | int status; |
| 106 | pid_t cpid, w; |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 107 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | setup(); |
subrata_modak | 25082ae | 2009-05-21 18:14:40 +0000 | [diff] [blame] | 109 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | cpid = fork(); //call exit_group() |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 111 | if (cpid == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | tst_brkm(TFAIL | TERRNO, cleanup, "fork failed"); |
Garrett Cooper | 9dc1a3d | 2011-01-18 23:30:01 -0800 | [diff] [blame] | 113 | } else if (cpid == 0) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 114 | sleep(5); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 115 | TEST(ltp_syscall(__NR_exit_group, 4)); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 116 | } else { |
| 117 | w = wait(&status); |
| 118 | if (w == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 119 | tst_brkm(TBROK | TERRNO, cleanup, "wait failed"); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 120 | if (WIFEXITED(status) && (WEXITSTATUS(status) == 4)) |
| 121 | tst_resm(TPASS, "exit_group succeeded"); |
| 122 | else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | tst_resm(TFAIL | TERRNO, |
| 124 | "exit_group failed (wait status = %d)", w); |
| 125 | } |
| 126 | } |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 127 | cleanup(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 128 | tst_exit(); |
Garrett Cooper | 9dc1a3d | 2011-01-18 23:30:01 -0800 | [diff] [blame] | 129 | } |