summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-05-30 12:07:33 +0000
committerthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-05-30 12:07:33 +0000
commit0b55c596b46f71b6efe426728a0173b566f24970 (patch)
treea514def9770e2ac0c75c86f80f3e2517dbefcd1f /tests
parentcd15a7dfc9f31517c50d230b5c3c1b42c35bec98 (diff)
downloadmpc-0b55c596b46f71b6efe426728a0173b566f24970.tar.gz
Add random seed setting (with environmnent variable GMP_CHECK_RANDOMIZE) for
reproducible tests. git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@147 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/random.c102
-rw-r--r--tests/tadd.c6
-rw-r--r--tests/tcos.c6
-rw-r--r--tests/tcosh.c6
-rw-r--r--tests/tdiv.c12
-rw-r--r--tests/test.c7
-rw-r--r--tests/texp.c6
-rw-r--r--tests/tlog.c6
-rw-r--r--tests/tmul.c6
-rw-r--r--tests/tsin.c6
-rw-r--r--tests/tsinh.c6
-rw-r--r--tests/tsqr.c6
-rw-r--r--tests/tsqrt.c6
-rw-r--r--tests/tsub.c6
-rw-r--r--tests/ttan.c7
-rw-r--r--tests/ttanh.c6
17 files changed, 198 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ef6cd1..cd7b435 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ LDADD = $(top_builddir)/src/libmpc.la
AM_CPPFLAGS = -I$(top_srcdir)/src
check_PROGRAMS = tadd test tcos tcosh tdiv texp tlog tmul tsin tsinh tsqr \
tsqrt tsub ttan ttanh
+EXTRA_DIST = random.c
TESTS = $(check_PROGRAMS)
CLEANFILES = mpc_test
diff --git a/tests/random.c b/tests/random.c
new file mode 100644
index 0000000..90d32e2
--- /dev/null
+++ b/tests/random.c
@@ -0,0 +1,102 @@
+/* Handle seed for random numbers.
+
+Copyright (C) 2008 Philippe Th\'eveny.
+
+This file is part of the MPC Library.
+
+The MPC Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPC Library 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 Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPC Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+/* Put test_start at the beginning of your test function and
+ test_end at the end.
+ These are an adaptation of those of MPFR. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gmp.h"
+
+#include "config.h"
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+/* Use the global variables of MPFR since we are using mpfr_random2 through
+ mpc_random2. */
+extern gmp_randstate_t mpfr_rands;
+extern char mpfr_rands_initialized;
+
+void
+test_start ()
+{
+ char *environment_seed;
+ unsigned long seed;
+
+ if (mpfr_rands_initialized)
+ {
+ fprintf (stderr,
+ "Put test_start at the beginning of your test function.\n");
+ exit (1);
+ }
+
+ gmp_randinit_default (mpfr_rands);
+ mpfr_rands_initialized = 1;
+
+ environment_seed = getenv ("GMP_CHECK_RANDOMIZE");
+ if (environment_seed == NULL)
+ gmp_randseed_ui (mpfr_rands, 0xfac11e);
+ else
+ {
+ seed = atoi (environment_seed);
+ if (seed == 0 || seed == 1)
+ {
+#if HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ seed = tv.tv_sec + tv.tv_usec;
+#else
+ time_t tv;
+ time (&tv);
+ seed = tv;
+#endif
+ gmp_randseed_ui (mpfr_rands, seed);
+ printf ("Seed GMP_CHECK_RANDOMIZE=%lu "
+ "(include this in bug reports)\n", seed);
+ }
+ else
+ {
+ printf ("Re-seeding with GMP_CHECK_RANDOMIZE=%lu\n", seed);
+ gmp_randseed_ui (mpfr_rands, seed);
+ }
+ }
+}
+
+void
+test_end ()
+{
+ if (mpfr_rands_initialized)
+ {
+ mpfr_rands_initialized = 0;
+ gmp_randclear (mpfr_rands);
+ }
+}
diff --git a/tests/tadd.c b/tests/tadd.c
index 9c3f3b8..ade98b5 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -22,6 +22,8 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_add
#define TWOARGS
#include "tgeneric.c"
@@ -60,8 +62,12 @@ check_ternary_value ()
int
main()
{
+ test_start ();
+
check_ternary_value();
tgeneric ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tcos.c b/tests/tcos.c
index 16ce677..7fb57dc 100644
--- a/tests/tcos.c
+++ b/tests/tcos.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_cos
#include "tgeneric.c"
@@ -439,6 +441,8 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
@@ -447,5 +451,7 @@ main()
check_53 ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tcosh.c b/tests/tcosh.c
index 149abc3..28fb76f 100644
--- a/tests/tcosh.c
+++ b/tests/tcosh.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_cosh
#include "tgeneric.c"
@@ -642,6 +644,8 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
@@ -650,5 +654,7 @@ main()
check_53 ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tdiv.c b/tests/tdiv.c
index 213e4e7..49b4abf 100644
--- a/tests/tdiv.c
+++ b/tests/tdiv.c
@@ -26,6 +26,8 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
+
#define ERR(x) { mpc_out_str (stderr, 2, 0, x, MPC_RNDNN); \
fprintf (stderr, "\n"); }
@@ -235,6 +237,8 @@ main()
mp_rnd_t rnd_re, rnd_im;
mpc_rnd_t rnd;
+ test_start ();
+
mpc_init (b);
mpc_init (c);
mpc_init (q);
@@ -271,6 +275,8 @@ main()
for (prec = 2; prec < 1000; prec++)
{
+ const size_t s = 1 + (prec-1)/BITS_PER_MP_LIMB;
+
mpc_set_prec (b, prec);
mpc_set_prec (c, prec);
mpc_set_prec (q, prec);
@@ -278,11 +284,11 @@ main()
for (i = 0; i < (int) (1000/prec); i++)
{
- mpc_random (b);
+ mpc_random2 (b, s, 0);
/* generate a non-zero divisor */
do
{
- mpc_random (c);
+ mpc_random2 (c, s, 0);
}
while (mpfr_sgn (MPC_RE(c)) == 0 && mpfr_sgn (MPC_IM(c)) == 0);
@@ -318,5 +324,7 @@ main()
mpc_clear (q);
mpc_clear (q_ref);
+ test_end ();
+
return 0;
}
diff --git a/tests/test.c b/tests/test.c
index b17ccc0..35ce1e8 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -25,9 +25,12 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
#define PRINT(x) {}
+/* Crude tests for some functions. */
+/* TODO: use tgeneric instead and remove this. */
int
main()
{
@@ -38,6 +41,8 @@ main()
int nread;
const char *filename = "mpc_test";
+ test_start ();
+
mpc_init (x);
mpc_init2 (y, 2);
mpc_init3 (z, 2, 2);
@@ -217,5 +222,7 @@ main()
mpfr_clear (f);
mpfr_clear (g);
+ test_end ();
+
return 0;
}
diff --git a/tests/texp.c b/tests/texp.c
index 75ceb0b..a79e008 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_exp
#include "tgeneric.c"
@@ -35,6 +37,8 @@ main()
mpfr_t f, g;
mp_prec_t prec;
+ test_start ();
+
mpc_init (x);
mpc_init (z);
mpfr_init (f);
@@ -74,5 +78,7 @@ main()
mpfr_clear (f);
mpfr_clear (g);
+ test_end ();
+
return 0;
}
diff --git a/tests/tlog.c b/tests/tlog.c
index baebd1e..ff2a1a4 100644
--- a/tests/tlog.c
+++ b/tests/tlog.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_log
#include "tgeneric.c"
@@ -35,6 +37,8 @@ main()
mpfr_t twopi;
mp_prec_t prec;
+ test_start ();
+
tgeneric ();
mpc_init (z);
@@ -100,5 +104,7 @@ main()
mpc_clear (tmp);
mpfr_clear (twopi);
+ test_end ();
+
return 0;
}
diff --git a/tests/tmul.c b/tests/tmul.c
index 7f5b745..7909ae2 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -29,6 +29,8 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
+
void cmpmul (mpc_srcptr, mpc_srcptr, mpc_rnd_t);
void cmpmului (mpc_srcptr, unsigned long int, mpc_rnd_t);
void cmpmulsi (mpc_srcptr, long int, mpc_rnd_t);
@@ -409,6 +411,8 @@ main()
int i;
long int ysi;
+ test_start ();
+
#ifdef TIMING
timemul ();
#endif
@@ -456,5 +460,7 @@ main()
mpc_clear (x);
mpc_clear (y);
+ test_end ();
+
return 0;
}
diff --git a/tests/tsin.c b/tests/tsin.c
index 036edaa..48fd251 100644
--- a/tests/tsin.c
+++ b/tests/tsin.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_sin
#include "tgeneric.c"
@@ -517,6 +519,8 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
@@ -525,5 +529,7 @@ main()
check_53 ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tsinh.c b/tests/tsinh.c
index 85ac211..738a5b0 100644
--- a/tests/tsinh.c
+++ b/tests/tsinh.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_sinh
#include "tgeneric.c"
@@ -433,6 +435,8 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
@@ -441,5 +445,7 @@ main()
check_53 ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tsqr.c b/tests/tsqr.c
index 22d73a3..8c364c3 100644
--- a/tests/tsqr.c
+++ b/tests/tsqr.c
@@ -26,6 +26,8 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
+
void cmpsqr (mpc_srcptr, mpc_rnd_t);
void testsqr (long, long, mp_prec_t, mpc_rnd_t);
void special (void);
@@ -186,6 +188,8 @@ main()
mp_prec_t prec;
int i;
+ test_start ();
+
special ();
testsqr (247, -65, 8, 24);
@@ -216,5 +220,7 @@ main()
mpc_clear (x);
+ test_end ();
+
return 0;
}
diff --git a/tests/tsqrt.c b/tests/tsqrt.c
index 2c8c459..9e1fbbd 100644
--- a/tests/tsqrt.c
+++ b/tests/tsqrt.c
@@ -25,13 +25,19 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_sqrt
#include "tgeneric.c"
int
main()
{
+ test_start ();
+
tgeneric ();
+ test_end ();
+
return 0;
}
diff --git a/tests/tsub.c b/tests/tsub.c
index f300ad9..f16f5ee 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -22,6 +22,8 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_sub
#define TWOARGS
#include "tgeneric.c"
@@ -29,7 +31,11 @@ MA 02111-1307, USA. */
int
main()
{
+ test_start ();
+
tgeneric ();
+ test_end ();
+
return 0;
}
diff --git a/tests/ttan.c b/tests/ttan.c
index 2316cca..64e8f6b 100644
--- a/tests/ttan.c
+++ b/tests/ttan.c
@@ -26,6 +26,8 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_tan
#include "tgeneric.c"
@@ -531,13 +533,16 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
tgeneric ();
-
check_53 ();
+ test_end ();
+
return 0;
}
diff --git a/tests/ttanh.c b/tests/ttanh.c
index 177fc04..4e66971 100644
--- a/tests/ttanh.c
+++ b/tests/ttanh.c
@@ -25,6 +25,8 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "mpc.h"
+#include "random.c"
+
#define TEST_FUNCTION mpc_tanh
#include "tgeneric.c"
@@ -603,6 +605,8 @@ check_53()
int
main()
{
+ test_start ();
+
special ();
pure_real_argument ();
pure_imaginary_argument ();
@@ -611,5 +615,7 @@ main()
check_53 ();
+ test_end ();
+
return 0;
}