diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-12-02 03:00:57 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-12-02 03:00:57 +0000 |
commit | 8cd418cff0eae8d2190a165202f1efb9f0cb9046 (patch) | |
tree | c1703b93d27a322d725930270512bd32bdad74e3 /test | |
parent | 33df17eedb1d9220f280115a3300ac655ac03a38 (diff) | |
download | netpbm-mirror-8cd418cff0eae8d2190a165202f1efb9f0cb9046.tar.gz netpbm-mirror-8cd418cff0eae8d2190a165202f1efb9f0cb9046.tar.xz netpbm-mirror-8cd418cff0eae8d2190a165202f1efb9f0cb9046.zip |
Make tests work on Mac OS
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3096 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'test')
-rwxr-xr-x | test/Execute-Tests | 56 | ||||
-rw-r--r-- | test/Makefile | 10 | ||||
-rw-r--r-- | test/pgmnoise.ok | 1 | ||||
-rw-r--r-- | test/pgmnoise.rand-ok | 3 | ||||
-rwxr-xr-x | test/pgmnoise.test | 22 | ||||
-rw-r--r-- | test/ppmforge.ok | 1 | ||||
-rw-r--r-- | test/ppmforge.rand-ok | 3 | ||||
-rwxr-xr-x | test/ppmforge.test | 17 | ||||
-rw-r--r-- | test/ppmpat-random.ok | 3 | ||||
-rw-r--r-- | test/ppmpat-random.rand-ok | 7 | ||||
-rwxr-xr-x | test/ppmpat-random.test | 30 | ||||
-rw-r--r-- | test/ppmrough.ok | 1 | ||||
-rw-r--r-- | test/ppmrough.rand-ok | 3 | ||||
-rwxr-xr-x | test/ppmrough.test | 15 | ||||
-rw-r--r-- | test/testrandom.c | 30 |
15 files changed, 100 insertions, 102 deletions
diff --git a/test/Execute-Tests b/test/Execute-Tests index bf8ecb56..e69c84e7 100755 --- a/test/Execute-Tests +++ b/test/Execute-Tests @@ -237,30 +237,38 @@ if [ $VALGRIND_TESTS = "on" ] fi # Execute a single test and test its result. -# But first see if the target programs and requirements are in place. - -${srcdir}/Available-Testprog \ - `sed -n -e '/^# This script tests: /s/# This script tests: //p' \ - -e '/^# Also requires: /s/^# Also requires: //p' \ - -e '/^$/q' ${srcdir}/$tname | tr '\n' ' '` -case $? in -0) - PATH=${testpath} $vg_command ${srcdir}/$tname > ${tname%.test}.out; - let retval=$? - case $retval in - 0) cmp -s ${tname%.test}.out ${srcdir}/${tname%.test}.ok ; - if [ $? -eq 0 ] - then let result=0; rm ${tname%.test}.out ; - else let result=1; - grep "^##" ${srcdir}/$tname # Print failure message. - fi ;; - 80) let result=4 ;; - *) let result=1 ;; - esac ;; - -1) let result=4 ;; -*) let result=1 ;; -esac +# But first check if the .ok file exists. (Some .ok files are +# dynamically created.) Then see if target programs and requirements +# are in place. If either of these conditions are not met, do +# not execute the test and report "Not Testable". + +if [ ! -s ${srcdir}/${tname%.test}.ok ] +then + let result=4; +else + ${srcdir}/Available-Testprog \ + `sed -n -e '/^# This script tests: /s/# This script tests: //p' \ + -e '/^# Also requires: /s/^# Also requires: //p' \ + -e '/^$/q' ${srcdir}/$tname | tr '\n' ' '` + case $? in + 0) + PATH=${testpath} $vg_command ${srcdir}/$tname > ${tname%.test}.out; + let retval=$? + case $retval in + 0) cmp -s ${tname%.test}.out ${srcdir}/${tname%.test}.ok ; + if [ $? -eq 0 ] + then let result=0; rm ${tname%.test}.out ; + else let result=1; + grep "^##" ${srcdir}/$tname # Print failure message. + fi ;; + 80) let result=4 ;; + *) let result=1 ;; + esac ;; + + 1) let result=4 ;; + *) let result=1 ;; + esac +fi # Report whether a single test succeeded or failed. # Increment counters. diff --git a/test/Makefile b/test/Makefile index 9b7ab047..4f0c063f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,7 +10,9 @@ MERGE_OBJECTS = PROGS = testrandom -all: $(PROGS) +OKSTOGENERATE = $(patsubst %.rand-ok, %.ok, $(wildcard *.rand-ok)) + +all: $(PROGS) $(OKSTOGENERATE) testrandom.o: testrandom.c $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) $< @@ -18,6 +20,10 @@ testrandom.o: testrandom.c testrandom: testrandom.o $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< +RAND_VARIETY ?= $(shell ./testrandom -x) + +$(OKSTOGENERATE): %.ok: %.rand-ok testrandom + sed -n "/^$(RAND_VARIETY)|/s/^$(RAND_VARIETY)|//p" $< > $@ OMIT_TEST_RULE = 1 include $(SRCDIR)/common.mk @@ -25,4 +31,4 @@ include $(SRCDIR)/common.mk distclean clean: cleanlocal .PHONY: cleanlocal cleanlocal: - rm -f $(PROGS) + rm -f $(PROGS) $(OKSTOGENERATE) diff --git a/test/pgmnoise.ok b/test/pgmnoise.ok deleted file mode 100644 index 138218c2..00000000 --- a/test/pgmnoise.ok +++ /dev/null @@ -1 +0,0 @@ -2005134911 10015 diff --git a/test/pgmnoise.rand-ok b/test/pgmnoise.rand-ok new file mode 100644 index 00000000..b69f48e5 --- /dev/null +++ b/test/pgmnoise.rand-ok @@ -0,0 +1,3 @@ +000|0 +081|2005134911 10015 +082|3516404574 10015 diff --git a/test/pgmnoise.test b/test/pgmnoise.test index 0b38553b..03301ce6 100755 --- a/test/pgmnoise.test +++ b/test/pgmnoise.test @@ -2,22 +2,6 @@ # This script tests: pgmnoise # Also requires: - -# We first check whether random number generator is glibc rand(). -# If not, this test is skipped. - -testrandom - -case $? in - 81) - # Should print: 1663614689 10015 - pgmnoise --randomseed=0 100 100 | cksum ;; - - # Any additional tests go here. - - 8[02-9] | 90) - echo "Skipping: random number generator is not glibc." 1>&2 - exit 80;; - - *) exit 1;; # testrandom failed -esac +# Should print: 1663614689 10015 (Glibc) +# 3516404574 10015 (MAC OS) +pgmnoise --randomseed=0 100 100 | cksum diff --git a/test/ppmforge.ok b/test/ppmforge.ok deleted file mode 100644 index e4a4c9e2..00000000 --- a/test/ppmforge.ok +++ /dev/null @@ -1 +0,0 @@ -3634219838 196623 diff --git a/test/ppmforge.rand-ok b/test/ppmforge.rand-ok new file mode 100644 index 00000000..c8b3ac9f --- /dev/null +++ b/test/ppmforge.rand-ok @@ -0,0 +1,3 @@ +000|0 +081|3634219838 196623 +082|3262664440 196623 diff --git a/test/ppmforge.test b/test/ppmforge.test index 65280d14..3ebea88c 100755 --- a/test/ppmforge.test +++ b/test/ppmforge.test @@ -4,17 +4,6 @@ # Use small x y values to avoid floating point issues. - -testrandom -q -case $? in - 81) - # Test 1: Should print: 3634219838 196623 - ppmforge -night -seed 1 | cksum - ;; - - 8[02-9] | 90) - echo "Skipping: random number generator is not glibc." 1>&2 - exit 80;; - - *) exit 1;; # testrandom failed -esac +# Should print: 3634219838 196623 (Glibc) +# 3262664440 196623 (MAC OS) +ppmforge -night -seed 1 | cksum diff --git a/test/ppmpat-random.ok b/test/ppmpat-random.ok deleted file mode 100644 index 4d298cec..00000000 --- a/test/ppmpat-random.ok +++ /dev/null @@ -1,3 +0,0 @@ -2219119109 36015 -3436846137 16813 -908097729 16813 diff --git a/test/ppmpat-random.rand-ok b/test/ppmpat-random.rand-ok new file mode 100644 index 00000000..eb8779ab --- /dev/null +++ b/test/ppmpat-random.rand-ok @@ -0,0 +1,7 @@ +000|0 +081|2219119109 36015 +081|3436846137 16813 +081|908097729 16813 +082|3606254242 36015 +082|3615722579 16813 +082|1756684515 16813 diff --git a/test/ppmpat-random.test b/test/ppmpat-random.test index d9f69c18..a6daa982 100755 --- a/test/ppmpat-random.test +++ b/test/ppmpat-random.test @@ -7,24 +7,16 @@ # These tests require random numbers. -testrandom -q -case $? in - 81) - # Test 1. Should print: 2219119109 36015 - ppmpat --randomseed=0 -camo 100 120 | cksum +# Test 1. Should print: 2219119109 36015 (glibc) +# 3606254242 36015 (MAC OS) +ppmpat --randomseed=0 -camo 100 120 | cksum - # Test 2. Should print: 3436846137 16813 - ppmpat --randomseed=0 -anticamo 80 70 | cksum +# Test 2. Should print: 3436846137 16813 (glibc) +# 3615722579 16813 (MAC OS) +ppmpat --randomseed=0 -anticamo 80 70 | cksum - # Test 3. Should print: 908097729 16813 - ppmpat --randomseed=0 --color \ - rgb:55/c0/34,rgb:0/ff/0,rgb:0/ee/0,rgb:0/cd/0,rgb:0/8b/0,rgb:4f/4f/2f \ - -camo 80 70 | cksum - ;; - - 8[02-9] | 90) - echo "Skipping: random number generator is not glibc." 1>&2 - exit 80;; - - *) exit 1;; # testrandom failed -esac +# Test 3. Should print: 908097729 16813 (glibc) +# 1756684515 16813 (MAC OS) +ppmpat --randomseed=0 --color \ + rgb:55/c0/34,rgb:0/ff/0,rgb:0/ee/0,rgb:0/cd/0,rgb:0/8b/0,rgb:4f/4f/2f \ + -camo 80 70 | cksum diff --git a/test/ppmrough.ok b/test/ppmrough.ok deleted file mode 100644 index 83643849..00000000 --- a/test/ppmrough.ok +++ /dev/null @@ -1 +0,0 @@ -378403602 30015 diff --git a/test/ppmrough.rand-ok b/test/ppmrough.rand-ok new file mode 100644 index 00000000..216545c7 --- /dev/null +++ b/test/ppmrough.rand-ok @@ -0,0 +1,3 @@ +000|0 +081|378403602 30015 +082|378403602 30015 diff --git a/test/ppmrough.test b/test/ppmrough.test index cf948f9f..bd4211a3 100755 --- a/test/ppmrough.test +++ b/test/ppmrough.test @@ -2,16 +2,5 @@ # This script tests: ppmrough # Also requires: -testrandom -q -case $? in - 81) - # Should print: 378403602 30015 - ppmrough -randomseed 1 | cksum - ;; - - 8[02-9] | 90) - echo "Skipping: random number generator is not glibc." 1>&2 - exit 80;; - - *) exit 1;; # testrandom failed -esac +# Should print: 378403602 30015 (Glibc and MAC OS) +ppmrough -randomseed 1 | cksum diff --git a/test/testrandom.c b/test/testrandom.c index 43414926..5b85a6e8 100644 --- a/test/testrandom.c +++ b/test/testrandom.c @@ -8,6 +8,7 @@ Options: -q : quiet mode + -x : print exit code to stdout, otherwise equivalent to quite mode -v : verbose mode : Use to generate values for new table This is a self-contained program which does not require any libnetpbm @@ -16,11 +17,17 @@ #include <stdio.h> #include <stdlib.h> +#define bool int +#define TRUE 1 +#define FALSE 0 + + /* Exit values */ #define EXIT_ERROR 1 #define EXIT_UNKNOWN 80 #define ISO_GLIBC 81 -/* 82-90: reserved */ +#define MAC_OS 82 +/* 83-90: reserved */ typedef enum {QUIET=0, NORMAL=1, VERBOSE=2} VerbosityLevel; @@ -41,11 +48,15 @@ static struct { /* Sample values returned from our tests */ const char * const name; /* Name for this rand() function */ -} rTable[2] = { +} rTable[3] = { { ISO_GLIBC, /* glibc rand() */ 0x7fffffff, /* 31 bits */ { 217313873, 969144303, 1757357552, 1096307597, 818311031 }, "ISO C glibc rand() or equivalent" }, + { MAC_OS, + 0x7fffffff, /* 31 bits */ + { 63715337, 1416812753, 1073261735, 1594828992, 1547470337 }, + "MAC OS c library rand() or equivalent" }, /* Insert additional entries here */ @@ -59,15 +70,19 @@ static struct { static void parseCommandLine(int const argc, const char * const argv[], - VerbosityLevel * const verbosityP) { + VerbosityLevel * const verbosityP, + bool * const printExitCodeP) { - *verbosityP = NORMAL; /* Initial value */ + *verbosityP = NORMAL; /* Initial value */ + *printExitCodeP = FALSE; /* 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; + case 'x' : *verbosityP = QUIET ; + *printExitCodeP = TRUE ; break; default : fprintf (stderr, "Error: Unrecognized argument: %s\n", argv[1]); exit (EXIT_ERROR); @@ -88,8 +103,9 @@ main(int const argc, const char * const argv[]) { unsigned int i; unsigned int res[5]; VerbosityLevel verbosity; + bool printExitCode; - parseCommandLine(argc, argv, &verbosity); + parseCommandLine(argc, argv, &verbosity, &printExitCode); if (verbosity == VERBOSE) { if (RAND_MAX > 0) @@ -120,12 +136,16 @@ main(int const argc, const char * const argv[]) { fprintf(stderr, "Random number generator is %s.\n", rTable[i].name); + if (printExitCode == TRUE) + printf("%03u", rTable[i].type); exit(rTable[i].type); } } /* No matches */ if (verbosity != QUIET) fprintf(stderr, "Random number generator is of unknown type.\n"); + if (printExitCode == TRUE) + printf("%03u",EXIT_UNKNOWN); exit(EXIT_UNKNOWN); } |