Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix common test framework options #10975

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/asynciotest.c
Expand Up @@ -397,6 +397,11 @@ OPT_TEST_DECLARE_USAGE("certname privkey\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/clienthellotest.c
Expand Up @@ -250,6 +250,11 @@ OPT_TEST_DECLARE_USAGE("sessionfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(sessionfile = test_get_argument(0)))
return 0;

Expand Down
5 changes: 5 additions & 0 deletions test/cmp_msg_test.c
Expand Up @@ -538,6 +538,11 @@ void cleanup_tests(void)

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(server_cert_f = test_get_argument(0))
|| !TEST_ptr(pkcs10_f = test_get_argument(1))) {
TEST_error("usage: cmp_msg_test server.crt pkcs10.der\n");
Expand Down
5 changes: 5 additions & 0 deletions test/cmp_protect_test.c
Expand Up @@ -455,6 +455,11 @@ int setup_tests(void)
char *root_f;
char *intermediate_f;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
if (!TEST_ptr(server_f = test_get_argument(0))
|| !TEST_ptr(ir_protected_f = test_get_argument(1))
Expand Down
5 changes: 5 additions & 0 deletions test/cmsapitest.c
Expand Up @@ -65,6 +65,11 @@ int setup_tests(void)
char *certin = NULL, *privkeyin = NULL;
BIO *certbio = NULL, *privkeybio = NULL;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(certin = test_get_argument(0))
|| !TEST_ptr(privkeyin = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/d2i_test.c
Expand Up @@ -127,6 +127,11 @@ int setup_tests(void)
{"compare", ASN1_COMPARE}
};

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(test_type_name = test_get_argument(0))
|| !TEST_ptr(expected_error_string = test_get_argument(1))
|| !TEST_ptr(test_file = test_get_argument(2)))
Expand Down
5 changes: 5 additions & 0 deletions test/danetest.c
Expand Up @@ -413,6 +413,11 @@ OPT_TEST_DECLARE_USAGE("basedomain CAfile tlsafile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(basedomain = test_get_argument(0))
|| !TEST_ptr(CAfile = test_get_argument(1))
|| !TEST_ptr(tlsafile = test_get_argument(2)))
Expand Down
5 changes: 5 additions & 0 deletions test/dtlstest.c
Expand Up @@ -332,6 +332,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
8 changes: 7 additions & 1 deletion test/evp_test.c
Expand Up @@ -3258,8 +3258,14 @@ OPT_TEST_DECLARE_USAGE("file...\n")

int setup_tests(void)
{
size_t n = test_get_argument_count();
size_t n;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

n = test_get_argument_count();
if (n == 0)
return 0;

Expand Down
5 changes: 5 additions & 0 deletions test/fatalerrtest.c
Expand Up @@ -86,6 +86,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/gosttest.c
Expand Up @@ -82,6 +82,11 @@ OPT_TEST_DECLARE_USAGE("certfile1 privkeyfile1 certfile2 privkeyfile2\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert1 = test_get_argument(0))
|| !TEST_ptr(privkey1 = test_get_argument(1))
|| !TEST_ptr(cert2 = test_get_argument(2))
Expand Down
5 changes: 5 additions & 0 deletions test/ocspapitest.c
Expand Up @@ -215,6 +215,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(certstr = test_get_argument(0))
|| !TEST_ptr(privkeystr = test_get_argument(1)))
return 0;
Expand Down
8 changes: 7 additions & 1 deletion test/params_conversion_test.c
Expand Up @@ -328,8 +328,14 @@ OPT_TEST_DECLARE_USAGE("file...\n")

int setup_tests(void)
{
size_t n = test_get_argument_count();
size_t n;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

n = test_get_argument_count();
if (n == 0)
return 0;

Expand Down
5 changes: 5 additions & 0 deletions test/recordlentest.c
Expand Up @@ -185,6 +185,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/servername_test.c
Expand Up @@ -239,6 +239,11 @@ static int test_servername(int test)

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/ssl_test.c
Expand Up @@ -506,6 +506,11 @@ int setup_tests(void)
{
long num_tests;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(conf = NCONF_new(NULL))
/* argv[1] should point to the test conf file */
|| !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
Expand Down
5 changes: 5 additions & 0 deletions test/ssl_test_ctx_test.c
Expand Up @@ -244,6 +244,11 @@ OPT_TEST_DECLARE_USAGE("conf_file\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(conf = NCONF_new(NULL)))
return 0;
/* argument should point to test/ssl_test_ctx_test.conf */
Expand Down
5 changes: 5 additions & 0 deletions test/sslapitest.c
Expand Up @@ -6972,6 +6972,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile srpvfile tmpfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(certsdir = test_get_argument(0))
|| !TEST_ptr(srpvfile = test_get_argument(1))
|| !TEST_ptr(tmpfilename = test_get_argument(2)))
Expand Down
5 changes: 5 additions & 0 deletions test/sslbuffertest.c
Expand Up @@ -156,6 +156,11 @@ int setup_tests(void)
{
char *cert, *pkey;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(pkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/sslcorrupttest.c
Expand Up @@ -250,6 +250,11 @@ int setup_tests(void)
{
int n;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
6 changes: 6 additions & 0 deletions test/testutil.h
Expand Up @@ -193,6 +193,12 @@ char *test_get_argument(size_t n);
/* Return the number of additional non optional command line arguments */
size_t test_get_argument_count(void);

/*
* Skip over common test options. Should be called before calling
* test_get_argument()
*/
int test_skip_common_options(void);

/*
* Internal helpers. Test programs shouldn't use these directly, but should
* rather link to one of the helper main() methods.
Expand Down
15 changes: 15 additions & 0 deletions test/testutil/options.c
Expand Up @@ -15,6 +15,21 @@

static int used[100] = { 0 };

int test_skip_common_options(void)
{
OPTION_CHOICE_DEFAULT o;

while ((o = (OPTION_CHOICE_DEFAULT)opt_next()) != OPT_EOF) {
switch (o) {
case OPT_TEST_CASES:
break;
default:
case OPT_ERR:
return 0;
}
}
return 1;
}

size_t test_get_argument_count(void)
{
Expand Down
5 changes: 5 additions & 0 deletions test/tls13ccstest.c
Expand Up @@ -492,6 +492,11 @@ OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(cert = test_get_argument(0))
|| !TEST_ptr(privkey = test_get_argument(1)))
return 0;
Expand Down
5 changes: 5 additions & 0 deletions test/v3ext.c
Expand Up @@ -41,6 +41,11 @@ OPT_TEST_DECLARE_USAGE("cert.pem\n")

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(infile = test_get_argument(0)))
return 0;

Expand Down
5 changes: 5 additions & 0 deletions test/verify_extra_test.c
Expand Up @@ -263,6 +263,11 @@ static int test_req_sm2_id(void)

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(roots_f = test_get_argument(0))
|| !TEST_ptr(untrusted_f = test_get_argument(1))
|| !TEST_ptr(bad_f = test_get_argument(2))
Expand Down
5 changes: 5 additions & 0 deletions test/x509_check_cert_pkey_test.c
Expand Up @@ -122,6 +122,11 @@ const OPTIONS *test_get_options(void)

int setup_tests(void)
{
if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

if (!TEST_ptr(c = test_get_argument(0))
|| !TEST_ptr(k = test_get_argument(1))
|| !TEST_ptr(t = test_get_argument(2))
Expand Down
8 changes: 7 additions & 1 deletion test/x509_dup_cert_test.c
Expand Up @@ -37,8 +37,14 @@ OPT_TEST_DECLARE_USAGE("cert.pem...\n")

int setup_tests(void)
{
size_t n = test_get_argument_count();
size_t n;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

n = test_get_argument_count();
if (!TEST_int_gt(n, 0))
return 0;

Expand Down
9 changes: 8 additions & 1 deletion test/x509aux.c
Expand Up @@ -165,7 +165,14 @@ OPT_TEST_DECLARE_USAGE("certfile...\n")

int setup_tests(void)
{
size_t n = test_get_argument_count();
size_t n;

if (!test_skip_common_options()) {
TEST_error("Error parsing test options\n");
return 0;
}

n = test_get_argument_count();
if (n == 0)
return 0;

Expand Down