about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--buildtools/Makefile16
-rw-r--r--buildtools/testrandom.c130
-rw-r--r--test/all-in-place.ok2
-rw-r--r--test/pgmcrater.test5
-rw-r--r--test/pgmnoise.test4
-rw-r--r--test/ppmforge.test5
-rwxr-xr-xtest/ppmpat.test5
-rw-r--r--test/ppmrough.test5
8 files changed, 154 insertions, 18 deletions
diff --git a/buildtools/Makefile b/buildtools/Makefile
index 9c0ee778..e90feeca 100644
--- a/buildtools/Makefile
+++ b/buildtools/Makefile
@@ -9,11 +9,21 @@ include $(BUILDDIR)/config.mk
 MERGE_OBJECTS =
 
 # These are programs that are used by the make files:
-PROGS = libopt typegen endiangen
+BUILDPROGS = libopt typegen endiangen
+
+# Ideally, this directory would not contain anything but build tools, which
+# means they would all be built to run in the build environment, not the
+# target environment.  But we have no other convenient place for test tools,
+# so we put them here and build them for the target environment.
+TESTPROGS = testrandom
+
+PROGS = $(BUILDPROGS) $(TESTPROGS)
 
 all: $(PROGS)
 
-BINARIES =
+PORTBINARIES = $(TESTPROGS)
+BINARIES = $(PORTBINARIES)
+OBJECTS = $(BINARIES:%=%.o)
 SCRIPTS =
 
 OMIT_BUILDTOOL_RULE = 1
@@ -36,7 +46,7 @@ libopt.o: libopt.c
 typegen.o endiangen.o:%.o:%.c
 	$(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) $<
 
-$(PROGS):%:%.o
+$(BUILDPROGS):%:%.o
 	$(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $<
 
 distclean clean: cleanlocal
diff --git a/buildtools/testrandom.c b/buildtools/testrandom.c
new file mode 100644
index 00000000..3f65f0d2
--- /dev/null
+++ b/buildtools/testrandom.c
@@ -0,0 +1,130 @@
+/*=============================================================================
+                                   testrandom
+===============================================================================
+  Test for the random number generator type by generating 5 values with rand()
+  and comparing them against values in a table.
+
+  Currently only recognizes ISO glibc rand().
+
+  Options:
+    -q : quiet mode
+    -v : verbose mode : Use to generate values for new table 
+=============================================================================*/
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Exit values */
+#define EXIT_ERROR 1
+#define EXIT_UNKNOWN 80
+#define ISO_GLIBC 81
+/* 82-90: reserved */
+
+typedef enum {QUIET=0, NORMAL=1, VERBOSE=2} VerbosityLevel;
+
+/* On some Sun systems RAND_MAX is not defined */
+#ifndef RAND_MAX
+#define RAND_MAX 0
+#endif
+
+#define SEED 3791
+
+static struct { 
+    int          const type;
+        /* Exit value for this rand() function  */
+    int          const randMax;
+        /* Usually 0x7fffffff, sometimes 0x7fff */
+        /* Other values are possible; 0 means undefined */
+    unsigned int const res[5];
+        /* Sample values returned from our tests */
+    const char * const name;
+        /* Name for this rand() function */
+} rTable[2] = {
+    { ISO_GLIBC,  /* glibc rand() */ 
+      0x7fffffff, /* 31 bits */ 
+      { 217313873, 969144303, 1757357552, 1096307597, 818311031 },
+      "ISO C glibc rand() or equivalent" },
+    
+    /* Insert additional entries here */
+    
+    { 0,   /* terminating code */
+      0,
+      {0, 0, 0, 0, 0}, NULL  /* unknown type */}
+};
+
+
+
+static void
+parseCommandLine(int              const argc,
+                 const char *     const argv[],
+                 VerbosityLevel * const verbosityP) {
+
+    *verbosityP = NORMAL; /* Initial value */
+
+    if (argc == 2) {
+        if (argv[1][0] == '-' && argv[1][2] == '\0') {
+            switch ( argv[1][1] ) {
+            case 'v' : *verbosityP = VERBOSE; break;
+            case 'q' : *verbosityP = QUIET  ; break;
+            default :  fprintf (stderr,
+                                "Error: Unrecognized argument: %s\n", argv[1]);
+                exit (EXIT_ERROR);
+            }
+        } 
+    }
+    if (argc > 2 ) {
+        fprintf (stderr, "Error: Too many arguments.\n");
+        exit (EXIT_ERROR);
+    }
+}
+
+
+
+int
+main(int const argc, const char * const argv[]) {
+
+    unsigned int i;
+    unsigned int res[5];
+    VerbosityLevel verbosity;
+
+    parseCommandLine(argc, argv, &verbosity);
+
+    if (verbosity == VERBOSE) {
+        if (RAND_MAX > 0)
+            fprintf(stderr, "RAND_MAX = 0x%x (%d)\n", RAND_MAX, RAND_MAX);
+        else
+            fprintf(stderr, "RAND_MAX is undefined\n");
+    }
+
+    /* Set seed for pseudo-random number generator */
+    if (verbosity == VERBOSE)
+        fprintf(stderr, "Generating samples. Seed=%u\n", SEED);
+
+    srand(SEED);
+
+    /*  Generate five samples and store in array res[] */
+    for (i = 0; i < 5; ++i) {
+        res[i] = rand();
+        if (verbosity == VERBOSE)
+            fprintf (stderr, "%d\n",res[i]);
+    }
+
+    /*  Look for a match in table */
+    for (i = 0; rTable[i].type != 0; ++i) {
+        if (rTable[i].randMax == RAND_MAX && rTable[i].res[0] == res[0] &&
+            rTable[i].res[1] == res[1] &&    rTable[i].res[2] == res[2] &&
+            rTable[i].res[3] == res[3] &&    rTable[i].res[4] == res[4]) {
+            if (verbosity != QUIET)
+                fprintf(stderr,
+                        "Random number generator is %s.\n", rTable[i].name);
+
+            exit(rTable[i].type);
+        }
+    }
+    /* No matches */
+    if (verbosity != QUIET)   
+        fprintf(stderr, "Random number generator is of unknown type.\n");
+    exit(EXIT_UNKNOWN);
+}
+
+
+
diff --git a/test/all-in-place.ok b/test/all-in-place.ok
index 1510f2e7..ca8ad8c3 100644
--- a/test/all-in-place.ok
+++ b/test/all-in-place.ok
@@ -324,13 +324,13 @@ tgatoppm: ok
 thinkjettopbm: ok
 tifftopnm: ok
 wbmptopbm: ok
+winicontopam: ok
 winicontoppm: ok
 xbmtopbm: ok
 ximtoppm: ok
 xpmtoppm: ok
 xvminitoppm: ok
 xwdtopnm: ok
-winicontopam: ok
 ybmtopbm: ok
 yuvsplittoppm: ok
 yuvtoppm: ok
diff --git a/test/pgmcrater.test b/test/pgmcrater.test
index e8df9a23..e6942cee 100644
--- a/test/pgmcrater.test
+++ b/test/pgmcrater.test
@@ -1,6 +1,5 @@
 #! /bin/bash
 # This script tests: pgmcrater
-# Also requires: pgmnoise
 
 # This test is sensitive to differences in floating point math.
 # With GCC slight results start to appear with -number 75 in
@@ -14,7 +13,7 @@
 # The slight differences in the image file are not discernable by
 # the naked eye.
 
-${PBM_BINPREFIX}pgmnoise --testrandom --quiet
+testrandom -q
 case $? in
    81)
       # Should print: 3828822912 65551
