Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-getloadavg.c @ 16465:c0803728f645
New module 'modfl-ieee'.
* modules/modfl-ieee: New file.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 26 Feb 2012 17:55:31 +0100 |
parents | 8c89b3a442f2 |
children | e542fd46ad6f |
rev | line source |
---|---|
14355 | 1 /* Test of getting load average. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14358
diff
changeset
|
2 Copyright (C) 2011-2012 Free Software Foundation, Inc. |
14355 | 3 |
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. | |
8 | |
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. | |
13 | |
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/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 #include <stdlib.h> | |
20 | |
21 #include "signature.h" | |
22 SIGNATURE_CHECK (getloadavg, int, (double [], int)); | |
23 | |
24 #include <errno.h> | |
25 #include <stdio.h> | |
26 #include <unistd.h> | |
27 | |
28 static void | |
29 check_avg (int minutes, double avg, int printit) | |
30 { | |
31 if (printit) | |
32 printf ("%d-minute: %f ", minutes, avg); | |
14358
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
33 else |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
34 { |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
35 /* Plausibility checks. */ |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
36 if (avg < 0.01) |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
37 printf ("suspiciously low %d-minute average: %f\n", minutes, avg); |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
38 if (avg > 1000000) |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
39 printf ("suspiciously high %d-minute average: %f\n", minutes, avg); |
d1eef489f6fa
getloadavg test: Add some plausibility checks.
Bruno Haible <bruno@clisp.org>
parents:
14355
diff
changeset
|
40 } |
14355 | 41 if (avg < 0 || avg != avg) |
42 exit (minutes); | |
43 } | |
44 | |
45 /* This program can also be used as a manual test, by invoking it with | |
46 an argument; it then prints the load average. If the argument is | |
47 nonzero, the manual test repeats forever, sleeping for the stated | |
48 interval between each iteration. */ | |
49 int | |
50 main (int argc, char **argv) | |
51 { | |
52 int naptime = 0; | |
53 | |
54 if (argc > 1) | |
55 naptime = atoi (argv[1]); | |
56 | |
57 while (1) | |
58 { | |
59 double avg[3]; | |
60 int loads = getloadavg (avg, 3); | |
61 if (loads == -1) | |
62 { | |
16265
8c89b3a442f2
getloadavg test: skip the test on GNU/Linux without /proc mounted
Dmitry V. Levin <ldv@altlinux.org>
parents:
16201
diff
changeset
|
63 if (! (errno == ENOSYS || errno == ENOTSUP || errno == ENOENT)) |
14355 | 64 return 1; |
65 perror ("Skipping test; load average not supported"); | |
66 return 77; | |
67 } | |
68 if (loads > 0) | |
69 check_avg (1, avg[0], argc > 1); | |
70 if (loads > 1) | |
71 check_avg (5, avg[1], argc > 1); | |
72 if (loads > 2) | |
73 check_avg (15, avg[1], argc > 1); | |
74 if (loads > 0 && argc > 1) | |
75 putchar ('\n'); | |
76 | |
77 if (naptime == 0) | |
78 break; | |
79 sleep (naptime); | |
80 } | |
81 | |
82 return 0; | |
83 } |