summaryrefslogtreecommitdiffstats
path: root/test/ecstresstest.c
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2018-08-16 12:36:01 +1000
committerRichard Levitte <levitte@openssl.org>2019-02-11 15:31:51 +0100
commita43ce58f5569a160272c492c680f2e42d38ec769 (patch)
treeacfaac32bee9b8e5dd832fbb49f95709c3b9741e /test/ecstresstest.c
parent9d5560331d86c6463e965321f774e4eed582ce0b (diff)
Updated test command line parsing to support commmon commands
Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6975)
Diffstat (limited to 'test/ecstresstest.c')
-rw-r--r--test/ecstresstest.c62
1 files changed, 34 insertions, 28 deletions
diff --git a/test/ecstresstest.c b/test/ecstresstest.c
index 8cb43e6a42..a589103f65 100644
--- a/test/ecstresstest.c
+++ b/test/ecstresstest.c
@@ -18,7 +18,7 @@
#define NUM_REPEATS "1000000"
-static int64_t num_repeats;
+static intmax_t num_repeats;
static int print_mode = 0;
#ifndef OPENSSL_NO_EC
@@ -39,10 +39,10 @@ static const char *kP256DefaultResult =
* point multiplication.
* Returns the X-coordinate of the end result or NULL on error.
*/
-static BIGNUM *walk_curve(const EC_GROUP *group, EC_POINT *point, int64_t num)
+static BIGNUM *walk_curve(const EC_GROUP *group, EC_POINT *point, intmax_t num)
{
BIGNUM *scalar = NULL;
- int64_t i;
+ intmax_t i;
if (!TEST_ptr(scalar = BN_new())
|| !TEST_true(EC_POINT_get_affine_coordinates(group, point, scalar,
@@ -101,20 +101,21 @@ err:
}
#endif
-static int atoi64(const char *in, int64_t *result)
-{
- int64_t ret = 0;
-
- for ( ; *in != '\0'; in++) {
- char c = *in;
+typedef enum OPTION_choice {
+ OPT_ERR = -1,
+ OPT_EOF = 0,
+ OPT_NUM_REPEATS,
+ OPT_TEST_ENUM
+} OPTION_CHOICE;
- if (!isdigit((unsigned char)c))
- return 0;
- ret *= 10;
- ret += (c - '0');
- }
- *result = ret;
- return 1;
+const OPTIONS *test_get_options(void)
+{
+ static const OPTIONS test_options[] = {
+ OPT_TEST_OPTIONS_DEFAULT_USAGE,
+ { "num", OPT_NUM_REPEATS, 'M', "Number of repeats" },
+ { NULL }
+ };
+ return test_options;
}
/*
@@ -124,22 +125,27 @@ static int atoi64(const char *in, int64_t *result)
*/
int setup_tests(void)
{
- const char *p;
+ OPTION_CHOICE o;
- if (!atoi64(NUM_REPEATS, &num_repeats)) {
+ if (!opt_imax(NUM_REPEATS, &num_repeats)) {
TEST_error("Cannot parse " NUM_REPEATS);
return 0;
}
- /*
- * TODO(openssl-team): code under test/ should be able to reuse the option
- * parsing framework currently in apps/.
- */
- p = test_get_option_argument("-num");
- if (p != NULL) {
- if (!atoi64(p, &num_repeats)
- || num_repeats < 0)
- return 0;
- print_mode = 1;
+
+ while ((o = opt_next()) != OPT_EOF) {
+ switch (o) {
+ case OPT_NUM_REPEATS:
+ if (!opt_imax(opt_arg(), &num_repeats)
+ || num_repeats < 0)
+ return 0;
+ print_mode = 1;
+ break;
+ case OPT_TEST_CASES:
+ break;
+ default:
+ case OPT_ERR:
+ return 0;
+ }
}
#ifndef OPENSSL_NO_EC