plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * shmdt02.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * shmdt02 - check for EINVAL error |
| 26 | * |
| 27 | * ALGORITHM |
| 28 | * loop if that option was specified |
| 29 | * call shmdt() using an invalid shared memory address |
| 30 | * check the errno value |
| 31 | * issue a PASS message if we get EINVAL |
| 32 | * otherwise, the tests fails |
| 33 | * issue a FAIL message |
| 34 | * call cleanup |
| 35 | * |
| 36 | * USAGE: <for command-line> |
| 37 | * shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] |
| 38 | * where, -c n : Run n copies concurrently. |
| 39 | * -e : Turn on errno logging. |
| 40 | * -i n : Execute test n times. |
| 41 | * -I x : Execute test for x seconds. |
| 42 | * -P x : Pause for x seconds between iterations. |
| 43 | * -t : Turn on syscall timing. |
| 44 | * |
| 45 | * HISTORY |
| 46 | * 03/2001 - Written by Wayne Boyer |
| 47 | * |
| 48 | * RESTRICTIONS |
| 49 | * none |
| 50 | */ |
| 51 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 52 | #include "ipcshm.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | |
| 54 | char *TCID = "shmdt02"; |
| 55 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 57 | int exp_enos[] = { EINVAL, 0 }; /* 0 terminated list of expected errnos */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
robbiew | 23499f0 | 2002-11-18 19:54:58 +0000 | [diff] [blame] | 59 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 61 | int lc; |
| 62 | char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 63 | int unshared; /* a local variable to use to produce *//* the error in the shmdt() call */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 65 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 66 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | } |
| 68 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 69 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
| 71 | /* The following loop checks looping state if -i option given */ |
| 72 | |
| 73 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame^] | 74 | /* reset tst_count in case we are looping */ |
| 75 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 78 | * make the call using the TEST() macro - attempt to |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | * remove an invalid shared memory address |
| 80 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 81 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | TEST(shmdt(&unshared)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 83 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | if (TEST_RETURN != -1) { |
| 85 | tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly"); |
| 86 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | TEST_ERROR_LOG(TEST_ERRNO); |
| 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | switch (TEST_ERRNO) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | case EINVAL: |
| 92 | tst_resm(TPASS, "expected failure - errno = %d : %s", |
| 93 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 94 | break; |
| 95 | default: |
| 96 | tst_resm(TFAIL, "call failed with an unexpected error " |
| 97 | "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | cleanup(); |
| 103 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 104 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * setup() - performs all the ONE TIME setup for this test. |
| 109 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 112 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 114 | |
| 115 | /* Set up the expected error numbers for -e option */ |
| 116 | TEST_EXP_ENOS(exp_enos); |
| 117 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | TEST_PAUSE; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 123 | * or premature exit. |
| 124 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 125 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | { |
| 127 | /* |
| 128 | * print timing stats if that option was specified. |
| 129 | * print errno log if that option was specified. |
| 130 | */ |
| 131 | TEST_CLEANUP; |
| 132 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 133 | } |