From b4236694e37bc97c677ab38bbc8006481d60c593 Mon Sep 17 00:00:00 2001
From: David Cleaver <wraithx@morpheus.net>
Date: Sat, 16 Jan 2016 05:38:23 +0000
Subject: [PATCH] updates to improve coverage

git-svn-id: svn://scm.gforge.inria.fr/svnroot/ecm/trunk@2752 404564d9-a503-0410-82bf-e18ce2cf3989
---
 Makefile.am  |  5 +++--
 dummy.save   |  2 ++
 test.ecm     | 45 ++++++++++++++++++++++++++++++++++++---------
 test.pm1     | 19 +++++++++++++++++--
 test.pp1     | 23 +++++++++++++++++++++--
 testlong.pm1 | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 126 insertions(+), 15 deletions(-)
 create mode 100644 testlong.pm1

diff --git a/Makefile.am b/Makefile.am
index 1925f033..20af7349 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -110,8 +110,8 @@ EXTRA_DIST = test.pm1 test.pp1 test.ecm README.lib INSTALL-ecm ecm.xml  \
              athlon/params.h x86/params.h ia64/params.h arm/params.h    \
              powerpc64/params.h powerpc32/params.h sparc64/params.h     \
              hppa/params.h mips/params.h x86_64/corei7/params.h         \
-             generic/params.h testlong.pp1 testlong.ecm M997.save M877.save \
-             dummy.save dummy2.save Z2102.n
+             generic/params.h testlong.pp1 testlong.pm1 testlong.ecm \
+             M997.save M877.save dummy.save dummy2.save Z2102.n
 
 DIST_SUBDIRS = athlon pentium4 x86_64 powerpc64 aprtcle
 
@@ -156,6 +156,7 @@ longcheck: ecm$(EXEEXT)
 	$(srcdir)/test.ecm "$(VALGRIND) ./ecm$(EXEEXT) -mpzmod"
 	$(srcdir)/test.ecm "$(VALGRIND) ./ecm$(EXEEXT) -treefile tree"
 	$(srcdir)/testlong.pp1 "$(VALGRIND) ./ecm$(EXEEXT)"
+	$(srcdir)/testlong.pm1 "$(VALGRIND) ./ecm$(EXEEXT)"
 	$(srcdir)/testlong.ecm "$(VALGRIND) ./ecm$(EXEEXT)"
 
 ## to be sure ecm.1 is considered as source
diff --git a/dummy.save b/dummy.save
index 1951732f..b9b78deb 100755
--- a/dummy.save
+++ b/dummy.save
@@ -1 +1,3 @@
 METHOD ECM; PARAM=0; SIGMA=585928442; B1=174000; N=17061648125571273329563156588435816942778260706938821014533; X=0x1a2a694df04a5c037fd12f42668b474f16b7818933f4c8484; CHECKSUM=1505596339; PROGRAM=GMP-ECM 7.0-dev; Y=0x0; X0=0x0; Y0=0x0; WHO=zimmerma@tarte; TIME=Tue Apr  7 11:00:55 2015;
+METHOD=ECM; PARAM=0; SIGMA=585928442; B1=174000; N=17061648125571273329563156588435816942778260706938821014533; X=0x1a2a694df04a5c037fd12f42668b474f16b7818933f4c8484; CHECKSUM=505596339; PROGRAM=GMP-ECM 7.0-dev; Y=0x0; X0=0x0; Y0=0x0; WHO=zimmerma@tarte; TIME=Tue Apr  7 11:00:55 2015;
+METHOD=ECM; PARAM=0; B1=174000; N=17061648125571273329563156588435816942778260706938821014533; X=0x1a2a694df04a5c037fd12f42668b474f16b7818933f4c8484; CHECKSUM=1505596339; PROGRAM=GMP-ECM 7.0-dev; Y=0x0; X0=0x0; Y0=0x0; WHO=zimmerma@tarte; TIME=Tue Apr  7 11:00:55 2015;
diff --git a/test.ecm b/test.ecm
index b4ed4330..5c1841aa 100755
--- a/test.ecm
+++ b/test.ecm
@@ -2,7 +2,7 @@
 
 # test file for ECM
 #
-# Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012
+# Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012, 2016
 # Jim Fougeron, Alexander Kruppa, Dave Newman, Paul Zimmermann, Cyril Bouvier,
 # David Cleaver.
 #
@@ -263,14 +263,10 @@ C=$?
 /bin/rm -f test.ecm.save
 checkcode $C 0
 
-$ECM -resume dummy.save 1e3
-C=$?
-checkcode $C 0
+$ECM -resume dummy.save 1e3; checkcode $C 0
 
 # test a Prime95 save file, includes lines to be skipped by GMP-ECM
