diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2012-06-27 14:48:23 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2012-06-27 14:48:23 +0000 |
commit | aab87b1ef2e39bbe57a97abec11a89f302668980 (patch) | |
tree | 84b03ae546c9a59eafcfc8625435c417bdfcfaf9 | |
parent | b8c9c0d2f6ab47cef882c45ed2667397eb11dfe9 (diff) | |
download | mpc-aab87b1ef2e39bbe57a97abec11a89f302668980.tar.gz |
Add more template functions (function result checked, parameter reuse not checkable yet).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/branches/benchs_tests@1195 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/check_data.c | 99 | ||||
-rw-r--r-- | tests/clear_parameters.c | 6 | ||||
-rw-r--r-- | tests/close_datafile.c | 28 | ||||
-rw-r--r-- | tests/copy_parameter.c | 33 | ||||
-rw-r--r-- | tests/data_check.tpl | 29 | ||||
-rw-r--r-- | tests/init_parameters.c | 15 | ||||
-rw-r--r-- | tests/print_parameter.c | 108 | ||||
-rw-r--r-- | tests/tadd_tmpl.c | 9 | ||||
-rw-r--r-- | tests/templates.h | 43 | ||||
-rw-r--r-- | tests/tpl_mpc.c (renamed from tests/tpl_read_mpc.c) | 3 | ||||
-rw-r--r-- | tests/tpl_mpfr.c (renamed from tests/tpl_read_mpfr.c) | 2 |
12 files changed, 316 insertions, 64 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 030f1ba..b36f129 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,8 +41,9 @@ check_PROGRAMS = tabs tacos tacosh tadd tadd_fr tadd_si tadd_ui targ \ check_LTLIBRARIES=libmpc-tests.la libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ comparisons.c templates.h check_data.c clear_parameters.c \ - init_parameters.c open_datafile.c read_description.c read_line.c \ - tpl_read_mpfr.c tpl_read_mpc.c + close_datafile.c copy_parameter.c init_parameters.c open_datafile.c \ + print_parameter.c read_description.c read_line.c tpl_mpc.c \ + tpl_mpfr.c TEMPLATES = data_check.tpl add.dsc add_fr.dsc add_si.dsc add_ui.dsc diff --git a/tests/check_data.c b/tests/check_data.c index 8f68f05..e8890d0 100644 --- a/tests/check_data.c +++ b/tests/check_data.c @@ -1,4 +1,4 @@ -/* check_data.c -- Check computed data against test data. +/* check_data.c -- Check computed data against reference result. Copyright (C) 2012 INRIA @@ -20,38 +20,46 @@ along with this program. If not, see http://www.gnu.org/licenses/ . #include "templates.h" -static void +#define MPC_INEX_CMP(r, i, c) \ + (((r) == TERNARY_NOT_CHECKED || (r) == MPC_INEX_RE(c)) \ + && ((i) == TERNARY_NOT_CHECKED || (i) == MPC_INEX_IM (c))) + +static int check_param (mpc_datafile_context_t* datafile_context, mpc_operand_t* got, mpc_operand_t* expected, mpc_param_t t) { switch (t) { - /* case NATIVE_INT: */ - /* break; */ -/* case NATIVE_UL: */ -/* break; */ -/* case NATIVE_L: */ -/* break; */ -/* case NATIVE_D: */ -/* break; */ - - /* TODO */ - /* case GMP_Z: */ - /* break; */ - /* case GMP_Q: */ - /* break; */ - /* case GMP_F: */ - /* break; */ - -/* case MPFR_INEX: */ -/* break; */ -/* case MPFR: */ -/* break; */ - -/* case MPC_INEX: */ -/* break; */ -/* case MPC: */ -/* break; */ + case NATIVE_INT: + return got->i == expected->i; + case NATIVE_UL: + return got->ui == expected->ui; + case NATIVE_L: + return got->si == expected->si; + case NATIVE_D: + return got->d == expected->d; + +#if 0 + case GMP_Z: + break; + case GMP_Q: + break; + case GMP_F: + break; + + case MPFR_INEX: + break; + case MPFR: + break; +#endif + + case MPC_INEX: + return MPC_INEX_CMP (expected->mpc_inex_check[0], + expected->mpc_inex_check[1], + got->mpc_inex); + + case MPC: + return same_mpc_value (got->mpc, expected->mpc, expected->known_signs); default: fprintf (stderr, "check_data: unsupported type.\n"); @@ -60,15 +68,40 @@ check_param (mpc_datafile_context_t* datafile_context, } void -check_data (mpc_datafile_context_t* datafile_context, - mpc_fun_param_t* params) +check_data (mpc_datafile_context_t* dc, mpc_fun_param_t* params) { - int out; + int out, i; int total = params->nbout + params->nbin; for (out = 0; out < params->nbout; out++) { - check_param (datafile_context, &(params->P[out]), - &(params->P[total + out]), params->T[out]); + if (!check_param (dc, &(params->P[out]), &(params->P[total + out]), + params->T[out])) + { + printf ("%s() failed (line %lu, file %s)\n", + params->name, dc->test_line_number, dc->pathname); + + for (i = 0; i < params->nbin; i++) + { + printf ("op%d", i + 1); + print_parameter (params, params->nbout + i); + } + + for (i = 0; i < params->nbout; i++) + { + if ((params->T[i] == MPFR_INEX && params->T[out] != MPFR_INEX) + || (params->T[i] == MPC_INEX && params->T[out] != MPC_INEX)) + continue; /* don't print inexact flag if it is correct */ + + printf (" got%c", + (total + i > params->nbout ? '\0' : i + '0')); + print_parameter (params, i); + printf ("expected%c", + (total + i > params->nbout ? '\0' : i + '0')); + print_parameter (params, total + i); + } + printf ("\n"); + exit (1); + } } } diff --git a/tests/clear_parameters.c b/tests/clear_parameters.c index d923a0f..f92ba76 100644 --- a/tests/clear_parameters.c +++ b/tests/clear_parameters.c @@ -54,6 +54,12 @@ clear_param (mpc_operand_t* p, mpc_param_t t) mpc_clear (p->mpc); break; + case MPFR_RND: + break; + + case MPC_RND: + break; + default: fprintf (stderr, "clear_parameters: unsupported type.\n"); exit (1); diff --git a/tests/close_datafile.c b/tests/close_datafile.c new file mode 100644 index 0000000..7959d39 --- /dev/null +++ b/tests/close_datafile.c @@ -0,0 +1,28 @@ +/* close_datafile.c -- Deallocate buffers and close datafile. + +Copyright (C) 2012 INRIA + +This file is part of GNU MPC. + +GNU MPC 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 3 of the License, or (at your +option) any later version. + +GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ . +*/ + +#include <templates.h> + +void +close_datafile (mpc_datafile_context_t *dc) +{ + free (dc->pathname); + fclose (dc->fd); +} diff --git a/tests/copy_parameter.c b/tests/copy_parameter.c new file mode 100644 index 0000000..44ca539 --- /dev/null +++ b/tests/copy_parameter.c @@ -0,0 +1,33 @@ +/* copy_parameter.c -- Helper function for parameter copy. + +Copyright (C) 2012 INRIA + +This file is part of GNU MPC. + +GNU MPC 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 3 of the License, or (at your +option) any later version. + +GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ . +*/ + +#include "templates.h" + +void +copy_parameter (mpc_fun_param_t *params, int index) +{ +#if 0 + if (params.T[1] != params.T[n]) + exit (1); + + switch (params.T[1]) + {} +#endif +} diff --git a/tests/data_check.tpl b/tests/data_check.tpl index 80e1a0f..61f19c6 100644 --- a/tests/data_check.tpl +++ b/tests/data_check.tpl @@ -1,9 +1,16 @@ -/* data_check.tpl -- template file for checking result against data +/* Data_check.tpl -- template file for checking result against data file. Usage: Before including this template file in your source file, - #define the prototype of the function under test in the CALL - symbol, see tadd_tmpl.c for an example. + #define the prototype of the function under test in the + CALL_MPC_FUNCTION symbol, see tadd_tmpl.c for an example. + + To test the reuse of the first parameter, #define the + MPC_FUNCTION_CALL_REUSE_OP1 and MPC_FUNCTION_CALL_REUSE_OP2 symbols + with the first and second input parameter reused as the output, see + tadd_tmpl.c for an example. It is not possible to test parameter + reuse in functions with two output (like mpc_sin_cos) with this + system. Copyright (C) 2012 INRIA @@ -40,12 +47,22 @@ data_check_template (const char* descr_file, const char * data_file) open_datafile (dc, data_file); while (datafile_context.nextchar != EOF) { read_line (dc, ¶ms); - MPC_FUNCTION_CALL; - check_data (dc, ¶ms); + +#ifdef MPC_FUNCTION_CALL_REUSE_OP1 + copy_parameter (¶ms, 2); + MPC_FUNCTION_CALL_REUSE_OP1; + check_data_reuse_op1 (dc, ¶ms); +#endif + +#ifdef MPC_FUNCTION_CALL_REUSE_OP2 + copy_parameter (¶ms, 3); + MPC_FUNCTION_CALL_REUSE_OP2; + check_data_reuse_op2 (dc, ¶ms); +#endif } -/* close_datafile (dc); */ + close_datafile (dc); clear_parameters (¶ms); diff --git a/tests/init_parameters.c b/tests/init_parameters.c index 507bd67..322b7de 100644 --- a/tests/init_parameters.c +++ b/tests/init_parameters.c @@ -18,6 +18,8 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/ . */ +#include <stdio.h> + #include "templates.h" static void @@ -26,11 +28,8 @@ init_param (mpc_operand_t* p, mpc_param_t t) switch (t) { case NATIVE_INT: - break; case NATIVE_UL: - break; case NATIVE_L: - break; case NATIVE_D: break; @@ -45,13 +44,19 @@ init_param (mpc_operand_t* p, mpc_param_t t) case MPFR_INEX: break; case MPFR: - mpfr_init2 (&(p->mpfr), 53); + mpfr_init2 (p->mpfr, 53); break; case MPC_INEX: break; case MPC: - mpc_init2 (&(p->mpc), 53); + mpc_init2 (p->mpc, 53); + break; + + case MPFR_RND: + break; + + case MPC_RND: break; default: diff --git a/tests/print_parameter.c b/tests/print_parameter.c new file mode 100644 index 0000000..c5a2b89 --- /dev/null +++ b/tests/print_parameter.c @@ -0,0 +1,108 @@ +/* print_parameter.c -- Helper function for parameter printing. + +Copyright (C) 2012 INRIA + +This file is part of GNU MPC. + +GNU MPC 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 3 of the License, or (at your +option) any later version. + +GNU MPC 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 this program. If not, see http://www.gnu.org/licenses/ . +*/ + +#include <stdio.h> + +#include "templates.h" + +static const char *mpfr_rnd_mode [] = + { "MPFR_RNDN", "MPFR_RNDZ", "MPFR_RNDU", "MPFR_RNDD" }; + +const char *rnd_mode[] = + { "MPC_RNDNN", "MPC_RNDZN", "MPC_RNDUN", "MPC_RNDDN", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", + "MPC_RNDNZ", "MPC_RNDZZ", "MPC_RNDUZ", "MPC_RNDDZ", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", + "MPC_RNDNU", "MPC_RNDZU", "MPC_RNDUU", "MPC_RNDDU", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", + "MPC_RNDND", "MPC_RNDZD", "MPC_RNDUD", "MPC_RNDDD", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", "undefined", "undefined", "undefined", + "undefined", "undefined", + }; + +#define MPFR_INEX_STR(inex) \ + (inex) == TERNARY_NOT_CHECKED ? "?" \ + : (inex) == +1 ? "+1" \ + : (inex) == -1 ? "-1" : "0" + +void +print_parameter (mpc_fun_param_t* params, int index) +{ + switch (params->T[index]) + { +#if 0 + case NATIVE_INT: + case NATIVE_UL: + case NATIVE_L: + case NATIVE_D: + break; + + case GMP_Z: + break; + case GMP_Q: + break; + case GMP_F: + break; + + case MPFR_INEX: + break; + case MPFR: + break; +#endif + + case MPC_INEX: + if (index >= params->nbout + params->nbin) + printf (" ternary value = (%s, %s)\n", + MPFR_INEX_STR (params->P[index].mpc_inex_check[0]), + MPFR_INEX_STR (params->P[index].mpc_inex_check[1])); + else + printf (" ternary value = %s\n", MPC_INEX_STR (params->P[index].mpc_inex)); + break; + + case MPC: + printf ("[%lu,%lu]=", + (unsigned long int) MPC_PREC_RE (params->P[index].mpc), + (unsigned long int) MPC_PREC_IM (params->P[index].mpc)); + mpc_out_str (stdout, 2, 0, params->P[index].mpc, MPC_RNDNN); + printf ("\n"); + break; + + case MPFR_RND: + printf ("(rounding mode): %s\n", + mpfr_rnd_mode[params->P[index].mpfr_rnd]); + break; + + case MPC_RND: + printf ("(rounding mode): %s\n", + rnd_mode[params->P[index].mpc_rnd]); + break; + + default: + fprintf (stderr, "print_parameter: unsupported type.\n"); + exit (1); + } +} diff --git a/tests/tadd_tmpl.c b/tests/tadd_tmpl.c index 0ed78f6..4d80041 100644 --- a/tests/tadd_tmpl.c +++ b/tests/tadd_tmpl.c @@ -1,6 +1,6 @@ /* tadd_tmpl.c -- templated test file for mpc_add. -Copyright (C) 2008, 2010, 2011 INRIA +Copyright (C) 2008, 2010, 2011, 2012 INRIA This file is part of GNU MPC. @@ -55,6 +55,13 @@ check_ternary_value (void) #define MPC_FUNCTION_CALL \ P[0].mpc_inex = mpc_add (P[1].mpc, P[2].mpc, P[3].mpc, P[4].mpc_rnd) +#if 0 +#define MPC_FUNCTION_CALL_REUSE_OP1 \ + P[0].mpc_inex = mpc_add (P[1].mpc, P[1].mpc, P[3].mpc, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_REUSE_OP2 \ + P[0].mpc_inex = mpc_add (P[1].mpc, P[2].mpc, P[1].mpc, P[4].mpc_rnd) +#endif + #include "data_check.tpl" int diff --git a/tests/templates.h b/tests/templates.h index babff5a..5805a10 100644 --- a/tests/templates.h +++ b/tests/templates.h @@ -99,25 +99,40 @@ typedef struct { int nextchar; } mpc_datafile_context_t; -void open_datafile (mpc_datafile_context_t* datafile_context, - const char * data_filename); -void tpl_read_int (mpc_datafile_context_t* datafile_context, int *nread, const char *name); -void tpl_skip_whitespace_comments (mpc_datafile_context_t* datafile_context); - -void tpl_read_ternary (mpc_datafile_context_t* datafile_context, int* ternary); -void tpl_read_mpfr (mpc_datafile_context_t* datafile_context, mpfr_ptr x, int *known_sign); -void tpl_read_mpfr_rnd (mpc_datafile_context_t* datafile_context, mpfr_rnd_t* rnd); -void tpl_read_mpfr_inex (mpc_datafile_context_t* datafile_context, int *nread); - -void tpl_read_mpc_inex (mpc_datafile_context_t* datafile_context, int *nread); -void tpl_read_mpc (mpc_datafile_context_t* datafile_context, mpc_ptr z, known_signs_t *ks); -void tpl_read_mpc_rnd (mpc_datafile_context_t* datafile_context, mpc_rnd_t* rnd); - +void open_datafile (mpc_datafile_context_t* datafile_context, + const char * data_filename); +void close_datafile (mpc_datafile_context_t *dc); void init_parameters (mpc_fun_param_t *params); void clear_parameters (mpc_fun_param_t *params); +void print_parameter (mpc_fun_param_t *params, int index); +void copy_parameter (mpc_fun_param_t *params, int index); void read_line (mpc_datafile_context_t* datafile_context, mpc_fun_param_t* params); void check_data (mpc_datafile_context_t* datafile_context, mpc_fun_param_t* params); +/* helper reading functions */ +void tpl_read_int (mpc_datafile_context_t* datafile_context, + int *nread, const char *name); +void tpl_skip_whitespace_comments (mpc_datafile_context_t* datafile_context); + +void tpl_read_ternary (mpc_datafile_context_t* datafile_context, + int* ternary); +void tpl_read_mpfr (mpc_datafile_context_t* datafile_context, + mpfr_ptr x, int *known_sign); +void tpl_read_mpfr_rnd (mpc_datafile_context_t* datafile_context, + mpfr_rnd_t* rnd); +void tpl_read_mpfr_inex (mpc_datafile_context_t* datafile_context, + int *nread); + +void tpl_read_mpc_inex (mpc_datafile_context_t* datafile_context, + int *nread); +void tpl_read_mpc (mpc_datafile_context_t* datafile_context, + mpc_ptr z, known_signs_t *ks); +void tpl_read_mpc_rnd (mpc_datafile_context_t* datafile_context, + mpc_rnd_t* rnd); + +/* helper comparison functions */ +void tpl_cmp_mpc (mpc_datafile_context_t* datafile_context, + mpc_fun_param_t* params); #endif /*__TEMPLATES_H*/ diff --git a/tests/tpl_read_mpc.c b/tests/tpl_mpc.c index 0d1038c..47c2c40 100644 --- a/tests/tpl_read_mpc.c +++ b/tests/tpl_mpc.c @@ -1,4 +1,4 @@ -/* tplread_mpc.c -- Read test mpc data in file. +/* tpl_mpc.c -- Helper functions for mpc data. Copyright (C) 2012 INRIA @@ -20,7 +20,6 @@ along with this program. If not, see http://www.gnu.org/licenses/ . #include "templates.h" - void tpl_read_mpc_rnd (mpc_datafile_context_t* datafile_context, mpc_rnd_t* rnd) { diff --git a/tests/tpl_read_mpfr.c b/tests/tpl_mpfr.c index 9874cf6..b064674 100644 --- a/tests/tpl_read_mpfr.c +++ b/tests/tpl_mpfr.c @@ -1,4 +1,4 @@ -/* tpl_read_mpfr.c -- Read test mpfr data in file. +/* tpl_mpfr.c -- Helper functions for mpfr data. Copyright (C) 2012 INRIA |