Latest update.

This commit is contained in:
2019-02-12 03:52:27 +09:00
parent 225c12e45d
commit 6523a76e2e
67 changed files with 1604 additions and 968 deletions
+159 -20
View File
@@ -21,6 +21,7 @@
# define strdup _strdup
#endif
/*
* Declares the structures needed to register each test case function.
*/
@@ -36,14 +37,21 @@ typedef struct test_info {
static TEST_INFO all_tests[1024];
static int num_tests = 0;
static int show_list = 0;
static int single_test = -1;
static int single_iter = -1;
static int level = 0;
static int seed = 0;
/*
* A parameterised tests runs a loop of test cases.
* A parameterised test runs a loop of test cases.
* |num_test_cases| counts the total number of test cases
* across all tests.
*/
static int num_test_cases = 0;
static int process_shared_options(void);
void add_test(const char *test_case_name, int (*test_fn) (void))
{
assert(num_tests != OSSL_NELEM(all_tests));
@@ -66,8 +74,6 @@ void add_all_tests(const char *test_case_name, int(*test_fn)(int idx),
num_test_cases += num;
}
static int level = 0;
int subtest_level(void)
{
return level;
@@ -99,21 +105,26 @@ static int gcd(int a, int b)
return a;
}
void setup_test_framework(void)
static void set_seed(int s)
{
seed = s;
if (seed <= 0)
seed = (int)time(NULL);
test_printf_stdout("%*s# RAND SEED %d\n", subtest_level(), "", seed);
test_flush_stdout();
srand(seed);
}
int setup_test_framework(int argc, char *argv[])
{
char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
char *test_seed = getenv("OPENSSL_TEST_RAND_ORDER");
char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
level = TAP_levels != NULL ? 4 * atoi(TAP_levels) : 0;
if (test_seed != NULL) {
seed = atoi(test_seed);
if (seed <= 0)
seed = (int)time(NULL);
test_printf_stdout("%*s# RAND SEED %d\n", subtest_level(), "", seed);
test_flush_stdout();
srand(seed);
}
if (TAP_levels != NULL)
level = 4 * atoi(TAP_levels);
if (test_seed != NULL)
set_seed(atoi(test_seed));
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (should_report_leaks()) {
@@ -121,8 +132,115 @@ void setup_test_framework(void)
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
}
#endif
if (!opt_init(argc, argv, test_get_options()))
return 0;
return 1;
}
/*
* This can only be called after setup() has run, since num_tests and
* all_tests[] are setup at this point
*/
static int check_single_test_params(char *name, char *testname, char *itname)
{
if (name != NULL) {
int i;
for (i = 0; i < num_tests; ++i) {
if (strcmp(name, all_tests[i].test_case_name) == 0) {
single_test = 1 + i;
break;
}
}
if (i >= num_tests)
single_test = atoi(name);
}
/* if only iteration is specified, assume we want the first test */
if (single_test == -1 && single_iter != -1)
single_test = 1;
if (single_test != -1) {
if (single_test < 1 || single_test > num_tests) {
test_printf_stderr("Invalid -%s value "
"(Value must be a valid test name OR a value between %d..%d)\n",
testname, 1, num_tests);
return 0;
}
}
if (single_iter != -1) {
if (all_tests[single_test - 1].num == -1) {
test_printf_stderr("-%s option is not valid for test %d:%s\n",
itname,
single_test,
all_tests[single_test - 1].test_case_name);
return 0;
} else if (single_iter < 1
|| single_iter > all_tests[single_test - 1].num) {
test_printf_stderr("Invalid -%s value for test %d:%s\t"
"(Value must be in the range %d..%d)\n",
itname, single_test,
all_tests[single_test - 1].test_case_name,
1, all_tests[single_test - 1].num);
return 0;
}
}
return 1;
}
static int process_shared_options(void)
{
OPTION_CHOICE_DEFAULT o;
int value;
int ret = -1;
char *flag_test = "";
char *flag_iter = "";
char *testname = NULL;
opt_begin();
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
/* Ignore any test options at this level */
default:
break;
case OPT_ERR:
return ret;
case OPT_TEST_HELP:
opt_help(test_get_options());
return 0;
case OPT_TEST_LIST:
show_list = 1;
break;
case OPT_TEST_SINGLE:
flag_test = opt_flag();
testname = opt_arg();
break;
case OPT_TEST_ITERATION:
flag_iter = opt_flag();
if (!opt_int(opt_arg(), &single_iter))
goto end;
break;
case OPT_TEST_INDENT:
if (!opt_int(opt_arg(), &value))
goto end;
level = 4 * value;
break;
case OPT_TEST_SEED:
if (!opt_int(opt_arg(), &value))
goto end;
set_seed(value);
break;
}
}
if (!check_single_test_params(testname, flag_test, flag_iter))
goto end;
ret = 1;
end:
return ret;
}
int pulldown_test_framework(int ret)
{
set_test_title(NULL);
@@ -131,7 +249,6 @@ int pulldown_test_framework(int ret)
&& CRYPTO_mem_leaks_cb(openssl_error_cb, NULL) <= 0)
return EXIT_FAILURE;
#endif
return ret;
}
@@ -176,14 +293,21 @@ int run_tests(const char *test_prog_name)
int ii, i, jj, j, jstep;
int permute[OSSL_NELEM(all_tests)];
i = process_shared_options();
if (i == 0)
return EXIT_SUCCESS;
if (i == -1)
return EXIT_FAILURE;
if (num_tests < 1) {
test_printf_stdout("%*s1..0 # Skipped: %s\n", level, "",
test_prog_name);
} else {
} else if (show_list == 0 && single_test == -1) {
if (level > 0)
test_printf_stdout("%*s# Subtest: %s\n", level, "", test_prog_name);
test_printf_stdout("%*s1..%d\n", level, "", num_tests);
}
test_flush_stdout();
for (i = 0; i < num_tests; i++)
@@ -198,12 +322,25 @@ int run_tests(const char *test_prog_name)
for (ii = 0; ii != num_tests; ++ii) {
i = permute[ii];
if (all_tests[i].num == -1) {
if (single_test != -1 && ((i+1) != single_test)) {
continue;
}
else if (show_list) {
if (all_tests[i].num != -1) {
test_printf_stdout("%d - %s (%d..%d)\n", ii + 1,
all_tests[i].test_case_name, 1,
all_tests[i].num);
} else {
test_printf_stdout("%d - %s\n", ii + 1,
all_tests[i].test_case_name);
}
test_flush_stdout();
} else if (all_tests[i].num == -1) {
int ret = 0;
set_test_title(all_tests[i].test_case_name);
ret = all_tests[i].test_fn();
verdict = 1;
if (!ret) {
verdict = 0;
@@ -215,7 +352,7 @@ int run_tests(const char *test_prog_name)
int num_failed_inner = 0;
level += 4;
if (all_tests[i].subtest) {
if (all_tests[i].subtest && single_iter == -1) {
test_printf_stdout("%*s# Subtest: %s\n", level, "",
all_tests[i].test_case_name);
test_printf_stdout("%*s%d..%d\n", level, "", 1,
@@ -235,6 +372,8 @@ int run_tests(const char *test_prog_name)
int ret;
j = (j + jstep) % all_tests[i].num;
if (single_iter != -1 && ((jj + 1) != single_iter))
continue;
set_test_title(NULL);
ret = all_tests[i].param_test_fn(j);
+10 -76
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2016-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
@@ -8,28 +8,9 @@
*/
#include "../testutil.h"
#include "internal/nelem.h"
#include "output.h"
#include "tu_local.h"
#include <string.h>
static size_t arg_count;
static char **args;
static unsigned char arg_used[1000];
static void check_arg_usage(void)
{
size_t i, n = arg_count < OSSL_NELEM(arg_used) ? arg_count
: OSSL_NELEM(arg_used);
for (i = 0; i < n; i++)
if (!arg_used[i+1])
test_printf_stderr("Warning ignored command-line argument %zu: %s\n",
i, args[i+1]);
if (i < arg_count)
test_printf_stderr("Warning arguments %zu and later unchecked\n", i);
}
int main(int argc, char *argv[])
{
@@ -42,65 +23,18 @@ int main(int argc, char *argv[])
return ret;
}
arg_count = argc - 1;
args = argv;
if (!setup_test_framework(argc, argv))
goto end;
setup_test_framework();
if (setup_tests())
if (setup_tests()) {
ret = run_tests(argv[0]);
cleanup_tests();
check_arg_usage();
cleanup_tests();
opt_check_usage();
} else {
opt_help(test_get_options());
}
end:
ret = pulldown_test_framework(ret);
test_close_streams();
return ret;
}
const char *test_get_program_name(void)
{
return args[0];
}
char *test_get_argument(size_t n)
{
if (n > arg_count)
return NULL;
if (n + 1 < OSSL_NELEM(arg_used))
arg_used[n + 1] = 1;
return args[n + 1];
}
size_t test_get_argument_count(void)
{
return arg_count;
}
int test_has_option(const char *option)
{
size_t i;
for (i = 1; i <= arg_count; i++)
if (strcmp(args[i], option) == 0) {
arg_used[i] = 1;
return 1;
}
return 0;
}
const char *test_get_option_argument(const char *option)
{
size_t i, n = strlen(option);
for (i = 1; i <= arg_count; i++)
if (strncmp(args[i], option, n) == 0) {
arg_used[i] = 1;
if (args[i][n] == '\0' && i + 1 < arg_count) {
arg_used[++i] = 1;
return args[i];
}
return args[i] + n;
}
return NULL;
}
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (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 "internal/nelem.h"
#include "tu_local.h"
#include "output.h"
static int used[100] = { 0 };
size_t test_get_argument_count(void)
{
return opt_num_rest();
}
char *test_get_argument(size_t n)
{
char **argv = opt_rest();
OPENSSL_assert(n < sizeof(used));
if ((int)n >= opt_num_rest() || argv == NULL)
return NULL;
used[n] = 1;
return argv[n];
}
void opt_check_usage(void)
{
int i;
char **argv = opt_rest();
int n, arg_count = opt_num_rest();
if (arg_count > (int)OSSL_NELEM(used))
n = (int)OSSL_NELEM(used);
else
n = arg_count;
for (i = 0; i < n; i++) {
if (used[i] == 0)
test_printf_stderr("Warning ignored command-line argument %d: %s\n",
i, argv[i]);
}
if (i < arg_count)
test_printf_stderr("Warning arguments %d and later unchecked\n", i);
}
int opt_printf_stderr(const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = test_vprintf_stderr(fmt, ap);
va_end(ap);
return ret;
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (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 "tu_local.h"
/* An overridable list of command line options */
const OPTIONS *test_get_options(void)
{
static const OPTIONS default_options[] = {
OPT_TEST_OPTIONS_DEFAULT_USAGE,
{ NULL }
};
return default_options;
}
+10 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2017-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
@@ -44,8 +44,16 @@ void test_fail_memory_message(const char *prefix, const char *file,
const unsigned char *m1, size_t l1,
const unsigned char *m2, size_t l2);
void setup_test_framework(void);
__owur int setup_test_framework(int argc, char *argv[]);
__owur int pulldown_test_framework(int ret);
__owur int run_tests(const char *test_prog_name);
void set_test_title(const char *title);
typedef enum OPTION_choice_default {
OPT_ERR = -1,
OPT_EOF = 0,
OPT_TEST_ENUM
} OPTION_CHOICE_DEFAULT;
void opt_check_usage(void);