mtest vs. test: add possibility to exit testing 'mtest' can now optionally only run a given amount of loops. the first parameter <n> when invoking 'mtest' is considered to determine the amount when <n> is in the range -63..-1: mtest will run 2^-n runs when <n> is > 0: mtest will run n runs else: mtest will exit immediately
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
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);