make bench use wolfCLU_checkForArg()

pull/74/head
Levi Rak 2017-08-17 11:54:15 -06:00
parent e73aa160da
commit 86e2c9a7ba
3 changed files with 57 additions and 42 deletions

View File

@ -57,7 +57,7 @@ static struct option long_options[] = {
/* @temporary: implement modes as flags */
{"encrypt", required_argument, 0, ENCRYPT },
{"decrypt", required_argument, 0, DECRYPT },
{"bench", required_argument, 0, BENCHMARK },
{"bench", no_argument, 0, BENCHMARK },
{"hash", required_argument, 0, HASH },
{"x509", no_argument, 0, X509 },
{"req", required_argument, 0, REQUEST },

View File

@ -26,74 +26,82 @@ int wolfCLU_benchSetup(int argc, char** argv)
int ret = 0; /* return variable */
int time = 3; /* timer variable */
int i, j = 0; /* second loop variable */
const char* algs[] = { /* list of acceptable algorithms */
char* algs[] = { /* list of acceptable algorithms */
#ifndef NO_AES
"aes-cbc"
"aes-cbc",
#endif
#ifdef WOLFSSL_AES_COUNTER
, "aes-ctr"
"aes-ctr",
#endif
#ifndef NO_DES3
, "3des"
"3des",
#endif
#ifdef HAVE_CAMELLIA
, "camellia"
"camellia",
#endif
#ifndef NO_MD5
, "md5"
"md5",
#endif
#ifndef NO_SHA
, "sha"
"sha",
#endif
#ifndef NO_SHA256
, "sha256"
"sha256",
#endif
#ifdef WOLFSSL_SHA384
, "sha384"
"sha384",
#endif
#ifdef WOLFSSL_SHA512
, "sha512"
"sha512",
#endif
#ifdef HAVE_BLAKE2
, "blake2b"
"blake2b",
#endif
NULL /* terminal argument (also stops us from having an empty list) */
};
size_t algsSz = sizeof(algs) / sizeof(algs[0]) - 1; /* -1 to ignore NULL */
int option[sizeof(algs)/sizeof(algs[0])] = {0};/* acceptable options */
int optionCheck = 0; /* acceptable option check */
/* acceptable options */
int option[sizeof(algs) / sizeof(algs[0])] = {0};
for (i = 2; i < argc; i++) {
if (XSTRNCMP(argv[i], "-help", 5) == 0 || XSTRNCMP(argv[i], "-h", 2)
== 0) {
/* help checking */
/* acceptable option check */
int optionCheck = 0;
ret = wolfCLU_checkForArg("-h", 2, argc, argv);
if (ret > 0) {
wolfCLU_benchHelp();
return 0;
}
for (j = 0; j < (int) sizeof(algs)/(int) sizeof(algs[0]); j++) {
/* checks for individual tests in the arguments */
if (XSTRNCMP(argv[i], algs[j], XSTRLEN(argv[i])) == 0) {
option[j] = 1;
optionCheck = 1;
}
}
if (XSTRNCMP(argv[i], "-time", 5) == 0 && argv[i+1] != NULL) {
/* time for each test in seconds */
time = atoi(argv[i+1]);
if (time < 1 || time > 10) {
printf("Invalid time, must be between 1-10. Using default"
" of three seconds.\n");
time = 3;
}
i++;
}
if (XSTRNCMP(argv[i], "-all", 4) == 0) {
/* perform all available tests */
for (j = 0; j < (int) sizeof(algs)/(int) sizeof(algs[0]); j++) {
option[j] = 1;
optionCheck = 1;
}
}
ret = wolfCLU_checkForArg("-time", 5, argc, argv);
if (ret > 0) {
/* time for each test in seconds */
time = atoi(argv[ret+1]);
if (time < 1 || time > 10) {
printf("Invalid time, must be between 1-10. Using default"
" of three seconds.\n");
time = 3;
}
}
ret = wolfCLU_checkForArg("-all", 4, argc, argv);
if (ret > 0) {
/* perform all available tests */
for (j = 0; j < (int)algsSz; j++) {
option[j] = 1;
optionCheck = 1;
}
}
/* pull as many of the algorithms out of the argv as posible */
for (i = 0; i < (int)algsSz; ++i) {
ret = wolfCLU_checkForArg(algs[i], XSTRLEN(algs[i]), argc, argv);
if (ret > 0) {
option[i] = 1;
optionCheck = 1;
}
}
if (optionCheck != 1) {
/* help checking */
wolfCLU_help();

View File

@ -63,6 +63,13 @@ int wolfCLU_benchmark(int timer, int* option)
wc_InitRng(&rng);
signal(SIGALRM, wolfCLU_stop);
/* @fragile:
* this function assumes that it perfectly knows the order and length of
* the option array in clu_src/benchmark/clu_bench_setup.c. Looping over a
* switch on an enum would be much more robust.
*/
i = 0;
#ifndef NO_AES
/* aes test */