1 /* 2 * Copyright (c) International Business Machines Corp., 2001 3 * 07/2001 Ported by Wayne Boyer 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 Foundation, 17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 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. 27 */ 28 29 #include <errno.h> 30 #include <unistd.h> 31 #include <fcntl.h> 32 #include <sys/wait.h> 33 #include <time.h> 34 35 #include "test.h" 36 37 static struct timespec tcases[] = { 38 {.tv_sec = -5, .tv_nsec = 9999}, 39 {.tv_sec = 0, .tv_nsec = 1000000000}, 40 }; 41 42 char *TCID = "nanosleep04"; 43 int TST_TOTAL = ARRAY_SIZE(tcases); 44 45 static void setup(void); 46 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 } 64 65 int main(int ac, char **av) 66 { 67 int lc, i; 68 69 tst_parse_opts(ac, av, NULL, NULL); 70 71 setup(); 72 73 for (lc = 0; TEST_LOOPING(lc); lc++) { 74 for (i = 0; i < TST_TOTAL; i++) 75 verify_nanosleep(&tcases[i]); 76 } 77 78 tst_exit(); 79 } 80 81 static void setup(void) 82 { 83 tst_sig(FORK, DEF_HANDLER, NULL); 84 85 TEST_PAUSE; 86 } 87