demos/test facelift

This commit is contained in:
Karel Miko 2017-03-29 20:52:30 +02:00
parent 4874430dec
commit 2a2968ae92
4 changed files with 59 additions and 10 deletions

View File

@ -26,10 +26,12 @@ static const struct {
LTC_TEST_FN(katja_test), LTC_TEST_FN(katja_test),
}; };
int main(void) int main(int argc, char **argv)
{ {
int x; int x, pass = 0, fail = 0, nop = 0;
size_t fn_len, i, dots; size_t fn_len, i, dots;
char *single_test = NULL;
ulong64 ts, dur = 0;
reg_algs(); reg_algs();
printf("build == \n%s\n", crypt_build_settings); printf("build == \n%s\n", crypt_build_settings);
@ -58,26 +60,46 @@ int main(void)
fn_len = fn_len + (4 - (fn_len % 4)); fn_len = fn_len + (4 - (fn_len % 4));
/* single test name from commandline */
if (argc > 1) single_test = argv[1];
for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
if (single_test && strcmp(test_functions[i].name, single_test)) {
continue;
}
dots = fn_len - strlen(test_functions[i].name); dots = fn_len - strlen(test_functions[i].name);
printf("\n%s", test_functions[i].name); printf("\n%s", test_functions[i].name);
while(dots--) printf("."); while(dots--) printf(".");
fflush(stdout); fflush(stdout);
ts = epoch_usec();
x = test_functions[i].fn(); x = test_functions[i].fn();
ts = epoch_usec() - ts;
dur += ts;
if (x) { if (x == CRYPT_OK) {
printf("failed\n"); printf("passed %10.3fms", (double)(ts)/1000);
exit(EXIT_FAILURE); pass++;
}
else if (x == CRYPT_NOP) {
printf("nop");
nop++;
} }
else { else {
printf("passed"); printf("failed %10.3fms", (double)(ts)/1000);
fail++;
} }
} }
printf("\n"); if (fail > 0 || fail+pass+nop == 0) {
return EXIT_SUCCESS; printf("\n\nFAILURE: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000));
return EXIT_FAILURE;
}
else {
printf("\n\nSUCCESS: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000));
return EXIT_SUCCESS;
}
} }
/* $Source$ */ /* $Source$ */

View File

@ -224,8 +224,7 @@ for (cnt = 0; cnt < len; ) {
int katja_test(void) int katja_test(void)
{ {
fprintf(stderr, "NOP"); return CRYPT_NOP;
return 0;
} }
#endif #endif

View File

@ -88,6 +88,7 @@ int compare_testvector(const void* is, const unsigned long is_len, const void* s
int sorter(const void *a, const void *b); int sorter(const void *a, const void *b);
void tally_results(int type); void tally_results(int type);
ulong64 rdtsc (void); ulong64 rdtsc (void);
ulong64 epoch_usec(void);
void t_start(void); void t_start(void);
ulong64 t_read(void); ulong64 t_read(void);

View File

@ -1,5 +1,32 @@
#include <tomcrypt_test.h> #include <tomcrypt_test.h>
#if defined(_WIN32)
#include <windows.h> /* GetSystemTimeAsFileTime */
#else
#include <sys/time.h>
#endif
/* microseconds since 1970 (UNIX epoch) */
ulong64 epoch_usec(void)
{
#if defined(LTC_NO_TEST_TIMING)
return 0;
#elif defined(_WIN32)
FILETIME CurrentTime;
ulong64 cur_time;
GetSystemTimeAsFileTime(&CurrentTime);
cur_time = ((ulong64)CurrentTime.dwHighDateTime << 32) + (ulong64)CurrentTime.dwLowDateTime;
cur_time -= 116444736000000000LL; /* subtract epoch in microseconds */
cur_time /= 10; /* nanoseconds > microseconds */
return cur_time;
#else
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */
#endif
}
prng_state yarrow_prng; prng_state yarrow_prng;
void print_hex(const char* what, const void* v, const unsigned long l) void print_hex(const char* what, const void* v, const unsigned long l)