work a bit on code coverage

This commit is contained in:
Steffen Jaeckel 2015-04-26 15:27:52 +02:00
parent d32e7a3dd0
commit c4501e1eb5
2 changed files with 126 additions and 108 deletions

View File

@ -165,6 +165,26 @@ int main(void)
printf("MP_PREC: %d\n", MP_PREC);
#if LTM_DEMO_TEST_VS_MTEST == 0
// trivial stuff
mp_set_int(&a, 5);
mp_neg(&a, &b);
if (mp_cmp(&a, &b) != MP_GT) {
return EXIT_FAILURE;
}
if (mp_cmp(&b, &a) != MP_LT) {
return EXIT_FAILURE;
}
mp_neg(&a, &a);
if (mp_cmp(&b, &a) != MP_EQ) {
return EXIT_FAILURE;
}
mp_abs(&a, &b);
if (mp_isneg(&b) != MP_NO) {
return EXIT_FAILURE;
}
mp_add_d(&a, 1, &b);
mp_add_d(&a, 6, &b);
// test montgomery
printf("Testing: montgomery...\n");
for (i = 1; i < 10; i++) {
@ -279,7 +299,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
if (mp_cmp_mag (&b, &c) != MP_EQ) {
printf ("mp_sqrt() bad result!\n");
return 1;
return EXIT_FAILURE;
}
}
@ -334,10 +354,9 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
for (ix = 10; ix < 128; ix++) {
printf ("Testing (not safe-prime): %9d bits \r", ix);
fflush (stdout);
err =
mp_prime_random_ex(&a, 8, ix,
(rand() & 1) ? 0 : LTM_PRIME_2MSB_ON,
myrng, NULL);
err = mp_prime_random_ex (&a, 8, ix,
(rand () & 1) ? 0 : LTM_PRIME_2MSB_ON, myrng,
NULL);
if (err != MP_OKAY) {
printf ("failed with err code %d\n", err);
return EXIT_FAILURE;
@ -352,9 +371,8 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
for (ix = 16; ix < 128; ix++) {
printf ("Testing ( safe-prime): %9d bits \r", ix);
fflush (stdout);
err =
mp_prime_random_ex(&a, 8, ix,
((rand() & 1) ? 0 : LTM_PRIME_2MSB_ON) | LTM_PRIME_SAFE,
err = mp_prime_random_ex (
&a, 8, ix, ((rand () & 1) ? 0 : LTM_PRIME_2MSB_ON) | LTM_PRIME_SAFE,
myrng, NULL);
if (err != MP_OKAY) {
printf ("failed with err code %d\n", err);
@ -414,7 +432,6 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
mp_2expt (&a, cnt);
mp_sub_d (&a, 2, &a); /* a = 2**cnt - 2 */
printf ("\r %4d bits", cnt);
printf ("(%d)", mp_reduce_is_2k (&a));
mp_reduce_2k_setup (&a, &tmp);
@ -430,7 +447,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
mp_reduce_2k (&b, &a, 2);
if (mp_cmp (&c, &b)) {
printf ("FAILED\n");
exit(0);
return EXIT_FAILURE;
}
}
}
@ -482,12 +499,12 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
mp_copy (&b, &c);
mp_mod (&b, &a, &b);
mp_dr_reduce(&c, &a, (((mp_digit) 1) << DIGIT_BIT) - a.dp[0]);
mp_dr_setup(&a, &mp),
mp_dr_reduce (&c, &a, mp);
if (mp_cmp (&b, &c) != MP_EQ) {
printf ("Failed on trial %u\n", rr);
exit(-1);
return EXIT_FAILURE;
}
} while (++rr < 500);
printf (" passed");

View File

@ -1,5 +1,6 @@
#include <tommath.h>
#include <time.h>
#include <unistd.h>
ulong64 _tt;