annotate tests/test-sleep.c @ 17848:ab58d4870664

version-etc: new year * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date. * all files: Run 'make update-copyright'.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 01 Jan 2015 01:38:23 +0000
parents 344018b6e5d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of sleep() function.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8787
diff changeset
4 This program is free software: you can redistribute it and/or modify
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8787
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8787
diff changeset
7 (at your option) any later version.
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8787
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <unistd.h>
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12481
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12481
diff changeset
24 SIGNATURE_CHECK (sleep, unsigned int, (unsigned int));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12481
diff changeset
25
12326
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
26 #include <signal.h>
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
28 #include "macros.h"
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
12326
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
30 #if HAVE_DECL_ALARM
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
31 static void
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
32 handle_alarm (int sig)
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
33 {
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
34 if (sig != SIGALRM)
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
35 _exit (1);
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
36 }
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
37 #endif
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
38
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 int
12481
f5dcba492f50 tests: avoid compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12326
diff changeset
40 main (void)
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 ASSERT (sleep (1) <= 1);
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 ASSERT (sleep (0) == 0);
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
12326
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
46 #if HAVE_DECL_ALARM
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
47 {
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
48 const unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
49 unsigned int remaining;
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
50 signal (SIGALRM, handle_alarm);
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
51 alarm (1);
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
52 remaining = sleep (pentecost);
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
53 ASSERT (pentecost - 10 < remaining && remaining <= pentecost);
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
54 }
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
55 #endif
25e64e77bb53 sleep: work around cygwin bug
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
56
8787
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 return 0;
e6cc4a44ff1a Tests for module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }