From: Ben Pfaff Date: Fri, 10 Aug 2007 04:49:58 +0000 (+0000) Subject: Fix bug #18982. Thanks to John Darrington for investigation, X-Git-Tag: v0.6.0~321 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf3da7e3a72705f3e9d0d09ba29039928dc64687;p=pspp-builds.git Fix bug #18982. Thanks to John Darrington for investigation, review, and verification of fix. * formats/date-in.sh: Use a portable pseudo-random number generator. * formats/time-in.sh: Ditto. --- diff --git a/tests/ChangeLog b/tests/ChangeLog index ef966a11..1776bfad 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,15 @@ +2007-08-09 Ben Pfaff + + Fix bug #18982. Thanks to John Darrington for investigation, + review, and verification of fix. + + * formats/date-in.sh: Use a portable pseudo-random number + generator. + + * formats/time-in.sh: Ditto. + + * formats/num-in.sh: Ditto. + 2007-08-03 Ben Pfaff * command/rank.sh: Test RANK with noncontiguous groups of SPLIT diff --git a/tests/formats/date-in.sh b/tests/formats/date-in.sh index e5314a39..67fe5799 100755 --- a/tests/formats/date-in.sh +++ b/tests/formats/date-in.sh @@ -38,6 +38,44 @@ pass() cd $TEMPDIR +activity="write PRNG fragment" +cat > my-rand.pl <<'EOF' +# This random number generator and the test for it below are drawn +# from Park and Miller, "Random Number Generators: Good Ones are Hard +# to Come By", Communications of the ACM 31:10 (October 1988). It is +# documented to function properly on systems with a 46-bit or longer +# real significand, which includes systems that have 64-bit IEEE reals +# (with 53-bit significand). The test should catch any systems for +# which this is not true, in any case. + +our ($seed) = 1; +sub my_rand { + my ($modulo) = @_; + my ($a) = 16807; + my ($m) = 2147483647; + my ($tmp) = $a * $seed; + $seed = $tmp - $m * int ($tmp / $m); + return $seed % $modulo; +} +EOF +if [ $? -ne 0 ] ; then no_result ; fi + +activity="write PRNG test program" +cat > test-my-rand.pl <<'EOF' +#! /usr/bin/perl +use strict; +use warnings; +do 'my-rand.pl'; +my_rand (1) foreach 1...10000; +our $seed; +die $seed if $seed != 1043618065; +EOF +if [ $? -ne 0 ] ; then no_result ; fi + +activity="test PRNG" +$PERL test-my-rand.pl +if [ $? -ne 0 ] ; then no_result ; fi + activity="write program to generate PSPP syntax and data" cat > date-in.pl <<'EOF' #! /usr/bin/perl @@ -45,7 +83,7 @@ cat > date-in.pl <<'EOF' use strict; use warnings; -our $next = 1; +do 'my-rand.pl'; my @formats = (['date', 'd-m-y'], ['adate', 'm-d-y'], @@ -207,12 +245,6 @@ sub maybe_print_space { sub pick { return $_[int (my_rand ($#_ + 1))]; } - -sub my_rand { - my ($modulo) = @_; - $next = ($next * 1103515245 + 12345) % (2**32); - return int ($next / 65536) % $modulo; -} EOF if [ $? -ne 0 ] ; then no_result ; fi @@ -646,9 +678,8 @@ diff -u datetime.out - < my-rand.pl <<'EOF' +# This random number generator and the test for it below are drawn +# from Park and Miller, "Random Number Generators: Good Ones are Hard +# to Come By", Communications of the ACM 31:10 (October 1988). It is +# documented to function properly on systems with a 46-bit or longer +# real significand, which includes systems that have 64-bit IEEE reals +# (with 53-bit significand). The test should catch any systems for +# which this is not true, in any case. + +our ($seed) = 1; +sub my_rand { + my ($modulo) = @_; + my ($a) = 16807; + my ($m) = 2147483647; + my ($tmp) = $a * $seed; + $seed = $tmp - $m * int ($tmp / $m); + return $seed % $modulo; +} +EOF +if [ $? -ne 0 ] ; then no_result ; fi + +activity="write PRNG test program" +cat > test-my-rand.pl <<'EOF' +#! /usr/bin/perl +use strict; +use warnings; +do 'my-rand.pl'; +my_rand (1) foreach 1...10000; +our $seed; +die $seed if $seed != 1043618065; +EOF +if [ $? -ne 0 ] ; then no_result ; fi + +activity="test PRNG" +$PERL test-my-rand.pl +if [ $? -ne 0 ] ; then no_result ; fi + activity="write program to generate PSPP syntax and data" cat > time-in.pl <<'EOF' #! /usr/bin/perl @@ -45,7 +83,7 @@ cat > time-in.pl <<'EOF' use strict; use warnings; -our $next = 1; +do 'my-rand.pl'; my @formats = (["time", "+H:M", "+H:M:S"], ["dtime", "+D H:M", "+D H:M:S"]); @@ -123,12 +161,6 @@ sub print_time_with_template { sub pick { return $_[int (my_rand ($#_ + 1))]; } - -sub my_rand { - my ($modulo) = @_; - $next = ($next * 1103515245 + 12345) % (2**32); - return int ($next / 65536) % $modulo; -} EOF if [ $? -ne 0 ] ; then no_result ; fi @@ -152,147 +184,147 @@ diff -u time.out - <