return ret;
}
-OPT_TEST_DECLARE_USAGE("conf_file modulename [fips_conf_file]\n")
+#define USAGE "conf_file module_name [module_conf_file]\n"
+OPT_TEST_DECLARE_USAGE(USAGE)
int setup_tests(void)
{
long num_tests;
- const char *modulename;
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
/* argv[1] should point to the test conf file */
|| !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
|| !TEST_int_ne(NCONF_get_number_e(conf, NULL, "num_tests",
- &num_tests), 0))
+ &num_tests), 0)) {
+ TEST_error("usage: ssl_test %s", USAGE);
return 0;
+ }
- if (!TEST_ptr(modulename = test_get_argument(1)))
+ if (!test_get_libctx(&libctx, &defctxnull, &thisprov, 1, USAGE))
return 0;
- if (strcmp(modulename, "none") != 0) {
- const char *configfile = test_get_argument(2);
-
- defctxnull = OSSL_PROVIDER_load(NULL, "null");
- libctx = OPENSSL_CTX_new();
- if (!TEST_ptr(libctx))
- return 0;
-
- if (configfile != NULL
- && !TEST_true(OPENSSL_CTX_load_config(libctx, configfile)))
- return 0;
-
- thisprov = OSSL_PROVIDER_load(libctx, modulename);
- if (!TEST_ptr(thisprov))
- return 0;
- }
-
ADD_ALL_TESTS(test_handshake, (int)num_tests);
return 1;
}
#ifndef OSSL_TESTUTIL_H
# define OSSL_TESTUTIL_H
-#include <stdarg.h>
+# include <stdarg.h>
-#include <openssl/err.h>
-#include <openssl/e_os2.h>
-#include <openssl/bn.h>
-#include "opt.h"
+# include <openssl/provider.h>
+# include <openssl/err.h>
+# include <openssl/e_os2.h>
+# include <openssl/bn.h>
+# include "opt.h"
/*-
* Simple unit tests should implement setup_tests().
/* The default test enum which should be common to all tests */
-#define OPT_TEST_ENUM \
+# define OPT_TEST_ENUM \
OPT_TEST_HELP = 500, \
OPT_TEST_LIST, \
OPT_TEST_SINGLE, \
OPT_TEST_SEED
/* The Default test OPTIONS common to all tests (without a usage string) */
-#define OPT_TEST_OPTIONS \
+# 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" }, \
{ "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) \
+# 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 \
+# 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 \
+# define OPT_TEST_CASES \
OPT_TEST_HELP: \
case OPT_TEST_LIST: \
case OPT_TEST_SINGLE: \
* 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) \
+# define OPT_TEST_DECLARE_USAGE(usage_str) \
const OPTIONS *test_get_options(void) \
{ \
enum { OPT_TEST_ENUM }; \
*/
int test_skip_common_options(void);
+int test_get_libctx(OPENSSL_CTX **libctx,
+ OSSL_PROVIDER **default_null_provider,
+ OSSL_PROVIDER **provider, int argn, const char *usage);
+
/*
* Internal helpers. Test programs shouldn't use these directly, but should
* rather link to one of the helper main() methods.
* Test assumption verification helpers.
*/
-#define PRINTF_FORMAT(a, b)
-#if defined(__GNUC__) && defined(__STDC_VERSION__)
+# define PRINTF_FORMAT(a, b)
+# if defined(__GNUC__) && defined(__STDC_VERSION__)
/*
* Because we support the 'z' modifier, which made its appearance in C99,
* we can't use __attribute__ with pre C99 dialects.
*/
-# if __STDC_VERSION__ >= 199901L
-# undef PRINTF_FORMAT
-# define PRINTF_FORMAT(a, b) __attribute__ ((format(printf, a, b)))
+# if __STDC_VERSION__ >= 199901L
+# undef PRINTF_FORMAT
+# define PRINTF_FORMAT(a, b) __attribute__ ((format(printf, a, b)))
+# endif
# endif
-#endif
# define DECLARE_COMPARISON(type, name, opname) \
int test_ ## name ## _ ## opname(const char *, int, \
/*
* Utilities to parse a test file.
*/
-#define TESTMAXPAIRS 150
+# define TESTMAXPAIRS 150
typedef struct pair_st {
char *key;
--- /dev/null
+/*
+ * Copyright 2018-2020 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
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include "../testutil.h"
+#include <openssl/provider.h>
+#include <string.h>
+
+int test_get_libctx(OPENSSL_CTX **libctx,
+ OSSL_PROVIDER **default_null_provider,
+ OSSL_PROVIDER **provider, int argn, const char *usage)
+{
+ const char *module_name;
+
+ if (!TEST_ptr(module_name = test_get_argument(argn))) {
+ TEST_error("usage: <prog> %s", usage);
+ return 0;
+ }
+ if (strcmp(module_name, "none") != 0) {
+ const char *config_fname = test_get_argument(argn + 1);
+
+ *default_null_provider = OSSL_PROVIDER_load(NULL, "null");
+ *libctx = OPENSSL_CTX_new();
+ if (!TEST_ptr(*libctx)) {
+ TEST_error("Failed to create libctx\n");
+ goto err;
+ }
+
+ if (config_fname != NULL
+ && !TEST_true(OPENSSL_CTX_load_config(*libctx, config_fname))) {
+ TEST_error("Error loading config file %s\n", config_fname);
+ goto err;
+ }
+
+ *provider = OSSL_PROVIDER_load(*libctx, module_name);
+ if (!TEST_ptr(*provider)) {
+ TEST_error("Failed to load provider %s\n", module_name);
+ goto err;
+ }
+ }
+ return 1;
+
+ err:
+ ERR_print_errors_fp(stderr);
+ return 0;
+}