1 /* Test of nanosleep() function.
2 Copyright (C) 2009-2011 Free Software Foundation, Inc.
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 3 of the License, or
7 (at your option) any later version.
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 the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
23 #include "signature.h"
24 SIGNATURE_CHECK (nanosleep, int, (struct timespec const *, struct timespec *));
35 handle_alarm (int sig)
50 ASSERT (nanosleep (&ts, NULL) == -1);
51 ASSERT (errno == EINVAL);
52 ts.tv_nsec = 1000000000;
54 ASSERT (nanosleep (&ts, NULL) == -1);
55 ASSERT (errno == EINVAL);
59 ASSERT (nanosleep (&ts, &ts) == 0);
60 /* Remaining time is only defined on EINTR failure; but on success,
61 it is typically either 0 or unchanged from input. At any rate,
62 it shouldn't be randomly changed to unrelated values. */
63 ASSERT (ts.tv_sec == 0);
64 ASSERT (ts.tv_nsec == 0 || ts.tv_nsec == 1);
66 ASSERT (nanosleep (&ts, NULL) == 0);
70 const time_t pentecost = 50 * 24 * 60 * 60; /* 50 days. */
71 signal (SIGALRM, handle_alarm);
73 ts.tv_sec = pentecost;
74 ts.tv_nsec = 999999999;
76 ASSERT (nanosleep (&ts, &ts) == -1);
77 ASSERT (errno == EINTR);
78 ASSERT (pentecost - 10 < ts.tv_sec && ts.tv_sec <= pentecost);
79 ASSERT (0 <= ts.tv_nsec && ts.tv_nsec <= 999999999);