blob: f5108d02697e94cfd47f08873c90f51e119e1a84 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
Cyril Hrubisb4be63d2015-02-19 13:37:42 +01002 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 Ported by Wayne Boyer
plars865695b2001-08-27 22:15:12 +00004 *
Cyril Hrubisb4be63d2015-02-19 13:37:42 +01005 * 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.
plars865695b2001-08-27 22:15:12 +00009 *
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010010 * 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.
plars865695b2001-08-27 22:15:12 +000014 *
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010015 * 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
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
plars865695b2001-08-27 22:15:12 +000021 * 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.
plars865695b2001-08-27 22:15:12 +000027 */
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010028
plars865695b2001-08-27 22:15:12 +000029#include <errno.h>
30#include <unistd.h>
31#include <fcntl.h>
Steven Jackson249f4052016-12-13 16:16:00 +000032#include <sys/wait.h>
robbiew01be3332003-03-26 23:48:41 +000033#include <time.h>
plars865695b2001-08-27 22:15:12 +000034
35#include "test.h"
plars865695b2001-08-27 22:15:12 +000036
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010037static struct timespec tcases[] = {
38 {.tv_sec = -5, .tv_nsec = 9999},
39 {.tv_sec = 0, .tv_nsec = 1000000000},
40};
41
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020042char *TCID = "nanosleep04";
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010043int TST_TOTAL = ARRAY_SIZE(tcases);
plars865695b2001-08-27 22:15:12 +000044
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010045static void setup(void);
plars865695b2001-08-27 22:15:12 +000046
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010047static 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}
plars865695b2001-08-27 22:15:12 +000064
subrata_modak56207ce2009-03-23 13:35:39 +000065int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000066{
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010067 int lc, i;
subrata_modak56207ce2009-03-23 13:35:39 +000068
Cyril Hrubisd6d11d02015-03-09 17:35:43 +010069 tst_parse_opts(ac, av, NULL, NULL);
plars865695b2001-08-27 22:15:12 +000070
plars865695b2001-08-27 22:15:12 +000071 setup();
72
plars865695b2001-08-27 22:15:12 +000073 for (lc = 0; TEST_LOOPING(lc); lc++) {
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010074 for (i = 0; i < TST_TOTAL; i++)
75 verify_nanosleep(&tcases[i]);
Garrett Cooper2c282152010-12-16 00:55:50 -080076 }
plars865695b2001-08-27 22:15:12 +000077
Garrett Coopera9e49f12010-12-16 10:54:03 -080078 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080079}
plars865695b2001-08-27 22:15:12 +000080
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010081static void setup(void)
plars865695b2001-08-27 22:15:12 +000082{
Cyril Hrubisb4be63d2015-02-19 13:37:42 +010083 tst_sig(FORK, DEF_HANDLER, NULL);
plars865695b2001-08-27 22:15:12 +000084
plars865695b2001-08-27 22:15:12 +000085 TEST_PAUSE;
Chris Dearmanec6edca2012-10-17 19:54:01 -070086}