|
Packit Service |
a2ae7a |
/* Test of nanosleep() function.
|
|
Packit Service |
a2ae7a |
Copyright (C) 2009-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Written by Eric Blake <ebb9@byu.net>, 2009. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <time.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "signature.h"
|
|
Packit Service |
a2ae7a |
SIGNATURE_CHECK (nanosleep, int, (struct timespec const *, struct timespec *));
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <errno.h>
|
|
Packit Service |
a2ae7a |
#include <signal.h>
|
|
Packit Service |
a2ae7a |
#include <unistd.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "macros.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#if HAVE_DECL_ALARM
|
|
Packit Service |
a2ae7a |
static void
|
|
Packit Service |
a2ae7a |
handle_alarm (int sig)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
if (sig != SIGALRM)
|
|
Packit Service |
a2ae7a |
_exit (1);
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
main (void)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
struct timespec ts;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
ts.tv_sec = 1000;
|
|
Packit Service |
a2ae7a |
ts.tv_nsec = -1;
|
|
Packit Service |
a2ae7a |
errno = 0;
|
|
Packit Service |
a2ae7a |
ASSERT (nanosleep (&ts, NULL) == -1);
|
|
Packit Service |
a2ae7a |
ASSERT (errno == EINVAL);
|
|
Packit Service |
a2ae7a |
ts.tv_nsec = 1000000000;
|
|
Packit Service |
a2ae7a |
errno = 0;
|
|
Packit Service |
a2ae7a |
ASSERT (nanosleep (&ts, NULL) == -1);
|
|
Packit Service |
a2ae7a |
ASSERT (errno == EINVAL);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
ts.tv_sec = 0;
|
|
Packit Service |
a2ae7a |
ts.tv_nsec = 1;
|
|
Packit Service |
a2ae7a |
ASSERT (nanosleep (&ts, &ts) == 0);
|
|
Packit Service |
a2ae7a |
/* Remaining time is only defined on EINTR failure; but on success,
|
|
Packit Service |
a2ae7a |
it is typically either 0 or unchanged from input. At any rate,
|
|
Packit Service |
a2ae7a |
it shouldn't be randomly changed to unrelated values. */
|
|
Packit Service |
a2ae7a |
ASSERT (ts.tv_sec == 0);
|
|
Packit Service |
a2ae7a |
ASSERT (ts.tv_nsec == 0 || ts.tv_nsec == 1);
|
|
Packit Service |
a2ae7a |
ts.tv_nsec = 0;
|
|
Packit Service |
a2ae7a |
ASSERT (nanosleep (&ts, NULL) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#if HAVE_DECL_ALARM
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
const time_t pentecost = 50 * 24 * 60 * 60; /* 50 days. */
|
|
Packit Service |
a2ae7a |
signal (SIGALRM, handle_alarm);
|
|
Packit Service |
a2ae7a |
alarm (1);
|
|
Packit Service |
a2ae7a |
ts.tv_sec = pentecost;
|
|
Packit Service |
a2ae7a |
ts.tv_nsec = 999999999;
|
|
Packit Service |
a2ae7a |
errno = 0;
|
|
Packit Service |
a2ae7a |
ASSERT (nanosleep (&ts, &ts) == -1);
|
|
Packit Service |
a2ae7a |
ASSERT (errno == EINTR);
|
|
Packit Service |
a2ae7a |
ASSERT (pentecost - 10 < ts.tv_sec && ts.tv_sec <= pentecost);
|
|
Packit Service |
a2ae7a |
ASSERT (0 <= ts.tv_nsec && ts.tv_nsec <= 999999999);
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
}
|