xref: /freebsd-src/crypto/openssl/test/testutil/options.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  */
9*e0c4386eSCy Schubert 
10*e0c4386eSCy Schubert #include "../testutil.h"
11*e0c4386eSCy Schubert #include "internal/nelem.h"
12*e0c4386eSCy Schubert #include "tu_local.h"
13*e0c4386eSCy Schubert #include "output.h"
14*e0c4386eSCy Schubert 
15*e0c4386eSCy Schubert 
16*e0c4386eSCy Schubert static int used[100] = { 0 };
17*e0c4386eSCy Schubert 
test_skip_common_options(void)18*e0c4386eSCy Schubert int test_skip_common_options(void)
19*e0c4386eSCy Schubert {
20*e0c4386eSCy Schubert     OPTION_CHOICE_DEFAULT o;
21*e0c4386eSCy Schubert 
22*e0c4386eSCy Schubert     while ((o = (OPTION_CHOICE_DEFAULT)opt_next()) != OPT_EOF) {
23*e0c4386eSCy Schubert         switch (o) {
24*e0c4386eSCy Schubert         case OPT_TEST_CASES:
25*e0c4386eSCy Schubert            break;
26*e0c4386eSCy Schubert         default:
27*e0c4386eSCy Schubert         case OPT_ERR:
28*e0c4386eSCy Schubert             return 0;
29*e0c4386eSCy Schubert         }
30*e0c4386eSCy Schubert     }
31*e0c4386eSCy Schubert     return 1;
32*e0c4386eSCy Schubert }
33*e0c4386eSCy Schubert 
test_get_argument_count(void)34*e0c4386eSCy Schubert size_t test_get_argument_count(void)
35*e0c4386eSCy Schubert {
36*e0c4386eSCy Schubert     return opt_num_rest();
37*e0c4386eSCy Schubert }
38*e0c4386eSCy Schubert 
test_get_argument(size_t n)39*e0c4386eSCy Schubert char *test_get_argument(size_t n)
40*e0c4386eSCy Schubert {
41*e0c4386eSCy Schubert     char **argv = opt_rest();
42*e0c4386eSCy Schubert 
43*e0c4386eSCy Schubert     OPENSSL_assert(n < sizeof(used));
44*e0c4386eSCy Schubert     if ((int)n >= opt_num_rest() || argv == NULL)
45*e0c4386eSCy Schubert         return NULL;
46*e0c4386eSCy Schubert     used[n] = 1;
47*e0c4386eSCy Schubert     return argv[n];
48*e0c4386eSCy Schubert }
49*e0c4386eSCy Schubert 
opt_check_usage(void)50*e0c4386eSCy Schubert void opt_check_usage(void)
51*e0c4386eSCy Schubert {
52*e0c4386eSCy Schubert     int i;
53*e0c4386eSCy Schubert     char **argv = opt_rest();
54*e0c4386eSCy Schubert     int n, arg_count = opt_num_rest();
55*e0c4386eSCy Schubert 
56*e0c4386eSCy Schubert     if (arg_count > (int)OSSL_NELEM(used))
57*e0c4386eSCy Schubert         n = (int)OSSL_NELEM(used);
58*e0c4386eSCy Schubert     else
59*e0c4386eSCy Schubert         n = arg_count;
60*e0c4386eSCy Schubert     for (i = 0; i < n; i++) {
61*e0c4386eSCy Schubert         if (used[i] == 0)
62*e0c4386eSCy Schubert             test_printf_stderr("Warning ignored command-line argument %d: %s\n",
63*e0c4386eSCy Schubert                                i, argv[i]);
64*e0c4386eSCy Schubert     }
65*e0c4386eSCy Schubert     if (i < arg_count)
66*e0c4386eSCy Schubert         test_printf_stderr("Warning arguments %d and later unchecked\n", i);
67*e0c4386eSCy Schubert }
68*e0c4386eSCy Schubert 
opt_printf_stderr(const char * fmt,...)69*e0c4386eSCy Schubert int opt_printf_stderr(const char *fmt, ...)
70*e0c4386eSCy Schubert {
71*e0c4386eSCy Schubert     va_list ap;
72*e0c4386eSCy Schubert     int ret;
73*e0c4386eSCy Schubert 
74*e0c4386eSCy Schubert     va_start(ap, fmt);
75*e0c4386eSCy Schubert     ret = test_vprintf_stderr(fmt, ap);
76*e0c4386eSCy Schubert     va_end(ap);
77*e0c4386eSCy Schubert     return ret;
78*e0c4386eSCy Schubert }
79*e0c4386eSCy Schubert 
80