Blame gl/tests/test-sleep.c
|
Packit |
aea12f |
/* Test of sleep() function.
|
|
Packit Service |
991b93 |
Copyright (C) 2007-2020 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
aea12f |
it under the terms of the GNU General Public License as published by
|
|
Packit |
aea12f |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
aea12f |
(at your option) any later version.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
This program is distributed in the hope that it will be useful,
|
|
Packit |
aea12f |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
aea12f |
GNU General Public License for more details.
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
You should have received a copy of the GNU General Public License
|
|
Packit |
aea12f |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <unistd.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "signature.h"
|
|
Packit |
aea12f |
SIGNATURE_CHECK (sleep, unsigned int, (unsigned int));
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <signal.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "macros.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#if HAVE_DECL_ALARM
|
|
Packit |
aea12f |
static void
|
|
Packit |
aea12f |
handle_alarm (int sig)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
if (sig != SIGALRM)
|
|
Packit |
aea12f |
_exit (1);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
int
|
|
Packit |
aea12f |
main (void)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
ASSERT (sleep (1) <= 1);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
ASSERT (sleep (0) == 0);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#if HAVE_DECL_ALARM
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
const unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */
|
|
Packit |
aea12f |
unsigned int remaining;
|
|
Packit |
aea12f |
signal (SIGALRM, handle_alarm);
|
|
Packit |
aea12f |
alarm (1);
|
|
Packit |
aea12f |
remaining = sleep (pentecost);
|
|
Packit |
aea12f |
ASSERT (pentecost - 10 < remaining && remaining <= pentecost);
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|