2727#define RUN_TIME 5
2828#define NONCE_CFG "file:servercert.pem"
2929
30+ static size_t timeout_us = RUN_TIME * 1000000 ;
31+
3032enum verbosity {
3133 VERBOSITY_TERSE ,
3234 VERBOSITY_DEFAULT ,
@@ -181,16 +183,37 @@ static void
181183usage (char * const argv [])
182184{
183185 fprintf (stderr ,
184- "Usage: %s [-t] [-v] [-n nonce_type:type_args] certsdir threadcount\n"
186+ "Usage: %s [-t] [-v] [-T time] [-n nonce_type:type_args] "
187+ "certsdir threadcount\n"
185188 "\t-t\tTerse output\n"
186189 "\t-v\tVerbose output. Multiple usage increases verbosity.\n"
190+ "\t-T\tTimeout for the test run in seconds,\n"
191+ "\t\tcan be fractional. Default: "
192+ OPENSSL_MSTR (RUN_TIME ) "\n"
187193 "\t-n\tNonce configuration, supported options:\n"
188194 "\t\t\tfile:PATH - load nonce certificate from PATH;\n"
189195 "\t\t\tif PATH is relative, the provided certsdir's are searched.\n"
190196 "\t\tDefault: " NONCE_CFG "\n"
191197 , basename (argv [0 ]));
192198}
193199
200+ static size_t
201+ parse_timeout (const char * const optarg )
202+ {
203+ char * endptr = NULL ;
204+ double timeout_s ;
205+
206+ timeout_s = strtod (optarg , & endptr );
207+
208+ if (endptr == NULL || * endptr != '\0' || timeout_s < 0 )
209+ errx (EXIT_FAILURE , "incorrect timeout value: \"%s\"" );
210+
211+ if (timeout_s > SIZE_MAX / 1000000 )
212+ errx (EXIT_FAILURE , "timeout is too large: %f" , timeout_s );
213+
214+ return (size_t )(timeout_s * 1e6 );
215+ }
216+
194217/**
195218 * Parse nonce configuration string. Currently supported formats:
196219 * * "file:PATH" - where PATH is either a relative path (that will be then
@@ -243,7 +266,7 @@ main(int argc, char *argv[])
243266
244267 parse_nonce_cfg (NONCE_CFG , & nonce_cfg );
245268
246- while ((opt = getopt (argc , argv , "tvn :" )) != -1 ) {
269+ while ((opt = getopt (argc , argv , "tvT:n :" )) != -1 ) {
247270 switch (opt ) {
248271 case 't' : /* terse */
249272 verbosity = VERBOSITY_TERSE ;
@@ -256,6 +279,9 @@ main(int argc, char *argv[])
256279 verbosity ++ ;
257280 }
258281 break ;
282+ case 'T' : /* timeout */
283+ timeout_us = parse_timeout (optarg );
284+ break ;
259285 case 'n' : /* nonce */
260286 parse_nonce_cfg (optarg , & nonce_cfg );
261287 break ;
@@ -294,7 +320,7 @@ main(int argc, char *argv[])
294320 if (x509_nonce == NULL )
295321 errx (EXIT_FAILURE , "Unable to create the nonce X509 object" );
296322
297- max_time = ossl_time_add (ossl_time_now (), ossl_seconds2time ( RUN_TIME ));
323+ max_time = ossl_time_add (ossl_time_now (), ossl_us2time ( timeout_us ));
298324
299325 if (!perflib_run_multi_thread_test (do_x509storeissuer , threadcount , & duration ))
300326 errx (EXIT_FAILURE , "Failed to run the test" );
@@ -305,7 +331,7 @@ main(int argc, char *argv[])
305331 for (i = 0 ; i < threadcount ; i ++ )
306332 total_count += counts [i ];
307333
308- avcalltime = (double )RUN_TIME * 1e6 * threadcount / total_count ;
334+ avcalltime = (double )timeout_us * threadcount / total_count ;
309335
310336 switch (verbosity ) {
311337 case VERBOSITY_TERSE :
0 commit comments