Beispiel #1
0
int main(int argc, char **argv)
{
#ifdef LTC_PTHREAD
   thread_info *tinfo, *res;
#endif
   int x, pass = 0, fail = 0, nop = 0;
   size_t fn_len, i, dots;
   char *single_test = NULL;
   ulong64 ts;
   long delta, dur, real = 0;
   register_algs();

   printf("LTC_VERSION  = %s\n%s\n\n", GIT_VERSION, crypt_build_settings);

#ifdef USE_LTM
   ltc_mp = ltm_desc;
   printf("MP_PROVIDER  = LibTomMath\n");
#elif defined(USE_TFM)
   ltc_mp = tfm_desc;
   printf("MP_PROVIDER  = TomsFastMath\n");
#elif defined(USE_GMP)
   ltc_mp = gmp_desc;
   printf("MP_PROVIDER  = GnuMP\n");
#elif defined(EXT_MATH_LIB)
   {
      extern ltc_math_descriptor EXT_MATH_LIB;
      ltc_mp = EXT_MATH_LIB;
   }

#define NAME_VALUE(s) #s"="NAME(s)
#define NAME(s) #s
   printf("MP_PROVIDER  = %s\n", NAME_VALUE(EXT_MATH_LIB));
#undef NAME_VALUE
#undef NAME

#endif
#ifdef LTC_TEST_MPI
   printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT);
#else
   printf("NO math provider selected, all tests requiring MPI were disabled and will 'nop'\n");
#endif

   printf("sizeof(ltc_mp_digit) = %d\n", (int)sizeof(ltc_mp_digit));

#ifdef LTC_PTHREAD
   tinfo = XCALLOC(sizeof(test_functions)/sizeof(test_functions[0]), sizeof(thread_info));
   if (tinfo == NULL) {
      printf("\n\nFAILURE: XCALLOC\n");
      return EXIT_FAILURE;
   }
#endif

   fn_len = 0;
   for (i = 0; i < sizeof(test_functions) / sizeof(test_functions[0]); ++i) {
      size_t len = strlen(test_functions[i].name);
      if (fn_len < len) fn_len = len;

#ifdef LTC_PTHREAD
      if(test_functions[i].fn == prng_test) continue;
      tinfo[i].t = &test_functions[i];
      x = pthread_create(&tinfo[i].thread_id, NULL, run, &tinfo[i]);
      if (x != 0)  {
         printf("\n\nFAILURE: pthread_create\n");
         return EXIT_FAILURE;
      }
#endif
   }

   fn_len = fn_len + (4 - (fn_len % 4));

   /* single test name from commandline */
   if (argc > 1) single_test = argv[1];

   dur = epoch_usec();
   for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
      if (single_test && strstr(test_functions[i].name, single_test) == NULL) {
        continue;
      }
      dots = fn_len - strlen(test_functions[i].name);

      printf("\n%s", test_functions[i].name);
      while(dots--) printf(".");
      fflush(stdout);

#ifdef LTC_PTHREAD
      if(test_functions[i].fn != prng_test) {
         x = pthread_join(tinfo[i].thread_id, (void**)&res);
         if (x != 0){
            printf("\n\nFAILURE: pthread_join\n");
            return EXIT_FAILURE;
         }
         x = res->err;
         delta = res->delta;
      }
      else {
         ts = epoch_usec();
         x = test_functions[i].fn();
         delta = (long)(epoch_usec() - ts);
      }
#else
      ts = epoch_usec();
      x = test_functions[i].fn();
      delta = (long)(epoch_usec() - ts);
#endif
      real += delta;

      if (x == CRYPT_OK) {
         printf("passed %10.3fms", (double)(delta)/1000);
         pass++;
      }
      else if (x == CRYPT_NOP) {
         printf("nop");
         nop++;
      }
      else {
         printf("failed (%s) %10.3fms", error_to_string(x), (double)(delta)/1000);
         fail++;
      }
   }
   dur = epoch_usec() - dur;

#ifdef LTC_PTHREAD
   XFREE(tinfo);
#endif

   x = (fail > 0 || fail+pass+nop == 0) ? EXIT_FAILURE : EXIT_SUCCESS;
   printf("\n\n%s: passed=%d failed=%d nop=%d duration=%.1fsec real=%.1fsec\n", x ? "FAILURE" : "SUCCESS", pass, fail, nop, (double)(dur)/(1000*1000), (double)(real)/(1000*1000));
   return x;
}
Beispiel #2
0
    benchmark_report_delim = "";
    benchmark(stdout, "test_example_wikipedia_bcon", test_example_wikipedia_bcon, 1, 1, 1.0, 10);
    printf("\n\t--------\n");
    benchmark_report_delim = "";
    benchmark(stdout, "test_example_wikipedia_bson", test_example_wikipedia_bson, 1, 1, 1.0, 10);
    putchar('\n');
 */
}

#define NAME_VALUE(x) { #x, x }

struct test_suite {
    char *name;
    void (*fn)();
} test_suite[] = {
    NAME_VALUE(test_bcon_token),
    NAME_VALUE(test_basic_types),
    NAME_VALUE(test_basic_interpolation),
    NAME_VALUE(test_oid_and_interpolation),
    NAME_VALUE(test_invalid_structure),
    NAME_VALUE(test_valid_structure),
    NAME_VALUE(test_problematic_structure),
    NAME_VALUE(test_high_order_interpolation),
    NAME_VALUE(test_example_hello_world),
    NAME_VALUE(test_example_awesome),
    /* NAME_VALUE(test_example_wikipedia), */
};

int main(int argc, char **argv) {
    int i;
    if (argc > 1)