Skip to content

Commit

Permalink
Merge pull request flintlib#1714 from albinahlback/prettify_tests
Browse files Browse the repository at this point in the history
Prettify printing of tests
  • Loading branch information
albinahlback authored Jan 14, 2024
2 parents 377ba83 + 6c312d6 commit 473413d
Show file tree
Hide file tree
Showing 64 changed files with 1,655 additions and 2,044 deletions.
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ yes|no)
esac],
enable_dependency_tracking="yes")

AC_ARG_ENABLE(pretty-tests,
[AS_HELP_STRING([--enable-pretty-tests],[Enable pretty printing for tests [default=yes]])],
[case $enableval in
yes|no)
;;
*)
AC_MSG_ERROR([Bad value $enableval for --enable-pretty-tests. Need yes or no.])
;;
esac],
enable_pretty_tests="yes")

AC_ARG_ENABLE(gmp-internals,
[AS_HELP_STRING([--enable-gmp-internals],[Enable calling GMP internals directly [default=yes]])],
[case $enableval in
Expand Down Expand Up @@ -1254,6 +1265,11 @@ else
AC_SUBST(WANT_DEPS,0)
fi
if test "$enable_pretty_tests" = "yes";
then
AC_DEFINE(FLINT_WANT_PRETTY_TESTS,1,[Define to enable pretty printing for tests.])
fi
if test "$with_ntl" = "yes";
then
AC_SUBST(WANT_NTL,1)
Expand Down
2 changes: 2 additions & 0 deletions src/flint.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ typedef struct __FLINT_FILE FLINT_FILE;
#endif

#if defined(_LONG_LONG_LIMB)
# define _WORD_FMT "ll"
# define WORD_FMT "%ll"
# define WORD_WIDTH_FMT "%*ll"
# define WORD(xx) (xx##LL)
Expand All @@ -171,6 +172,7 @@ typedef struct __FLINT_FILE FLINT_FILE;
# define WORD_MIN LLONG_MIN
# endif
#else
# define _WORD_FMT "l"
# define WORD_FMT "%l"
# define WORD_WIDTH_FMT "%*l"
# define WORD(xx) (xx##L)
Expand Down
2 changes: 2 additions & 0 deletions src/fmpq_poly/test/t-print_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TEST_FUNCTION_START(fmpq_poly_print_read, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n polynomials, write to and read from a pipe */
{
fmpq_poly_t *a;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz/test/t-out_inp_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TEST_FUNCTION_START(fmpz_out_inp_raw, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n integers, write to and read from a pipe */
{
fmpz *a;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz/test/t-print_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TEST_FUNCTION_START(fmpz_print_read, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n integers, write to and read from a pipe */
{
fmpz *a;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_mat/test/t-print_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TEST_FUNCTION_START(fmpz_mat_print_read, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise k mats, write to and read from a pipe */
{
fmpz_mat_t *M;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_mod_poly/test/t-print_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ TEST_FUNCTION_START(fmpz_mod_poly_print_read, state)

fmpz_mod_ctx_init_ui(ctx, 2);

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n polynomials, write to and read from a pipe */
{
fmpz_mod_poly_t *a;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_poly/test/t-print_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TEST_FUNCTION_START(fmpz_poly_print_read, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n polynomials, write to and read from a pipe */
{
fmpz_poly_t *a;
Expand Down
2 changes: 2 additions & 0 deletions src/fmpz_poly/test/t-print_read_pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TEST_FUNCTION_START(fmpz_poly_print_read_pretty, state)
int fd[2];
pid_t childpid;

fflush(stdout); /* Ensure buffer does not flow into child process */

/* Randomise n polynomials, write to and read from a pipe */
{
fmpz_poly_t *a;
Expand Down
11 changes: 4 additions & 7 deletions src/test/t-add_ssaaaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ TEST_FUNCTION_START(add_ssaaaa, state)

result = ((sh2 == sh1) && (sl2 == sl1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("ah1 = %wu, al1 = %wu, ah2 = %wu, al1 = %wu\n", ah1, al1, ah2, al1);
flint_printf("sh2 = %wu, sh1 = %wu, sl2 = %wu, sl1 = %wu\n", sh2, sh1, sl2, sl1);
fflush(stdout);
flint_abort();
}
TEST_FUNCTION_FAIL(
"ah1 = %wu, al1 = %wu, ah2 = %wu, al1 = %wu\n"
"sh2 = %wu, sh1 = %wu, sl2 = %wu, sl1 = %wu\n",
ah1, al1, ah2, al1, sh2, sh1, sl2, sl1);
}

TEST_FUNCTION_END(state);
Expand Down
18 changes: 9 additions & 9 deletions src/test/t-add_sssaaaaaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ TEST_FUNCTION_START(add_sssaaaaaa, state)

result = ((s[2] == t[2]) && (s[1] == t[1]) && (s[0] == t[0]));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a[2] = %wu, a[1] = %wu, a[0] = %wu\n", a[2], a[1], a[0]);
flint_printf("b[2] = %wu, b[1] = %wu, b[0] = %wu\n", b[2], b[1], b[0]);
flint_printf("s[2] = %wu, s[1] = %wu, s[0] = %wu\n", s[2], s[1], s[0]);
flint_printf("t[2] = %wu, t[1] = %wu, t[0] = %wu\n", t[2], t[1], t[0]);
fflush(stdout);
flint_abort();
}
TEST_FUNCTION_FAIL(
"a[2] = %wu, a[1] = %wu, a[0] = %wu\n"
"b[2] = %wu, b[1] = %wu, b[0] = %wu\n"
"s[2] = %wu, s[1] = %wu, s[0] = %wu\n"
"t[2] = %wu, t[1] = %wu, t[0] = %wu\n",
a[2], a[1], a[0],
b[2], b[1], b[0],
s[2], s[1], s[0],
t[2], t[1], t[0]);
}

TEST_FUNCTION_END(state);
Expand Down
55 changes: 23 additions & 32 deletions src/test/t-add_ssssaaaaaaaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TEST_FUNCTION_START(add_ssssaaaaaaaa, state)
for (i = 0; i < 100000 * flint_test_multiplier(); i++)
{
mp_limb_t s[4], t[4], a[4], b[4];
int aliasing;

for (j = 0; j < 4; j++)
{
Expand All @@ -28,47 +29,37 @@ TEST_FUNCTION_START(add_ssssaaaaaaaa, state)
b[j] = n_randtest(state);
}

add_ssssaaaaaaaa(s[3], s[2], s[1], s[0], a[3], a[2], a[1], a[0],
b[3], b[2], b[1], b[0]);
aliasing = n_randint(state, 2);

mpn_add_n(t, a, b, 4);

result = ((s[3] == t[3]) && (s[2] == t[2]) && (s[1] == t[1]) && (s[0] == t[0]));
if (!result)
if (aliasing)
{
flint_printf("FAIL:\n");
flint_printf("a[3] = %wu, a[2] = %wu, a[1] = %wu, a[0] = %wu\n", a[3], a[2], a[1], a[0]);
flint_printf("b[3] = %wu, b[2] = %wu, b[1] = %wu, b[0] = %wu\n", b[3], b[2], b[1], b[0]);
flint_printf("s[3] = %wu, s[2] = %wu, s[1] = %wu, s[0] = %wu\n", s[3], s[2], s[1], s[0]);
flint_printf("t[3] = %wu, t[2] = %wu, t[1] = %wu, t[0] = %wu\n", t[3], t[2], t[1], t[0]);
fflush(stdout);
flint_abort();
}
for (j = 0; j < 4; j++)
s[j] = a[j];

for (j = 0; j < 4; j++)
add_ssssaaaaaaaa(s[3], s[2], s[1], s[0], s[3], s[2], s[1], s[0],
b[3], b[2], b[1], b[0]);
}
else
{
s[j] = n_randtest(state);
t[j] = n_randtest(state);
a[j] = n_randtest(state);
b[j] = n_randtest(state);
add_ssssaaaaaaaa(s[3], s[2], s[1], s[0], a[3], a[2], a[1], a[0],
b[3], b[2], b[1], b[0]);
}

mpn_add_n(t, s, b, 4);

add_ssssaaaaaaaa(s[3], s[2], s[1], s[0], s[3], s[2], s[1], s[0],
b[3], b[2], b[1], b[0]);
mpn_add_n(t, a, b, 4);

result = ((s[3] == t[3]) && (s[2] == t[2]) && (s[1] == t[1]) && (s[0] == t[0]));
if (!result)
{
flint_printf("FAIL:\naliasing\n");
flint_printf("a[3] = %wu, a[2] = %wu, a[1] = %wu, a[0] = %wu\n", a[3], a[2], a[1], a[0]);
flint_printf("b[3] = %wu, b[2] = %wu, b[1] = %wu, b[0] = %wu\n", b[3], b[2], b[1], b[0]);
flint_printf("s[3] = %wu, s[2] = %wu, s[1] = %wu, s[0] = %wu\n", s[3], s[2], s[1], s[0]);
flint_printf("t[3] = %wu, t[2] = %wu, t[1] = %wu, t[0] = %wu\n", t[3], t[2], t[1], t[0]);
fflush(stdout);
flint_abort();
}
TEST_FUNCTION_FAIL(
"Aliasing: %d\n"
"a[3] = %wu, a[2] = %wu, a[1] = %wu, a[0] = %wu\n"
"b[3] = %wu, b[2] = %wu, b[1] = %wu, b[0] = %wu\n"
"s[3] = %wu, s[2] = %wu, s[1] = %wu, s[0] = %wu\n"
"t[3] = %wu, t[2] = %wu, t[1] = %wu, t[0] = %wu\n",
aliasing,
a[3], a[2], a[1], a[0],
b[3], b[2], b[1], b[0],
s[3], s[2], s[1], s[0],
t[3], t[2], t[1], t[0]);
}

TEST_FUNCTION_END(state);
Expand Down
104 changes: 45 additions & 59 deletions src/test/t-byte_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,55 @@

ulong byte_swap_naive(ulong n)
{
ulong r = 0;
slong i;
ulong r = 0;
slong i;

for (i = 0; i < sizeof(ulong); i++)
{
r <<= 8;
r |= (n & 0xFF);
n >>= 8;
}
for (i = 0; i < sizeof(ulong); i++)
{
r <<= 8;
r |= (n & 0xFF);
n >>= 8;
}

return r;
return r;
}

TEST_FUNCTION_START(byte_swap, state)
{
int i, result;

/* byte_swap(byte_swap(n)) == n */
for (i = 0; i < 10000 * flint_test_multiplier(); i++)
{
ulong n, r1, r2;

n = n_randtest(state);

r1 = n;

r2 = n;
byte_swap(r2);
byte_swap(r2);

result = (r1 == r2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("byte_swap(byte_swap(n)) != n\n");
flint_printf("n = %wx, r1 = %wx, r2 = %wx\n", n, r1, r2);
fflush(stdout);
flint_abort();
}
}

/* byte_swap(n) == byte_swap_naive(n) */
for (i = 0; i < 10000 * flint_test_multiplier(); i++)
{
ulong n, r1, r2;

n = n_randtest(state);

r1 = n;
byte_swap(r1);

r2 = byte_swap_naive(n);

result = (r1 == r2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("byte_swap(n) != byte_swap_naive(n)\n");
flint_printf("n = %wx, r1 = %wx, r2 = %wx\n", n, r1, r2);
fflush(stdout);
flint_abort();
}
}

TEST_FUNCTION_END(state);
int i, result;

for (i = 0; i < 10000 * flint_test_multiplier(); i++)
{
ulong n, r1, r2;
int cs;

n = n_randtest(state);
r1 = n;

cs = n_randint(state, 2);

if (cs == 0)
{
/* byte_swap(byte_swap(n)) == n */
r2 = n;
byte_swap(r2);
byte_swap(r2);
}
else
{
/* byte_swap(n) == byte_swap_naive(n) */
r1 = n;
byte_swap(r1);
r2 = byte_swap_naive(n);
}

result = (r1 == r2);
if (!result)
TEST_FUNCTION_FAIL(
"case %d\n"
"n = %wx, r1 = %wx, r2 = %wx\n",
n, r1, r2);
}

TEST_FUNCTION_END(state);
}
31 changes: 13 additions & 18 deletions src/test/t-flint_clz.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,22 @@

TEST_FUNCTION_START(flint_clz, state)
{
int i, result;
int i, result;

for (i = 0; i < 100000 * flint_test_multiplier(); i++)
{
mp_limb_t n;
unsigned int count = 0;
for (i = 0; i < 100000 * flint_test_multiplier(); i++)
{
mp_limb_t n;
unsigned int count = 0;

n = n_randtest(state);
n = n_randtest(state);

if (n != 0)
count = flint_clz(n);
if (n != 0)
count = flint_clz(n);

result = ((n == UWORD(0)) || (((slong)(n << count) < WORD(0)) && (r_shift(n, FLINT_BITS-count) == UWORD(0))));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wu, count = %u\n", n, count);
fflush(stdout);
flint_abort();
}
}
result = ((n == UWORD(0)) || (((slong)(n << count) < WORD(0)) && (r_shift(n, FLINT_BITS-count) == UWORD(0))));
if (!result)
TEST_FUNCTION_FAIL("n = %wu, count = %u\n", n, count);
}

TEST_FUNCTION_END(state);
TEST_FUNCTION_END(state);
}
7 changes: 1 addition & 6 deletions src/test/t-flint_ctz.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ TEST_FUNCTION_START(flint_ctz, state)

result = ((n == UWORD(0)) || (((n >> count) & UWORD(1)) && (l_shift(n, FLINT_BITS-count) == UWORD(0))));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wu, count = %u\n", n, count);
fflush(stdout);
flint_abort();
}
TEST_FUNCTION_FAIL("n = %wu, count = %u\n", n, count);
}

TEST_FUNCTION_END(state);
Expand Down
Loading

0 comments on commit 473413d

Please sign in to comment.