plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * 07/2001 Ported by Wayne Boyer |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 9 | * |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 14 | * |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 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 Foundation, |
| 17 | * 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 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 21 | * Test Description: |
| 22 | * Verify that nanosleep() will fail to suspend the execution |
| 23 | * of a process if the specified pause time is invalid. |
| 24 | * |
| 25 | * Expected Result: |
| 26 | * nanosleep() should return with -1 value and sets errno to EINVAL. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | */ |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 28 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 29 | #include <errno.h> |
| 30 | #include <unistd.h> |
| 31 | #include <fcntl.h> |
Steven Jackson | 249f405 | 2016-12-13 16:16:00 +0000 | [diff] [blame^] | 32 | #include <sys/wait.h> |
robbiew | 01be333 | 2003-03-26 23:48:41 +0000 | [diff] [blame] | 33 | #include <time.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | |
| 35 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 37 | static struct timespec tcases[] = { |
| 38 | {.tv_sec = -5, .tv_nsec = 9999}, |
| 39 | {.tv_sec = 0, .tv_nsec = 1000000000}, |
| 40 | }; |
| 41 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 42 | char *TCID = "nanosleep04"; |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 43 | int TST_TOTAL = ARRAY_SIZE(tcases); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 45 | static void setup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 47 | static void verify_nanosleep(struct timespec *tcase) |
| 48 | { |
| 49 | TEST(nanosleep(tcase, NULL)); |
| 50 | |
| 51 | if (TEST_RETURN != -1) { |
| 52 | tst_resm(TFAIL, "nanosleep() succeded unexpectedly"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if (TEST_ERRNO != EINVAL) { |
| 57 | tst_resm(TFAIL | TTERRNO, |
| 58 | "nanosleep() expected failure with EINVAL"); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | tst_resm(TPASS, "nanoslep() failed with EINVAL"); |
| 63 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | { |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 67 | int lc, i; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | |
Cyril Hrubis | d6d11d0 | 2015-03-09 17:35:43 +0100 | [diff] [blame] | 69 | tst_parse_opts(ac, av, NULL, NULL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | setup(); |
| 72 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 74 | for (i = 0; i < TST_TOTAL; i++) |
| 75 | verify_nanosleep(&tcases[i]); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 76 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 78 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 79 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 81 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | { |
Cyril Hrubis | b4be63d | 2015-02-19 13:37:42 +0100 | [diff] [blame] | 83 | tst_sig(FORK, DEF_HANDLER, NULL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | TEST_PAUSE; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 86 | } |