From 8c46a4c67e321801d99078a7fb22af6a20e4aa7b Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 30 Dec 2017 20:35:00 +0000 Subject: Copy Development as new Advanced git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3104 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- test/Execute-Tests | 56 +++++++++++++++++++++++++------------------- test/Makefile | 10 ++++++-- test/fiasco-roundtrip.ok | 2 +- test/fiasco-roundtrip.test | 7 ++++-- test/jpeg-roundtrip.ok | 6 ++--- test/jpeg-roundtrip.test | 17 +++++++++++--- test/jpeg2k-roundtrip.test | 2 +- test/palm-roundtrip.ok | 9 ++++--- test/palm-roundtrip.test | 9 ++++--- test/pamtopdbimg.test | 17 ++++++++++---- test/pgmnoise.rand-ok | 3 +++ test/pgmnoise.test | 22 +++-------------- test/ppmforge.rand-ok | 3 +++ test/ppmforge.test | 17 +++----------- test/ppmpat-random.rand-ok | 7 ++++++ test/ppmpat-random.test | 30 +++++++++--------------- test/ppmrough.rand-ok | 3 +++ test/ppmrough.test | 15 ++---------- test/testrandom.c | 30 ++++++++++++++++++++---- test/tiffcmyk-roundtrip.ok | 10 ++++---- test/tiffcmyk-roundtrip.test | 25 ++++++++++++++++---- 21 files changed, 172 insertions(+), 128 deletions(-) create mode 100644 test/pgmnoise.rand-ok create mode 100644 test/ppmforge.rand-ok create mode 100644 test/ppmpat-random.rand-ok create mode 100644 test/ppmrough.rand-ok (limited to 'test') 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/fiasco-roundtrip.ok b/test/fiasco-roundtrip.ok index 8a5e8ff6..544093d3 100644 --- a/test/fiasco-roundtrip.ok +++ b/test/fiasco-roundtrip.ok @@ -1 +1 @@ - 3 1 1 1 \ No newline at end of file + 3 1000.00 1000.00 1000.00 \ No newline at end of file diff --git a/test/fiasco-roundtrip.test b/test/fiasco-roundtrip.test index 6fd43432..8325a37d 100755 --- a/test/fiasco-roundtrip.test +++ b/test/fiasco-roundtrip.test @@ -7,7 +7,7 @@ # TODO: As in jpeg-rountrip.test the threshold has been determined # without much thought. -# Should print 3 1 1 1 +# Should print 3 1000.00 1000.00 1000.00 tmpdir=${tmpdir:-/tmp} padded_ppm=${tmpdir}/padded.ppm @@ -15,6 +15,9 @@ padded_ppm=${tmpdir}/padded.ppm pnmpad --black --bottom 1 --left 1 testimg.ppm > ${padded_ppm} && pnmtofiasco --progress-meter 0 ${padded_ppm} | fiascotopnm | \ pnmpsnr -machine - ${padded_ppm} | \ - awk '{printf("%3d %1d %1d %1d",NF,$1>14.0,$2>21.0,$3>$29.0)}' + awk '{printf("%3d %.2f %.2f %.2f", NF, + $1>14.0 ? 1000.00 : $1, + $2>21.0 ? 1000.00 : $2, + $3>29.0 ? 1000.00 : $3) }' rm ${padded_ppm} \ No newline at end of file diff --git a/test/jpeg-roundtrip.ok b/test/jpeg-roundtrip.ok index f32c58a2..9a93f216 100644 --- a/test/jpeg-roundtrip.ok +++ b/test/jpeg-roundtrip.ok @@ -1,3 +1,3 @@ - 3 1 1 1 - 3 1 1 1 - 3 1 1 1 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 diff --git a/test/jpeg-roundtrip.test b/test/jpeg-roundtrip.test index 1afc5423..23df6341 100755 --- a/test/jpeg-roundtrip.test +++ b/test/jpeg-roundtrip.test @@ -10,12 +10,23 @@ pnmtojpeg testimg.ppm | jpegtopnm | \ pnmpsnr -machine - testimg.ppm |\ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>55.0,$2>57.0,$3>48.0)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>55.0 ? 1000.00 : $1, + $2>57.0 ? 1000.00 : $2, + $3>48.0 ? 1000.00 : $3) }' + pnmtojpeg testimg.ppm -opt | jpegtopnm | \ pnmpsnr -machine - testimg.ppm |\ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>55.0,$2>57.0,$3>48.0)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>55.0 ? 1000.00 : $1, + $2>57.0 ? 1000.00 : $2, + $3>48.0 ? 1000.00 : $3) }' + pnmtojpeg testimg.ppm -progressive | jpegtopnm | \ pnmpsnr -machine - testimg.ppm |\ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>55.0,$2>57.0,$3>48.0)}' \ No newline at end of file + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>55.0 ? 1000.00 : $1, + $2>57.0 ? 1000.00 : $2, + $3>48.0 ? 1000.00 : $3) }' diff --git a/test/jpeg2k-roundtrip.test b/test/jpeg2k-roundtrip.test index eab6fb1e..0995849d 100755 --- a/test/jpeg2k-roundtrip.test +++ b/test/jpeg2k-roundtrip.test @@ -1,6 +1,6 @@ #! /bin/bash # This script tests: pamtojpeg2k jpeg2ktopam -# Also requires: pnmpsnr +# Also requires: # Should produce 1926073387 101484 diff --git a/test/palm-roundtrip.ok b/test/palm-roundtrip.ok index 6c9114a4..5bd3cb0a 100644 --- a/test/palm-roundtrip.ok +++ b/test/palm-roundtrip.ok @@ -3,8 +3,7 @@ 584219238 236 584219238 236 584219238 236 -600373046 101484 -600373046 101484 -600373046 101484 -600373046 101484 -600373046 101484 +0 +0 +0 +0 diff --git a/test/palm-roundtrip.test b/test/palm-roundtrip.test index 5570e968..9c053ba9 100755 --- a/test/palm-roundtrip.test +++ b/test/palm-roundtrip.test @@ -19,14 +19,17 @@ for flags in "" \ rm ${test4bit_pgm} -# Test 2. Should print 600373046 101484 5 times +# Test 2. Should print 0 4 times -pnmquant 256 testimg.ppm | tee ${test256color_ppm} | cksum +pnmquant 256 testimg.ppm > ${test256color_ppm} for flags in "" \ "-scanline_compression" \ "-rle_compression" \ "-packbits_compression" - do pnmtopalm -colormap $flags ${test256color_ppm} | palmtopnm | cksum; done + do pnmtopalm -colormap $flags ${test256color_ppm} | palmtopnm | \ + cmp -s - ${test256color_ppm} > /dev/null + echo $? + done rm ${test256color_ppm} diff --git a/test/pamtopdbimg.test b/test/pamtopdbimg.test index 267f6bc8..8de78a70 100755 --- a/test/pamtopdbimg.test +++ b/test/pamtopdbimg.test @@ -48,14 +48,20 @@ rm ${noise_pgm} # 0 # 1 # 0 + +# Some versions of wc have extra whitespace in the output (e.g. MAC OS) +# Delete with tr -d + echo long titles for flag in "" "-title=0123456789012345678901234567890" \ "-title=01234567890123456789012345678901" do - pamtopdbimg $flag testgrid.pbm | wc -c ; echo ${PIPESTATUS[0]} + pamtopdbimg $flag testgrid.pbm | wc -c | tr -d ' ' + echo ${PIPESTATUS[0]} done + # Test 4. large notefile # Should succeed twice and fail once, producing: # 3344 @@ -76,11 +82,14 @@ awk 'BEGIN { ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; head -c 65533 ${text65597} > ${text65533} head -c 65534 ${text65597} > ${text65534} -pamtopdbimg -uncompressed testgrid.pbm | wc -c +pamtopdbimg -uncompressed testgrid.pbm | \ + wc -c | tr -d ' ' echo ${PIPESTATUS[0]} -pamtopdbimg -uncompressed -notefile=${text65533} testgrid.pbm | wc -c +pamtopdbimg -uncompressed -notefile=${text65533} testgrid.pbm | \ + wc -c | tr -d ' ' echo ${PIPESTATUS[0]} -pamtopdbimg -uncompressed -notefile=${text65534} testgrid.pbm | wc -c +pamtopdbimg -uncompressed -notefile=${text65534} testgrid.pbm | \ + wc -c | tr -d ' ' echo ${PIPESTATUS[0]} rm ${text65533} ${text65534} ${text65597} \ No newline at end of file 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.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.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.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 #include +#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); } diff --git a/test/tiffcmyk-roundtrip.ok b/test/tiffcmyk-roundtrip.ok index e152d0a7..5f4963cd 100644 --- a/test/tiffcmyk-roundtrip.ok +++ b/test/tiffcmyk-roundtrip.ok @@ -1,5 +1,5 @@ - 3 1 1 1 - 3 1 1 1 - 3 1 1 1 - 3 1 1 1 - 3 1 1 1 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 + 3 1000.00 1000.00 1000.00 diff --git a/test/tiffcmyk-roundtrip.test b/test/tiffcmyk-roundtrip.test index e123d807..99e02c48 100755 --- a/test/tiffcmyk-roundtrip.test +++ b/test/tiffcmyk-roundtrip.test @@ -16,31 +16,46 @@ output_tiff=${tmpdir}/output.tiff pnmtotiffcmyk testimg.ppm > ${output_tiff} && \ tifftopnm -headerdump -byrow ${output_tiff} | \ pnmpsnr -machine - testimg.ppm | \ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>45.0,$2>59.5,$3>56.5)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>45.0 ? 1000.00 : $1, + $2>59.5 ? 1000.00 : $2, + $3>56.5 ? 1000.00 : $3) }' # Note that "-rowsperstrip=1" does not work pnmtotiffcmyk -rowsperstrip 1 -lsb2msb testimg.ppm > ${output_tiff} && \ tifftopnm -respectfillorder -byrow ${output_tiff} | \ pnmpsnr -machine - testimg.ppm | \ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>45.0,$2>59.5,$3>56.5)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>45.0 ? 1000.00 : $1, + $2>59.5 ? 1000.00 : $2, + $3>56.5 ? 1000.00 : $3) }' pnmtotiffcmyk -packbits testimg.ppm > ${output_tiff} && \ tifftopnm -byrow ${output_tiff} | \ pnmpsnr -machine - testimg.ppm | \ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>45.0,$2>59.5,$3>56.5)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>45.0 ? 1000.00 : $1, + $2>59.5 ? 1000.00 : $2, + $3>56.5 ? 1000.00 : $3) }' pnmtotiffcmyk -lzw testimg.ppm > ${output_tiff} && \ tifftopnm -byrow ${output_tiff} | \ pnmpsnr -machine - testimg.ppm | \ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>45.0,$2>59.5,$3>56.5)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>45.0 ? 1000.00 : $1, + $2>59.5 ? 1000.00 : $2, + $3>56.5 ? 1000.00 : $3) }' pnmtotiffcmyk -lzw -predictor 2 testimg.ppm > ${output_tiff} && \ tifftopnm -respectfillorder -byrow ${output_tiff} | \ pnmpsnr -machine - testimg.ppm | \ - awk '{printf("%3d %1d %1d %1d\n",NF,$1>45.0,$2>59.5,$3>56.5)}' + awk '{printf("%3d %.2f %.2f %.2f\n", NF, + $1>45.0 ? 1000.00 : $1, + $2>59.5 ? 1000.00 : $2, + $3>56.5 ? 1000.00 : $3) }' rm ${output_tiff} \ No newline at end of file -- cgit 1.4.1