@@ -25,5 +24,5 @@ case $? in
        echo "Skipping: random number generator is not glibc." 1>&2
        exit 80;;
 
-   *)  exit 1;;  # pgmnoise --testrandom failed
+   *)  exit 1;;  # testrandom failed
 esac
diff --git a/test/pgmnoise.test b/test/pgmnoise.test
index 8ee2fccc..60d06510 100644
--- a/test/pgmnoise.test
+++ b/test/pgmnoise.test
@@ -5,7 +5,7 @@
 # We first check whether random number generator is glibc rand().
 # If not, this test is skipped.
 
-${PBM_TESTPREFIX}pgmnoise --testrandom
+testrandom
 
 case $? in
    81)
@@ -18,5 +18,5 @@ case $? in
         echo "Skipping: random number generator is not glibc." 1>&2
         exit 80;;
 
-   *)   exit 1;;  # pgmnoise --testrandom failed
+   *)   exit 1;;  # testrandom failed
 esac
diff --git a/test/ppmforge.test b/test/ppmforge.test
index 014dc543..5ec37e9c 100644
--- a/test/ppmforge.test
+++ b/test/ppmforge.test
@@ -1,11 +1,10 @@
 #! /bin/bash
 # This script tests: ppmforge
-# Also requires: pgmnoise
 
 # Use small x y values to avoid floating point issues.
 
 
-${PBM_BINPREFIX}pgmnoise --testrandom --quiet
+testrandom -q
 case $? in
    81)
       # Test 1: Should print: 3634219838 196623
@@ -16,5 +15,5 @@ case $? in
        echo "Skipping: random number generator is not glibc." 1>&2
        exit 80;;
 
-   *)  exit 1;;  # pgmnoise --testrandom failed
+   *)  exit 1;;  # testrandom failed
 esac
diff --git a/test/ppmpat.test b/test/ppmpat.test
index 669cf17c..af0ce956 100755
--- a/test/ppmpat.test
+++ b/test/ppmpat.test
@@ -1,11 +1,10 @@
 #! /bin/bash
 # This script tests: ppmpat
-# Also requires: pgmnoise
 
 # TODO: Write tests for squig and poles.  It appears that they are
 # sensitive to differences in floating point math.
 
-${PBM_BINPREFIX}pgmnoise --testrandom --quiet
+testrandom -q
 case $? in
    81)
        # Test 1. Should print: 4008533639 781
@@ -31,5 +30,5 @@ case $? in
        echo "Skipping: random number generator is not glibc." 1>&2
        exit 80;;
 
-   *)  exit 1;;  # pgmnoise --testrandom failed
+   *)  exit 1;;  # testrandom failed
 esac
diff --git a/test/ppmrough.test b/test/ppmrough.test
index 1de8dd1b..92cc02d7 100644
--- a/test/ppmrough.test
+++ b/test/ppmrough.test
@@ -1,9 +1,8 @@
 #! /bin/bash
 # This script tests: ppmrough
-# Also requires: pgmnoise
 
 
-${PBM_BINPREFIX}pgmnoise --testrandom --quiet
+testrandom -q
 case $? in
    81)
       # Should print: 378403602 30015
@@ -14,5 +13,5 @@ case $? in
        echo "Skipping: random number generator is not glibc." 1>&2
        exit 80;;
 
-   *)  exit 1;;  # pgmnoise --testrandom failed
+   *)  exit 1;;  # testrandom failed
 esac