only run tests if the module is available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/demo/test.c b/demo/test.c
index 9c65eac..79cfb38 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -2220,53 +2220,58 @@ int unit_tests(int argc, char **argv)
const char *name;
int (*fn)(void);
} test[] = {
-#define T(n) { #n, test_##n }
- T(feature_detection),
- T(trivial_stuff),
- T(mp_get_set_i32),
- T(mp_get_set_i64),
- T(mp_and),
- T(mp_cnt_lsb),
- T(mp_complement),
- T(mp_decr),
- T(mp_div_3),
- T(mp_dr_reduce),
- T(mp_fread_fwrite),
- T(mp_get_u32),
- T(mp_get_u64),
- T(mp_get_ul),
- T(mp_ilogb),
- T(mp_incr),
- T(mp_invmod),
- T(mp_is_square),
- T(mp_kronecker),
- T(mp_montgomery_reduce),
- T(mp_root_u32),
- T(mp_or),
- T(mp_prime_is_prime),
- T(mp_prime_next_prime),
- T(mp_prime_rand),
- T(mp_rand),
- T(mp_read_radix),
- T(mp_reduce_2k),
- T(mp_reduce_2k_l),
+#define T0(n) { #n, test_##n }
+#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
+#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
+ T0(feature_detection),
+ T0(trivial_stuff),
+ T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
+ T2(mp_get_set_i64, MP_GET_I64, MP_GET_MAG_U64),
+ T1(mp_and, MP_AND),
+ T1(mp_cnt_lsb, MP_CNT_LSB),
+ T1(mp_complement, MP_COMPLEMENT),
+ T1(mp_decr, MP_DECR),
+ T1(mp_div_3, MP_DIV_3),
+ T1(mp_dr_reduce, MP_DR_REDUCE),
+ T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
+ T1(mp_get_u32, MP_GET_I32),
+ T1(mp_get_u64, MP_GET_I64),
+ T1(mp_get_ul, MP_GET_L),
+ T1(mp_ilogb, MP_ILOGB),
+ T1(mp_incr, MP_INCR),
+ T1(mp_invmod, MP_INVMOD),
+ T1(mp_is_square, MP_IS_SQUARE),
+ T1(mp_kronecker, MP_KRONECKER),
+ T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
+ T1(mp_root_u32, MP_ROOT_U32),
+ T1(mp_or, MP_OR),
+ T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
+ T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
+ T1(mp_prime_rand, MP_PRIME_RAND),
+ T1(mp_rand, MP_RAND),
+ T1(mp_read_radix, MP_READ_RADIX),
+ T1(mp_reduce_2k, MP_REDUCE_2K),
+ T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
- T(mp_set_double),
+ T1(mp_set_double, MP_SET_DOUBLE),
#endif
- T(mp_signed_rsh),
- T(mp_sqrt),
- T(mp_sqrtmod_prime),
- T(mp_xor),
- T(s_mp_balance_mul),
- T(s_mp_karatsuba_mul),
- T(s_mp_karatsuba_sqr),
- T(s_mp_toom_mul),
- T(s_mp_toom_sqr)
-#undef T
+ T1(mp_signed_rsh, MP_SIGNED_RSH),
+ T1(mp_sqrt, MP_SQRT),
+ T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
+ T1(mp_xor, MP_XOR),
+ T1(s_mp_balance_mul, S_MP_BALANCE_MUL),
+ T1(s_mp_karatsuba_mul, S_MP_KARATSUBA_MUL),
+ T1(s_mp_karatsuba_sqr, S_MP_KARATSUBA_SQR),
+ T1(s_mp_toom_mul, S_MP_TOOM_MUL),
+ T1(s_mp_toom_sqr, S_MP_TOOM_SQR),
+#undef T2
+#undef T1
};
- unsigned long i;
+ unsigned long i, ok, fail, nop;
uint64_t t;
- int res = EXIT_SUCCESS, j;
+ int j;
+
+ ok = fail = nop = 0;
t = (uint64_t)time(NULL);
printf("SEED: 0x%"PRIx64"\n\n", t);
@@ -2283,13 +2288,19 @@ int unit_tests(int argc, char **argv)
if (j == argc) continue;
}
printf("TEST %s\n\n", test[i].name);
- if (test[i].fn() != EXIT_SUCCESS) {
+ if (test[i].fn == NULL) {
+ nop++;
+ printf("NOP %s\n\n", test[i].name);
+ } else if (test[i].fn() == EXIT_SUCCESS) {
+ ok++;
+ printf("\n\n");
+ } else {
+ fail++;
printf("\n\nFAIL %s\n\n", test[i].name);
- res = EXIT_FAILURE;
- break;
}
- printf("\n\n");
}
+ printf("Tests OK/NOP/FAIL: %lu/%lu/%lu\n", ok, nop, fail);
- return res;
+ if (fail != 0) return EXIT_FAILURE;
+ else return EXIT_SUCCESS;
}