Skip to content

Commit ec0ff29

Browse files
committed
x509storeissuer: add -T option to specify the run time
Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent 2c93060 commit ec0ff29

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

source/x509storeissuer.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define RUN_TIME 5
2828
#define NONCE_CFG "file:servercert.pem"
2929

30+
static size_t timeout_us = RUN_TIME * 1000000;
31+
3032
enum verbosity {
3133
VERBOSITY_TERSE,
3234
VERBOSITY_DEFAULT,
@@ -179,16 +181,37 @@ static void
179181
usage(char * const argv[])
180182
{
181183
fprintf(stderr,
182-
"Usage: %s [-t] [-v] [-n nonce_type:type_args] certsdir threadcount\n"
184+
"Usage: %s [-t] [-v] [-T time] [-n nonce_type:type_args] "
185+
"certsdir threadcount\n"
183186
"\t-t\tTerse output\n"
184187
"\t-v\tVerbose output. Multiple usage increases verbosity.\n"
188+
"\t-T\tTimeout for the test run in seconds,\n"
189+
"\t\tcan be fractional. Default: "
190+
OPENSSL_MSTR(RUN_TIME) "\n"
185191
"\t-n\tNonce configuration, supported options:\n"
186192
"\t\t\tfile:PATH - load nonce certificate from PATH;\n"
187193
"\t\t\tif PATH is relative, the provided certsdir's are searched.\n"
188194
"\t\tDefault: " NONCE_CFG "\n"
189195
, basename(argv[0]));
190196
}
191197

198+
static size_t
199+
parse_timeout(const char * const optarg)
200+
{
201+
char *endptr = NULL;
202+
double timeout_s;
203+
204+
timeout_s = strtod(optarg, &endptr);
205+
206+
if (endptr == NULL || *endptr != '\0' || timeout_s < 0)
207+
errx(EXIT_FAILURE, "incorrect timeout value: \"%s\"");
208+
209+
if (timeout_s > SIZE_MAX / 1000000)
210+
errx(EXIT_FAILURE, "timeout is too large: %f", timeout_s);
211+
212+
return timeout_s * 1e6;
213+
}
214+
192215
/**
193216
* Parse nonce configuration string. Currently supported formats:
194217
* * "file:PATH" - where PATH is either a relative path (that will be then
@@ -241,7 +264,7 @@ main(int argc, char *argv[])
241264

242265
parse_nonce_cfg(NONCE_CFG, &nonce_cfg);
243266

244-
while ((opt = getopt(argc, argv, "tvn:")) != -1) {
267+
while ((opt = getopt(argc, argv, "tvT:n:")) != -1) {
245268
switch (opt) {
246269
case 't': /* terse */
247270
verbosity = VERBOSITY_TERSE;
@@ -254,6 +277,9 @@ main(int argc, char *argv[])
254277
verbosity++;
255278
}
256279
break;
280+
case 'T': /* timeout */
281+
timeout_us = parse_timeout(optarg);
282+
break;
257283
case 'n': /* nonce */
258284
parse_nonce_cfg(optarg, &nonce_cfg);
259285
break;
@@ -292,7 +318,7 @@ main(int argc, char *argv[])
292318
if (x509_nonce == NULL)
293319
errx(EXIT_FAILURE, "Unable to create the nonce X509 object");
294320

295-
max_time = ossl_time_add(ossl_time_now(), ossl_seconds2time(RUN_TIME));
321+
max_time = ossl_time_add(ossl_time_now(), ossl_us2time(timeout_us));
296322

297323
if (!perflib_run_multi_thread_test(do_x509storeissuer, threadcount, &duration))
298324
errx(EXIT_FAILURE, "Failed to run the test");
@@ -303,7 +329,7 @@ main(int argc, char *argv[])
303329
for (i = 0; i < threadcount; i++)
304330
total_count += counts[i];
305331

306-
avcalltime = (double)RUN_TIME * 1e6 * threadcount / total_count;
332+
avcalltime = (double)timeout_us * threadcount / total_count;
307333

308334
switch (verbosity) {
309335
case VERBOSITY_TERSE:

0 commit comments

Comments
 (0)