Thanks for that review, Bruno.  I'll add the following before pushing:

From c46ceeaabfab5055455daf282e64bc37d3a98ea9 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 15 Feb 2011 13:09:20 -0800
Subject: [PATCH] test-getloadavg: make it act like other tests

Suggested by Bruno Haible in
<http://lists.gnu.org/archive/html/bug-gnulib/2011-02/msg00186.html>.
* tests/test-getloadavg.c (check_avg): New function.
(main): Use it.

2011-02-15  Paul Eggert  <[email protected]>
---
 ChangeLog               |    9 +++++++++
 tests/test-getloadavg.c |   28 ++++++++++++++++++++--------
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5bfbfe3..a4b973f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2011-02-15  Paul Eggert  <[email protected]>
+ test-getloadavg: make it act like other tests
+
+       Suggested by Bruno Haible in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2011-02/msg00186.html>.
+       * tests/test-getloadavg.c (check_avg): New function.
+       (main): Use it.
+
+2011-02-15  Paul Eggert  <[email protected]>
+
        getloadavg: set errno
* lib/getloadavg.c: Set errno when returning -1. If no other
diff --git a/tests/test-getloadavg.c b/tests/test-getloadavg.c
index 1dc0437..f9b4a79 100644
--- a/tests/test-getloadavg.c
+++ b/tests/test-getloadavg.c
@@ -25,6 +25,19 @@ SIGNATURE_CHECK (getloadavg, int, (double [], int));
 #include <stdio.h>
 #include <unistd.h>
+static void
+check_avg (int minutes, double avg, int printit)
+{
+  if (printit)
+    printf ("%d-minute: %f  ", minutes, avg);
+  if (avg < 0 || avg != avg)
+    exit (minutes);
+}
+
+/* This program can also be used as a manual test, by invoking it with
+   an argument; it then prints the load average.  If the argument is
+   nonzero, the manual test repeats forever, sleeping for the stated
+   interval between each iteration.  */
 int
 main (int argc, char **argv)
 {
@@ -36,22 +49,21 @@ main (int argc, char **argv)
   while (1)
     {
       double avg[3];
-      int loads;
-
-      errno = 0;                /* Don't be misled if it doesn't set errno.  */
-      loads = getloadavg (avg, 3);
+      int loads = getloadavg (avg, 3);
       if (loads == -1)
         {
+          if (! (errno == ENOSYS || errno == ENOTSUP))
+            return 1;
           perror ("Skipping test; load average not supported");
           return 77;
         }
       if (loads > 0)
-        printf ("1-minute: %f  ", avg[0]);
+        check_avg (1, avg[0], argc > 1);
       if (loads > 1)
-        printf ("5-minute: %f  ", avg[1]);
+        check_avg (5, avg[1], argc > 1);
       if (loads > 2)
-        printf ("15-minute: %f  ", avg[2]);
-      if (loads > 0)
+        check_avg (15, avg[1], argc > 1);
+      if (loads > 0 && argc > 1)
         putchar ('\n');
if (naptime == 0)
--
1.7.4


Reply via email to