bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getloadavg test


From: Paul Eggert
Subject: Re: getloadavg test
Date: Tue, 15 Feb 2011 13:11:20 -0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7

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

From c46ceeaabfab5055455daf282e64bc37d3a98ea9 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
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  <address@hidden>
---
 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  <address@hidden>
+ 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  <address@hidden>
+
        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

[Prev in Thread] Current Thread [Next in Thread]