summaryrefslogtreecommitdiffstats
path: root/tests/factor
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 16:58:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 16:58:41 +0000
commite1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe (patch)
treef5cc731bedcac0fb7fe14d952e4581e749f8bb87 /tests/factor
parentInitial commit. (diff)
downloadcoreutils-upstream.tar.xz
coreutils-upstream.zip
Adding upstream version 9.4.upstream/9.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/factor')
-rwxr-xr-xtests/factor/create-test.sh83
-rwxr-xr-xtests/factor/factor-parallel.sh34
-rwxr-xr-xtests/factor/factor.pl125
-rwxr-xr-xtests/factor/run.sh34
4 files changed, 276 insertions, 0 deletions
diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh
new file mode 100755
index 0000000..25885aa
--- /dev/null
+++ b/tests/factor/create-test.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+# Create the factor test scripts.
+
+# Copyright (C) 2012-2023 Free Software Foundation, Inc.
+
+test_name=$1
+template=$2
+
+# Extract the test name: remove .sh suffix from the basename.
+t=`echo "$test_name"|sed 's,.*/,,;s,\.sh$,,'`
+
+# prefix of 2^64
+p=184467440737
+
+# prefix of 2^96
+q=79228162514264337593543
+
+# Each of these numbers has a Pollard rho factor larger than 2^64,
+# and thus exercises some hard-to-reach code in factor.c.
+t1=170141183460469225450570946617781744489
+t2=170141183460469229545748130981302223887
+
+# Factors of the above:
+# t1: 9223372036854775421 18446744073709551709
+# t2: 9223372036854775643 18446744073709551709
+
+# Each test is a triple: lo, hi, sha1 of result.
+# The test script, run.sh, runs seq lo hi|factor|sha1sum
+# and verifies that the actual and expected checksums are the same.
+# New tests must be added to tests/local.mk (factor_tests), too.
+case $t in
+ t00) set 0 10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
+ t01) set 10000000 20000000 c792a2e02f1c8536b5121f624b04039d20187016 ;;
+ t02) set 20000000 30000000 8115e8dff97d1674134ec054598d939a2a5f6113 ;;
+ t03) set 30000000 40000000 fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
+ t04) set 40000000 50000000 b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
+ t05) set 50000000 60000000 a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
+ t06) set 60000000 70000000 689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
+ t07) set 70000000 80000000 d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
+ t08) set 80000000 90000000 7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
+ t09) set $t1 $t1 4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
+ t10) set $t2 $t2 dea308253708b57afad357e8c0d2a111460ef50e ;;
+ t11) set ${p}08551616 ${p}08651615 66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
+ t12) set ${p}08651616 ${p}08751615 729228e693b1a568ecc85b199927424c7d16d410 ;;
+ t13) set ${p}08751616 ${p}08851615 5a0c985017c2d285e4698f836f5a059e0b684563 ;;
+ t14) set ${p}08851616 ${p}08951615 0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
+ t15) set ${p}08951616 ${p}09051615 9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
+ t16) set ${p}09051616 ${p}09151615 604366d2b1d75371d0679e6a68962d66336cd383 ;;
+ t17) set ${p}09151616 ${p}09251615 9192d2bdee930135b28d7160e6d395a7027871da ;;
+ t18) set ${p}09251616 ${p}09351615 bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
+ t19) set ${p}09351616 ${p}09451615 16b106398749e5f24d278ba7c58229ae43f650ac ;;
+ t20) set ${p}09451616 ${p}09551615 ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
+ t21) set ${p}09551616 ${p}09651615 2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
+ t22) set ${p}09651616 ${p}09751615 54851acd51c4819beb666e26bc0100dc9adbc310 ;;
+ t23) set ${p}09751616 ${p}09851615 6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
+ t24) set ${p}09851616 ${p}09951615 0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
+ t25) set ${p}09951616 ${p}10051615 630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
+ t26) set ${q}940336 ${q}942335 63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
+ t27) set ${q}942336 ${q}944335 0d03d63653767173182491b86fa18f8f680bb036 ;;
+ t28) set ${q}944336 ${q}946335 ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
+ t29) set ${q}946336 ${q}948335 86d59545a0c13567fa96811821ea5cde950611b1 ;;
+ t30) set ${q}948336 ${q}950335 c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
+ t31) set ${q}950336 ${q}952335 551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
+ t32) set ${q}952336 ${q}954335 b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
+ t33) set ${q}954336 ${q}956335 8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
+ t34) set ${q}956336 ${q}958335 d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
+ t35) set ${q}958336 ${q}960335 2374919a89196e1fce93adfe779cb4664556d4b6 ;;
+ t36) set ${q}960336 ${q}962335 569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
+ *)
+ echo "$0: error: unknown test: '$test_name' -> '$t'" >&2
+ exit 1
+ ;;
+esac
+
+TEMPLATE="TEST SCRIPT DERIVED FROM THE TEMPLATE $template"
+
+# Create the test script from the template for this test
+# by substituting the START, the END and the CKSUM.
+exec sed \
+ -e "s/__START__/$1/" \
+ -e "s/__END__/$2/" \
+ -e "s/__CKSUM__/$3/" \
+ -e "s!__TEMPLATE__!$TEMPLATE!" "$template"
diff --git a/tests/factor/factor-parallel.sh b/tests/factor/factor-parallel.sh
new file mode 100755
index 0000000..9a3d62a
--- /dev/null
+++ b/tests/factor/factor-parallel.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Test for complete lines on output
+
+# Copyright (C) 2015-2023 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ factor
+
+
+odd() { LC_ALL=C sed '/[24680]$/d'; }
+primes() { LC_ALL=C sed 's/.*: //; / /d'; }
+
+# Before v8.24 the number reported here would vary
+# Note -u not supplied to split, increased batching of quickly processed items.
+# As processing cost increases it becomes advantageous to use -u to keep
+# the factor processes supplied with data.
+nprimes=$(seq 1e6 | odd | split -nr/4 --filter='factor' | primes | wc -l)
+
+test "$nprimes" = '78498' || fail=1
+
+Exit $fail
diff --git a/tests/factor/factor.pl b/tests/factor/factor.pl
new file mode 100755
index 0000000..6e612e4
--- /dev/null
+++ b/tests/factor/factor.pl
@@ -0,0 +1,125 @@
+#!/usr/bin/perl
+# Basic tests for "factor".
+
+# Copyright (C) 1998-2023 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+
+(my $program_name = $0) =~ s|.*/||;
+my $prog = 'factor';
+
+# Turn off localization of executable's output.
+@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+
+my @Tests =
+ (
+ ['1', '9', {OUT => '3 3'}],
+ ['1a', '7', {OUT => '7'}],
+ ['1b', ' +7', {OUT => '7'}],
+ ['2', '4294967291', {OUT => '4294967291'}],
+ ['3', '4294967292', {OUT => '2 2 3 3 7 11 31 151 331'}],
+ ['4', '4294967293', {OUT => '9241 464773'}],
+
+ ['a', '4294966201', {OUT => '12197 352133'}],
+ ['b', '4294966339', {OUT => '13187 325697'}],
+ ['c', '4294966631', {OUT => '13729 312839'}],
+ ['d', '4294966457', {OUT => '14891 288427'}],
+ ['e', '4294966759', {OUT => '21649 198391'}],
+ ['f', '4294966573', {OUT => '23071 186163'}],
+ ['g', '4294967101', {OUT => '23603 181967'}],
+ ['h', '4294966519', {OUT => '34583 124193'}],
+ ['i', '4294966561', {OUT => '36067 119083'}],
+ ['j', '4294966901', {OUT => '37747 113783'}],
+ ['k', '4294966691', {OUT => '39241 109451'}],
+ ['l', '4294966969', {OUT => '44201 97169'}],
+ ['m', '4294967099', {OUT => '44483 96553'}],
+ ['n', '4294966271', {OUT => '44617 96263'}],
+ ['o', '4294966789', {OUT => '50411 85199'}],
+ ['p', '4294966189', {OUT => '53197 80737'}],
+ ['q', '4294967213', {OUT => '57139 75167'}],
+ ['s', '4294967071', {OUT => '65521 65551'}],
+ ['t', '4294966194', {OUT => '2 3 3 3 3 3 3 3 53 97 191'}],
+ ['u', '4294966272', {OUT => '2 2 2 2 2 2 2 2 2 2 3 23 89 683'}],
+ ['v', '4294966400', {OUT => '2 2 2 2 2 2 2 5 5 1342177'}],
+ ['w', '4294966464', {OUT => '2 2 2 2 2 2 3 3 3 2485513'}],
+ ['x', '4294966896', {OUT => '2 2 2 2 3 3 3 11 607 1489'}],
+ ['y', '4294966998', {OUT => '2 3 7 3917 26107'}],
+ ['z', '-1',
+ # Map newer glibc diagnostic to expected.
+ # Also map OpenBSD 5.1's "unknown option" to expected "invalid option".
+ {ERR_SUBST => q!s/'1'/1/;s/unknown/invalid/!},
+ {ERR => "$prog: invalid option -- 1\n"
+ . "Try '$prog --help' for more information.\n"},
+ {EXIT => 1}],
+ ['cont', 'a 4',
+ {OUT => "4: 2 2\n"},
+ {ERR => "$prog: 'a' is not a valid positive integer\n"},
+ {EXIT => 1}],
+ ['bug-2012-a', '465658903', {OUT => '15259 30517'}],
+ ['bug-2012-b', '2242724851', {OUT => '33487 66973'}],
+ ['bug-2012-c', '6635692801', {OUT => '57601 115201'}],
+ ['bug-2012-d', '17709149503', {OUT => '94099 188197'}],
+ ['bug-2012-e', '17754345703', {OUT => '94219 188437'}],
+ # Infinite loop bugs in v8.20 to 8.26 inclusive
+ ['bug-2016-a', '158909489063877810457',
+ {OUT => '3401347 3861211 12099721'}],
+ ['bug-2016-b', '222087527029934481871',
+ {OUT => '15601 26449 111427 4830277'}],
+ ['bug-2016-c', '12847291069740315094892340035',
+ {OUT => '5 4073 18899 522591721 63874247821'}],
+ ['bug-gmp-2_sup_128', '340282366920938463463374607431768211456',
+ {OUT => '2 'x127 . '2'}],
+ ['bug-gmp-2_sup_256',
+ '115792089237316195423570985008687907853'
+ . '269984665640564039457584007913129639936',
+ {OUT => '2 'x255 . '2'}],
+ ['bug-gmp-plus_2_sup_128_plus_1',
+ '+170141183460469231731687303715884105729',
+ {OUT => '3 56713727820156410577229101238628035243'}],
+ ['h-1', '-h 3000', {OUT => '2^3 3 5^3'}],
+ ['h-2', '3000 --exponents', {OUT => '2^3 3 5^3'}],
+ );
+
+
+# Prepend the command line argument and append a newline to end
+# of each expected 'OUT' string.
+my $t;
+
+Test:
+foreach $t (@Tests)
+ {
+ (my $arg1 = $t->[1]) =~ s| *\+?||; # strip '+'
+ (my $arg1 = $arg1) =~ s| *-[^ ]+ *||; # strip option
+
+ # Don't fiddle with expected OUT string if there's a nonzero exit status.
+ foreach my $e (@$t)
+ {
+ ref $e eq 'HASH' && exists $e->{EXIT} && $e->{EXIT}
+ and next Test;
+ }
+
+ foreach my $e (@$t)
+ {
+ ref $e eq 'HASH' && exists $e->{OUT}
+ and $e->{OUT} = "$arg1: $e->{OUT}\n"
+ }
+ }
+
+my $save_temps = $ENV{SAVE_TEMPS};
+my $verbose = $ENV{VERBOSE};
+
+my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
+exit $fail;
diff --git a/tests/factor/run.sh b/tests/factor/run.sh
new file mode 100755
index 0000000..1f9be3d
--- /dev/null
+++ b/tests/factor/run.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# === THIS IS A __TEMPLATE__ ===
+
+# Test the factor rewrite.
+# The test is to run this command
+# seq $START $END | factor | shasum -c --status <(echo $CKSUM -)
+# I.e., to ensure that the factorizations of integers $1..$2
+# match what we expect.
+#
+# See: tests/factor/create-test.sh
+
+# Copyright (C) 2012-2023 Free Software Foundation, Inc.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+
+# Don't run these tests by default.
+very_expensive_
+
+print_ver_ factor seq sha1sum
+
+# Template variables.
+START=__START__
+ END=__END__
+CKSUM=__CKSUM__
+
+test "$START" = '__ST''ART__' && skip_ 'ignoring factor test template'
+
+echo "$CKSUM -" > exp
+
+f=1
+seq $START $END | factor | sha1sum -c --status exp && f=0
+
+Exit $f