diff options
author | Richard Levitte <levitte@openssl.org> | 2019-07-17 11:34:14 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-07-26 18:14:41 +0200 |
commit | 3b5d61f4721f91b5f31a8d3b935f9b3cf4c27644 (patch) | |
tree | cfeace28e27f33fc806b5c31b60f1a669b825a78 /test/evp_test.c | |
parent | Add functions to see if a provider is available for use. (diff) | |
download | openssl-3b5d61f4721f91b5f31a8d3b935f9b3cf4c27644.tar.xz openssl-3b5d61f4721f91b5f31a8d3b935f9b3cf4c27644.zip |
test/evp_test.c: modify to use OSSL_PROVIDER_available()
This changes the stanza format used so far. Some test stanza had the
following line, only possible for digests:
Legacy = 1
These have been traded for the following:
Availablein = legacy
That line is globally available in all test stanza and can be used to
tell what providers a certain algorithm may be available in. Only one
provider needs to match, so one might have something like this for
some tests:
Availablein = default fips
This means that one of those providers must be available for the test
stanza to be performed.
If the providers mentioned for a stanza aren't available, the test is
skipped.
If this line isn't used in a stanza, the algorithm is assumed to be
available unconditionally (either by fallback providers, or providers
loaded by the config file).
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9398)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r-- | test/evp_test.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index 7e282031a1..5f2bcc623a 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -75,9 +75,6 @@ static int find_key(EVP_PKEY **ppk, const char *name, KEY_LIST *lst); static int parse_bin(const char *value, unsigned char **buf, size_t *buflen); -static OSSL_PROVIDER *defltprov = NULL; -static OSSL_PROVIDER *legacyprov = NULL; - /* * Compare two memory regions for equality, returning zero if they differ. * However, if there is expected to be an error and the actual error @@ -373,11 +370,6 @@ static int digest_test_parse(EVP_TEST *t, return evp_test_buffer_set_count(value, mdata->input); if (strcmp(keyword, "Ncopy") == 0) return evp_test_buffer_ncopy(value, mdata->input); - if (strcmp(keyword, "Legacy") == 0) { - if (legacyprov == NULL) - t->skip = 1; - return 1; - } return 0; } @@ -2900,6 +2892,33 @@ static char *take_value(PAIR *pp) } /* + * Return 1 if one of the providers named in the string is available. + * The provider names are separated with whitespace. + * NOTE: destructive function, it inserts '\0' after each provider name. + */ +static int prov_available(char *providers) +{ + char *p; + int more = 1; + + while (more) { + for (; isspace(*providers); providers++) + continue; + if (*providers == '\0') + break; /* End of the road */ + for (p = providers; *p != '\0' && !isspace(*p); p++) + continue; + if (*p == '\0') + more = 0; + else + *p = '\0'; + if (OSSL_PROVIDER_available(NULL, providers)) + return 1; /* Found one */ + } + return 0; +} + +/* * Read and parse one test. Return 0 if failure, 1 if okay. */ static int parse(EVP_TEST *t) @@ -3029,6 +3048,14 @@ top: } for (pp++, i = 1; i < t->s.numpairs; pp++, i++) { + if (strcmp(pp->key, "Availablein") == 0) { + if (!prov_available(pp->value)) { + TEST_info("skipping, providers not available: %s:%d", + t->s.test_file, t->s.start); + t->skip = 1; + return 0; + } + } if (strcmp(pp->key, "Result") == 0) { if (t->expected_err != NULL) { TEST_info("Line %d: multiple result lines", t->s.curr); @@ -3106,23 +3133,6 @@ int setup_tests(void) if (n == 0) return 0; - defltprov = OSSL_PROVIDER_load(NULL, "default"); - if (!TEST_ptr(defltprov)) - return 0; -#ifndef NO_LEGACY_MODULE - legacyprov = OSSL_PROVIDER_load(NULL, "legacy"); - if (!TEST_ptr(legacyprov)) { - OSSL_PROVIDER_unload(defltprov); - return 0; - } -#endif /* NO_LEGACY_MODULE */ - ADD_ALL_TESTS(run_file_tests, n); return 1; } - -void cleanup_tests(void) -{ - OSSL_PROVIDER_unload(legacyprov); - OSSL_PROVIDER_unload(defltprov); -} |