-$ECM -resume prime95.save 1 2e6
-C=$?
-checkcode $C 6
+$ECM -resume prime95.save 1 2e6; checkcode $C 0
 
 echo 89101594496537524661600025466303491594098940711325290746374420963129505171895306244425914080753573576861992127359576789001 | $ECM -param 0 -sigma 877655087 -go 325001 157721 1032299; checkcode $? 14
 
@@ -306,7 +302,7 @@ echo 493671084022010320922697718944221569774262937898523672663031469122444419595
 
 echo "10090030271*10^400+696212088699" | $ECM -param 0 -sigma 3923937547 1e3 1e6; checkcode $? 14
 
-echo 31622776601683791911 | $ECM -param 0 11000
+echo 31622776601683791911 | $ECM -param 0 11000; checkcode $? 0
 
 # those tests with params=1, 2 or 3 don't work with -redc
 if [ "$MUL" != "redc" -a "$MUL" != "mpzmod" ]; then
@@ -316,7 +312,7 @@ echo 31622776601683791911 | $ECM 11000
 $ECM -printconfig | grep "GMP_NUMB_BITS = 64"
 if [ $? -eq 0 ]; then
 
-echo 31622776601683791911 | $ECM -param 1 11000
+echo 31622776601683791911 | $ECM -param 1 11000; checkcode $? 0
 
 echo 31622776601683791911 | $ECM -param 1 -A 27063318473587686303 11000
 checkcode $? 0
@@ -455,6 +451,8 @@ echo "2^1123-1" | $ECM -x0 1 -param -1 11000; checkcode $? 1
 echo "2^1123-1" | $ECM -sigma 1.2 11000; checkcode $? 1
 # exercise "Error, invalid A value" error message
 echo "2^1123-1" | $ECM -A 1.2 11000; checkcode $? 1
+# exercise "Error, -A requires a starting point (-x0 x)." error message
+echo "2^1123-1" | $ECM -A 1234567890 11e3; checkcode $? 1
 # exercise "Error, the -I f option requires f > 0" error message
 echo "2^1123-1" | $ECM -I -1 11000; checkcode $? 1
 # exercise "Can't find input file" error message
@@ -490,6 +488,9 @@ $ECM -inp Z2102.n -sigma 0:4702936202311981741 2000; checkcode $? 6
 # exercise -nobase2 option
 echo "2^1123-1" | $ECM -nobase2 -sigma 0:13488386679529262989 11000; checkcode $? 6
 
+# exercise -nobase2s2 option
+echo "2^1123-1" | $ECM -nobase2s2 -sigma 0:13488386679529262989 11000; checkcode $? 6
+
 # this example would fail with the old Fgw.c when using gwnum (fixed by David Cleaver, r1734)
 echo "((173^173+1)/174)/471462511391940575680645418941" | $ECM -param 0 -sigma 12345 20000
 checkcode $? 0
@@ -498,6 +499,32 @@ checkcode $? 0
 echo "((173^173+1)/174)/471462511391940575680645418941+122" | $ECM -param 0 -sigma 77 20000
 checkcode $? 6
 
+# exercise "Could not open file <file> for reading" error message
+$ECM -bloads sfile.txt 1e6 < c155; checkcode $? 1
+
+# exercise "read_s_from_file: 0 bytes read from <file>" error message
+$ECM -bloads dummy2.save 1e6 < c155; checkcode $? 1
+
+# exercise batch error messages...
+$ECM -bsaves test.ecm.s 11e3 < c155
+$ECM -bloads test.ecm.s 1000 < c155; checkcode $? 1
+$ECM -bloads test.ecm.s 10900 < c155; checkcode $? 1
+/bin/rm -f test.ecm.s
+
+# exercise "Error, -bsaves/-bloads makes sense in batch mode only" error message
+$ECM -bsaves test.s -param 0 11e3 < c155; checkcode $? 1
+
+# exercise "Error, invalid parametrization." error message
+$ECM -param 5-3 11e3 < c155; checkcode $? 1
+
+# exercise "mpmod_init_BASE2: n does not divide ..." error message
+$ECM -base2 32768 -param 0 11e3 < c155; checkcode $? 1
+
+echo 2050449353925555290706354283 | $ECM -param 0 -sigma 7 -go 2411 3; checkcode $? 0
+
+# excercise "Warning, invalid expression %s for the -go option" error message
+$ECM -go N- 11e3 < c155; checkcode $? 0
+
 ##### tests for the Weierstrass form
 # factored with Step 1
 echo 2432902008176640001 | $ECM -param 5 -A 1 -x0 20 -y0 10 100000; checkcode $? 14
diff --git a/test.pm1 b/test.pm1
index b91a9507..cf13d44e 100755
--- a/test.pm1
+++ b/test.pm1
@@ -2,8 +2,8 @@
 
 # test file for P-1 method
 #
-# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012
-# Paul Zimmermann, Alexander Kruppa, Dave Newman, Jim Fougeron.
+# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012, 2016
+# Paul Zimmermann, Alexander Kruppa, Dave Newman, Jim Fougeron, David Cleaver
 #
 # 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
@@ -127,6 +127,21 @@ echo "234^997+997^234" | $PM1 -ntt 100 324; checkcode $? 0
 # check go with 'N' placeholder
 echo "2^(2^12)+1" | $PM1 -go "N-1" 1e6; checkcode $? 2
 
+# excercise even number: factor 2 found in step 1
+echo 12345678 | $PM1 1e3
+
+# exercise "Error: cannot choose suitable P value for your stage 2 parameters." error message
+$PM1 -ntt 5e3 1e6-1e20 < c155; checkcode $? 1
+
+# exercise maxmem with p-1 code...
+$PM1 -v -v -v -ntt -maxmem 1 5e3 1e4-1e6 < c155; checkcode $? 0
+
+# exercise maxmem with p-1 code...
+$PM1 -v -v -v -no-ntt -maxmem 1 5e3 1e4-1e6 < c155; checkcode $? 0
+
+# exercise pm1prob with -go option
+$PM1 -v -go 1234 1e5 < c155; checkcode $? 0
+
 # check -v option
 echo 33852066257429811148979390609187539760850944806763555795340084882048986912482949506591909041130651770779842162499482875755533111808276172876211496409325473343590723224081353129229935527059488811457730702694849036693756201766866018562295004353153066430367 | $PM1 -v 19999; checkcode $? 0
 
diff --git a/test.pp1 b/test.pp1
index 704b3ed4..0db0012f 100755
--- a/test.pp1
+++ b/test.pp1
@@ -1,8 +1,9 @@
 #!/bin/sh
+
 # test file for P+1 method
 #
-# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2012 Jim Fougeron,
-# Alexander Kruppa, Dave Newman and Paul Zimmermann.
+# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2012, 2016
+# Paul Zimmermann, Alexander Kruppa, Dave Newman, Jim Fougeron, David Cleaver
 #
 # 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
@@ -144,6 +145,24 @@ echo 154618728587 | $PP1 -x0 3 -go 36 4294957296-4294967295 1; checkcode $? 8
 
 echo 18446744073709551337 | $PP1 -pp1 -x0 2 70823 714487; checkcode $? 8
 
+# exercise pp1fs2_memory_use with -no-ntt
+$PP1 -maxmem 1 -no-ntt 5e3 < c155; checkcode $? 0
+
+# exercise onepass pp1fs2_memory_use with -ntt
+$PP1 -maxmem 1 -ntt 5e3 < c155; checkcode $? 0
+
+# exercise even number factor found in step one
+echo 1234 | $PP1 5e3; checkcode $? 14
+
+# exercise "Using lmax = 512 with one pass NTT which takes about 0MB of memory" message
+$PP1 -maxmem 1 -ntt -v 5e3 < c155; checkcode $? 0
+
+# exercise "Using lmax = 436 without NTT which takes about 0MB of memory" message
+$PP1 -maxmem 1 -no-ntt -v 5e3 < c155; checkcode $? 0
+
+# exercise "Error: cannot choose suitable P value for your stage 2 parameters." error message
+$PP1 5e3 1e6-1e20 < c155; checkcode $? 1
+
 # check -v option
 echo 33852066257429811148979390609187539760850944806763555795340084882048986912482949506591909041130651770779842162499482875755533111808276172876211496409325473343590723224081353129229935527059488811457730702694849036693756201766866018562295004353153066430367 | $PP1 -v 1e5; checkcode $? 0
 
diff --git a/testlong.pm1 b/testlong.pm1
new file mode 100644
index 00000000..1876e1a1
--- /dev/null
+++ b/testlong.pm1
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# test file for P-1 method
+#
+# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012, 2016
+# Paul Zimmermann, Alexander Kruppa, Dave Newman, Jim Fougeron, David Cleaver
+#
+# 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; see the file COPYING.  If not, see
+# http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+PM1="$1 -pm1"
+
+# Call with "checkcode $? n" to check that return code is n
+# the return code is (see ecm-ecm.h):
+# 0: no factor found
+# 1: error (for example out of memory)
+# 2: composite factor found with composite cofactor
+# 6: prime factor found with composite cofactor
+# 8: input number found
+# 10: composite factor found with prime cofactor
+# 14: prime factor found with prime cofactor
+
+checkcode () {
+  if [ $1 != $2 ]
+  then
+    echo "############### ERROR ###############"
+    echo "Expected return code $2 but got $1"
+    exit 1
+  fi
+}
+
+
+# exercise gathering primes between cascade_limit < p < B0
+echo 123 | $PM1 4.42e8; checkcode $? 8
+
-- 
GitLab