summaryrefslogtreecommitdiff
path: root/test/testutil.h
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/testutil.h
parent9d5560331d86c6463e965321f774e4eed582ce0b (diff)
downloadopenssl-new-a43ce58f5569a160272c492c680f2e42d38ec769.tar.gz
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/testutil.h')
-rw-r--r--test/testutil.h95
1 files changed, 82 insertions, 13 deletions
diff --git a/test/testutil.h b/test/testutil.h
index 10a4b6a78f..9e08a42e5e 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -15,6 +15,7 @@
#include <openssl/err.h>
#include <openssl/e_os2.h>
#include <openssl/bn.h>
+#include "../apps/opt.h"
/*-
* Simple unit tests should implement setup_tests().
@@ -117,22 +118,80 @@
# define TEST_CASE_NAME __func__
# endif /* __STDC_VERSION__ */
+
+/* The default test enum which should be common to all tests */
+#define OPT_TEST_ENUM \
+ OPT_TEST_HELP = 500, \
+ OPT_TEST_LIST, \
+ OPT_TEST_SINGLE, \
+ OPT_TEST_ITERATION, \
+ OPT_TEST_INDENT, \
+ OPT_TEST_SEED
+
+/* The Default test OPTIONS common to all tests (without a usage string) */
+#define OPT_TEST_OPTIONS \
+ { OPT_HELP_STR, 1, '-', "Valid options are:\n" }, \
+ { "help", OPT_TEST_HELP, '-', "Display this summary" }, \
+ { "list", OPT_TEST_LIST, '-', "Display the list of tests available" }, \
+ { "test", OPT_TEST_SINGLE, 's', "Run a single test by id or name" }, \
+ { "iter", OPT_TEST_ITERATION, 'n', "Run a single iteration of a test" }, \
+ { "indent", OPT_TEST_INDENT,'p', "Number of tabs added to output" }, \
+ { "seed", OPT_TEST_SEED, 'n', "Seed value to randomize tests with" }
+
+/* The Default test OPTIONS common to all tests starting with an additional usage string */
+#define OPT_TEST_OPTIONS_WITH_EXTRA_USAGE(usage) \
+ { OPT_HELP_STR, 1, '-', "Usage: %s [options] " usage }, \
+ OPT_TEST_OPTIONS
+
+/* The Default test OPTIONS common to all tests with an default usage string */
+#define OPT_TEST_OPTIONS_DEFAULT_USAGE \
+ { OPT_HELP_STR, 1, '-', "Usage: %s [options]\n" }, \
+ OPT_TEST_OPTIONS
+
+/*
+ * Optional Cases that need to be ignored by the test app when using opt_next(),
+ * (that are handled internally).
+ */
+#define OPT_TEST_CASES \
+ OPT_TEST_HELP: \
+ case OPT_TEST_LIST: \
+ case OPT_TEST_SINGLE: \
+ case OPT_TEST_ITERATION: \
+ case OPT_TEST_INDENT: \
+ case OPT_TEST_SEED
+
+/*
+ * Tests that use test_get_argument() that dont have any additional options
+ * (i.e- dont use opt_next()) can use this to set the usage string.
+ * It embeds test_get_options() which gives default command line options for
+ * the test system.
+ *
+ * Tests that need to use opt_next() need to specify
+ * (1) test_get_options() containing an options[] (Which should include either
+ * OPT_TEST_OPTIONS_DEFAULT_USAGE OR
+ * OPT_TEST_OPTIONS_WITH_EXTRA_USAGE).
+ * (2) An enum outside the test_get_options() which contains OPT_TEST_ENUM, as
+ * well as the additional options that need to be handled.
+ * (3) case OPT_TEST_CASES: break; inside the opt_next() handling code.
+ */
+#define OPT_TEST_DECLARE_USAGE(usage_str) \
+const OPTIONS *test_get_options(void) \
+{ \
+ enum { OPT_TEST_ENUM }; \
+ static const OPTIONS options[] = { \
+ OPT_TEST_OPTIONS_WITH_EXTRA_USAGE(usage_str), \
+ { NULL } \
+ }; \
+ return options; \
+}
+
/*
- * Tests that need access to command line arguments should use the functions:
- * test_get_argument(int n) to get the nth argument, the first argument is
- * argument 0. This function returns NULL on error.
- * test_get_argument_count() to get the count of the arguments.
- * test_has_option(const char *) to check if the specified option was passed.
- * test_get_option_argument(const char *) to get an option which includes an
- * argument. NULL is returns if the option is not found.
- * const char *test_get_program_name(void) returns the name of the test program
- * being executed.
+ * Used to read non optional command line values that follow after the options.
+ * Returns NULL if there is no argument.
*/
-const char *test_get_program_name(void);
char *test_get_argument(size_t n);
+/* Return the number of additional non optional command line arguments */
size_t test_get_argument_count(void);
-int test_has_option(const char *option);
-const char *test_get_option_argument(const char *option);
/*
* Internal helpers. Test programs shouldn't use these directly, but should
@@ -150,6 +209,16 @@ void add_all_tests(const char *test_case_name, int (*test_fn)(int idx), int num,
int global_init(void);
int setup_tests(void);
void cleanup_tests(void);
+/*
+ * Used to supply test specific command line options,
+ * If non optional parameters are used, then the first entry in the OPTIONS[]
+ * should contain:
+ * { OPT_HELP_STR, 1, '-', "list of non optional commandline params\n"},
+ * The last entry should always be { NULL }.
+ *
+ * Run the test locally using './test/test_name -help' to check the usage.
+ */
+const OPTIONS *test_get_options(void);
/*
* Test assumption verification helpers.