From 9ca37ca01ced3af9d9a39568c738354cf06aa108 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 15 Oct 2014 16:22:35 +0200 Subject: [PATCH] mtest vs. test: add possibility to exit testing 'mtest' can now optionally only run a given amount of loops. the first parameter when invoking 'mtest' is considered to determine the amount when is in the range -63..-1: mtest will run 2^-n runs when is > 0: mtest will run n runs else: mtest will exit immediately --- demo/demo.c | 3 +++ mtest/mtest.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/demo/demo.c b/demo/demo.c index 48352f6..081c993 100644 --- a/demo/demo.c +++ b/demo/demo.c @@ -798,6 +798,9 @@ printf("compare no compare!\n"); return EXIT_FAILURE; } printf("d == %d\n", ix); return EXIT_FAILURE; } + } else if (!strcmp(cmd, "exit")) { + printf("\nokay, exiting now\n"); + break; } } #endif diff --git a/mtest/mtest.c b/mtest/mtest.c index 0165acf..56b5a90 100644 --- a/mtest/mtest.c +++ b/mtest/mtest.c @@ -96,9 +96,10 @@ void rand_num2(mp_int *a) #define mp_to64(a, b) mp_toradix(a, b, 64) -int main(void) +int main(int argc, char *argv[]) { int n, tmp; + long long max; mp_int a, b, c, d, e; #ifdef MTEST_NO_FULLSPEED clock_t t1; @@ -111,6 +112,22 @@ int main(void) mp_init(&d); mp_init(&e); + if (argc > 1) { + max = strtol(argv[1], NULL, 0); + if (max < 0) { + if (max > -64) { + max = (1 << -(max)) + 1; + } else { + max = 1; + } + } else if (max == 0) { + max = 1; + } + } + else { + max = 0; + } + /* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */ /* @@ -154,6 +171,12 @@ int main(void) #endif n = getRandChar() % 15; + if (max != 0) { + --max; + if (max == 0) + n = 255; + } + if (n == 0) { /* add tests */ rand_num(&a); @@ -334,7 +357,11 @@ int main(void) printf("%s\n%d\n", buf, tmp); mp_to64(&b, buf); printf("%s\n", buf); + } else if (n == 255) { + printf("exit\n"); + break; } + } #ifdef LTM_MTEST_REAL_RAND fclose(rng);