From 499e10d59bb8eb009fab85354e497dccfefc6965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Tue, 4 Apr 2023 02:07:20 +0200 Subject: [PATCH] Sketch unified tests --- src/test/main.c | 59 +++++++++++++++++++++++++ src/test/t-add_ssaaaa.c | 78 +++++++++++++++------------------- src/test/t-add_sssaaaaaa.c | 14 ++---- src/test/t-add_ssssaaaaaaaa.c | 15 +++---- src/test/t-byte_swap.c | 14 ++---- src/test/t-flint_clz.c | 14 ++---- src/test/t-flint_ctz.c | 14 ++---- src/test/t-invert_limb.c | 13 ++---- src/test/t-sdiv_qrnnd.c | 14 ++---- src/test/t-smul_ppmm.c | 14 ++---- src/test/t-sub_dddmmmsss.c | 13 ++---- src/test/t-sub_ddmmss.c | 14 ++---- src/test/t-udiv_qrnnd.c | 14 ++---- src/test/t-udiv_qrnnd_preinv.c | 14 ++---- src/test/t-umul_ppmm.c | 14 ++---- src/test_helpers.h | 21 ++++++++- 16 files changed, 156 insertions(+), 183 deletions(-) create mode 100644 src/test/main.c diff --git a/src/test/main.c b/src/test/main.c new file mode 100644 index 0000000000..bd9481d10b --- /dev/null +++ b/src/test/main.c @@ -0,0 +1,59 @@ +/* + Copyright (C) 2023 Albin Ahlbäck + + This file is part of FLINT. + + FLINT is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License (LGPL) as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. See . +*/ + +/* Include functions *********************************************************/ + +#include "t-add_ssaaaa.c" +#include "t-add_sssaaaaaa.c" +#include "t-add_ssssaaaaaaaa.c" +#include "t-byte_swap.c" +#include "t-flint_clz.c" +#include "t-flint_ctz.c" +#include "t-invert_limb.c" +#include "t-sdiv_qrnnd.c" +#include "t-smul_ppmm.c" +#include "t-sub_dddmmmsss.c" +#include "t-sub_ddmmss.c" +#include "t-udiv_qrnnd.c" +#include "t-udiv_qrnnd_preinv.c" +#include "t-umul_ppmm.c" + +/* Array of test functions ***************************************************/ + +int (*test_functions[])(void) = +{ + TEST_FUNCTION(add_ssaaaa), + TEST_FUNCTION(add_sssaaaaaa), + TEST_FUNCTION(add_ssssaaaaaaaa), + TEST_FUNCTION(byte_swap), + TEST_FUNCTION(flint_clz), + TEST_FUNCTION(flint_ctz), + TEST_FUNCTION(invert_limb), + TEST_FUNCTION(sdiv_qrnnd), + TEST_FUNCTION(smul_ppmm), + TEST_FUNCTION(sub_dddmmmsss), + TEST_FUNCTION(sub_ddmmss), + TEST_FUNCTION(udiv_qrnnd), + TEST_FUNCTION(udiv_qrnnd_preinv), + TEST_FUNCTION(umul_ppmm) +}; + +/* main function *************************************************************/ + +int +main() +{ + slong ix; + + for (ix = 0; ix < sizeof(test_functions) / sizeof(int (*)(void)); ix++) + if (test_functions[ix]()) + flint_abort(); +} diff --git a/src/test/t-add_ssaaaa.c b/src/test/t-add_ssaaaa.c index b5b6a94d79..358d9bbf7f 100644 --- a/src/test/t-add_ssaaaa.c +++ b/src/test/t-add_ssaaaa.c @@ -9,50 +9,42 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(add_ssaaaa) { - int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("add_ssaaaa...."); - fflush(stdout); - - for (i = 0; i < 1000000; i++) - { - mp_limb_t sh1, sl1, sh2, sl2, ah1, al1, ah2, al2; - - ah1 = n_randtest(state); - al1 = n_randtest(state); - ah2 = n_randtest(state); - al2 = n_randtest(state); - - if (n_randint(state, 10) == 0) - add_ssaaaa(sh1, sl1, (slong) ah1, (slong) al1, (slong) ah2, (slong) al2); - else - add_ssaaaa(sh1, sl1, ah1, al1, ah2, al2); - - sl2 = al1 + al2; - sh2 = (sl1 < al1); - sh2 += ah1; - sh2 += ah2; - - 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(); - } - } - - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + int i, result; + + for (i = 0; i < 1000000; i++) + { + mp_limb_t sh1, sl1, sh2, sl2, ah1, al1, ah2, al2; + + ah1 = n_randtest(state); + al1 = n_randtest(state); + ah2 = n_randtest(state); + al2 = n_randtest(state); + + if (n_randint(state, 10) == 0) + add_ssaaaa(sh1, sl1, (slong) ah1, (slong) al1, (slong) ah2, (slong) al2); + else + add_ssaaaa(sh1, sl1, ah1, al1, ah2, al2); + + sl2 = al1 + al2; + sh2 = (sl1 < al1); + sh2 += ah1; + sh2 += ah2; + + 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_END; } diff --git a/src/test/t-add_sssaaaaaa.c b/src/test/t-add_sssaaaaaa.c index b791a13d9c..63efa38f4c 100644 --- a/src/test/t-add_sssaaaaaa.c +++ b/src/test/t-add_sssaaaaaa.c @@ -10,17 +10,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(add_sssaaaaaa) { int i, j, result; - FLINT_TEST_INIT(state); - - - flint_printf("add_sssaaaaaa...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -51,8 +46,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-add_ssssaaaaaaaa.c b/src/test/t-add_ssssaaaaaaaa.c index 533f807956..df8c07d5d6 100644 --- a/src/test/t-add_ssssaaaaaaaa.c +++ b/src/test/t-add_ssssaaaaaaaa.c @@ -1,22 +1,20 @@ /* Copyright (C) 2019 Daniel Schultz + This file is part of FLINT. + FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(add_ssssaaaaaaaa) { int i, j, result; - FLINT_TEST_INIT(state); - - flint_printf("add_ssssaaaaaaaa...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -73,8 +71,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-byte_swap.c b/src/test/t-byte_swap.c index c1403c72a8..4d7ee1db16 100644 --- a/src/test/t-byte_swap.c +++ b/src/test/t-byte_swap.c @@ -9,8 +9,8 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" ulong byte_swap_naive(ulong n) { @@ -27,13 +27,10 @@ ulong byte_swap_naive(ulong n) return r; } -int main(void) + +TEST_FUNCTION_START(byte_swap) { int i, result; - FLINT_TEST_INIT(state); - - flint_printf("byte_swap...."); - fflush(stdout); /* byte_swap(byte_swap(n)) == n */ for (i = 0; i < 10000 * flint_test_multiplier(); i++) @@ -82,8 +79,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-flint_clz.c b/src/test/t-flint_clz.c index 827b0a0f19..78bc9f236d 100644 --- a/src/test/t-flint_clz.c +++ b/src/test/t-flint_clz.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(flint_clz) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("flint_clz...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -41,8 +36,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-flint_ctz.c b/src/test/t-flint_ctz.c index 3ce7360b54..d07f661daa 100644 --- a/src/test/t-flint_ctz.c +++ b/src/test/t-flint_ctz.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(flint_ctz) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("flint_ctz...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -41,8 +36,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-invert_limb.c b/src/test/t-invert_limb.c index 04195bd658..77c3ca98e3 100644 --- a/src/test/t-invert_limb.c +++ b/src/test/t-invert_limb.c @@ -9,8 +9,8 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" #define invert_limb_naive(ninv, n) \ do { \ @@ -18,13 +18,9 @@ udiv_qrnnd (ninv, dummy, ~(n), ~(WORD(0)), n); \ } while (0) -int main(void) +TEST_FUNCTION_START(invert_limb) { int i, result; - FLINT_TEST_INIT(state); - - flint_printf("invert_limb...."); - fflush(stdout); for (i = 0; i < 100000 * flint_test_multiplier(); i++) { @@ -46,8 +42,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END } diff --git a/src/test/t-sdiv_qrnnd.c b/src/test/t-sdiv_qrnnd.c index 5026ff7dcd..699ce9ef15 100644 --- a/src/test/t-sdiv_qrnnd.c +++ b/src/test/t-sdiv_qrnnd.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(sdiv_qrnnd) { slong i; - FLINT_TEST_INIT(state); - - flint_printf("sdiv_qrnnd...."); - fflush(stdout); for (i = 0; i < 1000000*flint_test_multiplier(); i++) { @@ -75,8 +70,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-smul_ppmm.c b/src/test/t-smul_ppmm.c index 00fed8bdc6..f82199c338 100644 --- a/src/test/t-smul_ppmm.c +++ b/src/test/t-smul_ppmm.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(smul_ppmm) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("smul_ppmm...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -78,8 +73,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-sub_dddmmmsss.c b/src/test/t-sub_dddmmmsss.c index ca155b0d25..8a8ac91a11 100644 --- a/src/test/t-sub_dddmmmsss.c +++ b/src/test/t-sub_dddmmmsss.c @@ -10,16 +10,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(sub_dddmmmsss) { int i, j, result; - FLINT_TEST_INIT(state); - - flint_printf("sub_dddmmmsss...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -50,8 +46,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-sub_ddmmss.c b/src/test/t-sub_ddmmss.c index 1b949e9c5c..f12cfb626e 100644 --- a/src/test/t-sub_ddmmss.c +++ b/src/test/t-sub_ddmmss.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(sub_ddmmss) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("sub_ddmmss...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -52,8 +47,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-udiv_qrnnd.c b/src/test/t-udiv_qrnnd.c index f8b1fb262c..aef064e683 100644 --- a/src/test/t-udiv_qrnnd.c +++ b/src/test/t-udiv_qrnnd.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(udiv_qrnnd) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("udiv_qrnnd...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -48,8 +43,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-udiv_qrnnd_preinv.c b/src/test/t-udiv_qrnnd_preinv.c index 8490c56ddd..b0967201b9 100644 --- a/src/test/t-udiv_qrnnd_preinv.c +++ b/src/test/t-udiv_qrnnd_preinv.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(udiv_qrnnd_preinv) { int i, result; - FLINT_TEST_INIT(state); - - - flint_printf("udiv_qrnnd_preinv...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -50,8 +45,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test/t-umul_ppmm.c b/src/test/t-umul_ppmm.c index 703338e28c..132fee7da0 100644 --- a/src/test/t-umul_ppmm.c +++ b/src/test/t-umul_ppmm.c @@ -9,17 +9,12 @@ (at your option) any later version. See . */ -#include "flint.h" #include "ulong_extras.h" +#include "test_helpers.h" -int main(void) +TEST_FUNCTION_START(umul_ppmm) { int i, j, result; - FLINT_TEST_INIT(state); - - - flint_printf("umul_ppmm...."); - fflush(stdout); for (i = 0; i < 1000000; i++) { @@ -58,8 +53,5 @@ int main(void) } } - FLINT_TEST_CLEANUP(state); - - flint_printf("PASS\n"); - return 0; + TEST_FUNCTION_END; } diff --git a/src/test_helpers.h b/src/test_helpers.h index f481789733..c8ff7ccf0f 100644 --- a/src/test_helpers.h +++ b/src/test_helpers.h @@ -1,5 +1,6 @@ /* Copyright (C) 2021 Daniel Schultz + Copyright (C) 2023 Albin Ahlbäck This file is part of FLINT. @@ -12,6 +13,8 @@ #ifndef TEST_HELPERS_H #define TEST_HELPERS_H +#include "templates.h" + /* easy way to test a condition in test code */ #define FLINT_TEST(e) \ do { \ @@ -23,5 +26,21 @@ } \ } while (0) -#endif +/* test function macro *******************************************************/ + +#define TEST_FUNCTION(label) TEMPLATE(test, label) +#define TEST_FUNCTION_START(label) \ +int TEMPLATE(test, label)(void) \ +{ \ + FLINT_TEST_INIT(state); \ + printf(TEMPLATE_STR(label) "...."); \ + fflush(stdout); \ + +#define TEST_FUNCTION_END \ + FLINT_TEST_CLEANUP(state); \ + printf("PASS\n"); \ + return 0; \ +} + +#endif