Commit eedf1624f036bd3f86fe2ab58a50d25c02f57fc3

Steffen Jaeckel 2019-03-07T15:01:45

allow filtering of tests executed

diff --git a/demo/main.c b/demo/main.c
index 883f54d..aa58c20 100644
--- a/demo/main.c
+++ b/demo/main.c
@@ -1,7 +1,7 @@
 #include "shared.h"
 
 int mtest_opponent(void);
-int unit_tests(void);
+int unit_tests(int argc, char **argv);
 
 void ndraw(mp_int *a, const char *name)
 {
@@ -24,7 +24,7 @@ void ndraw(mp_int *a, const char *name)
    free(buf);
 }
 
-int main(void)
+int main(int argc, char **argv)
 {
    srand(LTM_DEMO_RAND_SEED);
 
@@ -48,5 +48,5 @@ int main(void)
    if (LTM_DEMO_TEST_VS_MTEST) {
       return mtest_opponent();
    }
-   return unit_tests();
+   return unit_tests(argc, argv);
 }
diff --git a/demo/test.c b/demo/test.c
index c72c493..01bc959 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -1806,7 +1806,7 @@ LTM_ERR:
    return EXIT_FAILURE;
 }
 
-int unit_tests(void)
+int unit_tests(int argc, char **argv)
 {
    static const struct {
       const char *name;
@@ -1846,7 +1846,7 @@ int unit_tests(void)
 #undef T
    };
    unsigned long i;
-   int res = EXIT_SUCCESS;
+   int res = EXIT_SUCCESS, j;
 
 #if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
    fd_urandom = fopen("/dev/urandom", "r");
@@ -1856,6 +1856,14 @@ int unit_tests(void)
 #endif
 
    for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
+      if (argc > 1) {
+         for (j = 1; j < argc; ++j) {
+            if (strstr(test[i].name, argv[j]) != NULL) {
+               break;
+            }
+         }
+         if (j == argc) continue;
+      }
       printf("TEST %s\n\n", test[i].name);
       if (test[i].fn() != EXIT_SUCCESS) {
          printf("\n\nFAIL %s\n\n", test[i].name);