@@ -7430,9 +7430,13 @@ static void run_cmov_tests(void) {
7430
7430
ge_storage_cmov_test ();
7431
7431
}
7432
7432
7433
- static int process_args (int argc , char * * argv ) {
7433
+ static int process_args (int * all_enabled , int argc , char * * argv ) {
7434
7434
int is_count_arg_set = 0 ;
7435
7435
const char * env = getenv ("SECP256K1_TEST_ITERS" );
7436
+ char * valid_args [] = {"integer" , "hash" , "scalar" , "field" , "group" ,
7437
+ "ecmult" , "ecdh" , "ecdsa" , "recovery" , "extrakeys" ,
7438
+ "schnorrsig" };
7439
+ size_t valid_args_size = sizeof (valid_args )/sizeof (valid_args [0 ]);
7436
7440
7437
7441
if (argc > 1 ) {
7438
7442
int count_arg = strtol (argv [1 ], NULL , 0 );
@@ -7453,9 +7457,31 @@ static int process_args(int argc, char **argv) {
7453
7457
return 0 ;
7454
7458
}
7455
7459
}
7460
+
7461
+ * all_enabled = argc == 1 || (argc == 2 && is_count_arg_set );
7462
+
7463
+ if (is_count_arg_set ) {
7464
+ argc -- ;
7465
+ argv ++ ;
7466
+ }
7467
+ if (have_invalid_args (argc , argv , valid_args , valid_args_size )) {
7468
+ fprintf (stderr , "./tests: unrecognized argument.\n\n" );
7469
+ return 0 ;
7470
+ }
7471
+
7456
7472
return 1 ;
7457
7473
}
7458
7474
7475
+ static int module_unavailable (int argc , char * * argv , char * module ) {
7476
+ if (have_flag (argc , argv , module )) {
7477
+ fprintf (stderr , "./tests: %s module not enabled.\n" , module );
7478
+ fprintf (stderr , "Use ./configure --enable-module-%s.\n\n" , module );
7479
+ return 1 ;
7480
+ }
7481
+ return 0 ;
7482
+ }
7483
+
7484
+
7459
7485
static void help (void ) {
7460
7486
printf ("The command ./tests runs a test suite on the code base.\n" );
7461
7487
printf ("\n" );
@@ -7464,14 +7490,36 @@ static void help(void) {
7464
7490
printf ("setting the environment variable SECP256K1_TEST_ITERS or by providing\n" );
7465
7491
printf ("the iteration count as a command line argument.\n" );
7466
7492
printf ("\n" );
7493
+ printf ("By default, all tests are enabled.\n" );
7467
7494
printf ("Usage: ./tests [args]\n" );
7468
7495
printf ("Available arguments:\n" );
7469
7496
printf (" help : display this help message and exit\n" );
7470
7497
printf (" <count> : set the iteration count to <count>\n" );
7498
+ printf (" integer : enable integer tests\n" );
7499
+ printf (" hash : enable hash tests\n" );
7500
+ printf (" scalar : enable scalar tests\n" );
7501
+ printf (" field : enable field tests\n" );
7502
+ printf (" group : enable group tests\n" );
7503
+ printf (" ecmult : enable ecmult tests\n" );
7504
+ #ifdef ENABLE_MODULE_ECDH
7505
+ printf (" ecdh : enable ecdh tests\n" );
7506
+ #endif
7507
+ printf (" ecdsa : enable ecdsa tests\n" );
7508
+ #ifdef ENABLE_MODULE_RECOVERY
7509
+ printf (" recovery : enable recovery tests\n" );
7510
+ #endif
7511
+ #ifdef ENABLE_MODULE_EXTRAKEYS
7512
+ printf (" extrakeys : enable extrakeys tests\n" );
7513
+ #endif
7514
+ #ifdef ENABLE_MODULE_SCHNORRSIG
7515
+ printf (" schnorrsig : enable schnorrsig tests\n" );
7516
+ #endif
7471
7517
printf ("\n" );
7472
7518
}
7473
7519
7474
7520
int main (int argc , char * * argv ) {
7521
+ /* This variable is set to true if all tests are enabled by the user */
7522
+ int all_enabled ;
7475
7523
/* Disable buffering for stdout to improve reliability of getting
7476
7524
* diagnostic information. Happens right at the start of main because
7477
7525
* setbuf must be used before any other operation on the stream. */
@@ -7489,7 +7537,7 @@ int main(int argc, char **argv) {
7489
7537
}
7490
7538
}
7491
7539
7492
- if (!process_args (argc , argv )) {
7540
+ if (!process_args (& all_enabled , argc , argv )) {
7493
7541
help ();
7494
7542
return EXIT_FAILURE ;
7495
7543
}
@@ -7537,47 +7585,59 @@ int main(int argc, char **argv) {
7537
7585
run_rand_int ();
7538
7586
7539
7587
/* integer arithmetic tests */
7588
+ if (all_enabled || have_flag (argc , argv , "integer" )) {
7540
7589
#ifdef SECP256K1_WIDEMUL_INT128
7541
- run_int128_tests ();
7590
+ run_int128_tests ();
7542
7591
#endif
7543
- run_ctz_tests ();
7544
- run_modinv_tests ();
7545
- run_inverse_tests ();
7592
+ run_ctz_tests ();
7593
+ run_modinv_tests ();
7594
+ run_inverse_tests ();
7595
+ }
7546
7596
7547
7597
/* hash tests */
7548
- run_sha256_known_output_tests ();
7549
- run_sha256_counter_tests ();
7550
- run_hmac_sha256_tests ();
7551
- run_rfc6979_hmac_sha256_tests ();
7552
- run_tagged_sha256_tests ();
7598
+ if (all_enabled || have_flag (argc , argv , "hash" )) {
7599
+ run_sha256_known_output_tests ();
7600
+ run_sha256_counter_tests ();
7601
+ run_hmac_sha256_tests ();
7602
+ run_rfc6979_hmac_sha256_tests ();
7603
+ run_tagged_sha256_tests ();
7604
+ }
7553
7605
7554
7606
/* scalar tests */
7555
- run_scalar_tests ();
7607
+ if (all_enabled || have_flag (argc , argv , "scalar" )) {
7608
+ run_scalar_tests ();
7609
+ }
7556
7610
7557
7611
/* field tests */
7558
- run_field_half ();
7559
- run_field_misc ();
7560
- run_field_convert ();
7561
- run_fe_mul ();
7562
- run_sqr ();
7563
- run_sqrt ();
7612
+ if (all_enabled || have_flag (argc , argv , "field" )) {
7613
+ run_field_half ();
7614
+ run_field_misc ();
7615
+ run_field_convert ();
7616
+ run_fe_mul ();
7617
+ run_sqr ();
7618
+ run_sqrt ();
7619
+ }
7564
7620
7565
7621
/* group tests */
7566
- run_ge ();
7567
- run_gej ();
7568
- run_group_decompress ();
7622
+ if (all_enabled || have_flag (argc , argv , "group" )) {
7623
+ run_ge ();
7624
+ run_gej ();
7625
+ run_group_decompress ();
7626
+ }
7569
7627
7570
7628
/* ecmult tests */
7571
- run_ecmult_pre_g ();
7572
- run_wnaf ();
7573
- run_point_times_order ();
7574
- run_ecmult_near_split_bound ();
7575
- run_ecmult_chain ();
7576
- run_ecmult_constants ();
7577
- run_ecmult_gen_blind ();
7578
- run_ecmult_const_tests ();
7579
- run_ecmult_multi_tests ();
7580
- run_ec_combine ();
7629
+ if (all_enabled || have_flag (argc , argv , "ecmult" )) {
7630
+ run_ecmult_pre_g ();
7631
+ run_wnaf ();
7632
+ run_point_times_order ();
7633
+ run_ecmult_near_split_bound ();
7634
+ run_ecmult_chain ();
7635
+ run_ecmult_constants ();
7636
+ run_ecmult_gen_blind ();
7637
+ run_ecmult_const_tests ();
7638
+ run_ecmult_multi_tests ();
7639
+ run_ec_combine ();
7640
+ }
7581
7641
7582
7642
/* endomorphism tests */
7583
7643
run_endomorphism_tests ();
@@ -7593,29 +7653,59 @@ int main(int argc, char **argv) {
7593
7653
7594
7654
#ifdef ENABLE_MODULE_ECDH
7595
7655
/* ecdh tests */
7596
- run_ecdh_tests ();
7656
+ if (all_enabled || have_flag (argc , argv , "ecdh" )) {
7657
+ run_ecdh_tests ();
7658
+ }
7659
+ #endif
7660
+ #ifndef ENABLE_MODULE_ECDH
7661
+ if (module_unavailable (argc , argv , "ecdh" )) {
7662
+ return EXIT_FAILURE ;
7663
+ }
7597
7664
#endif
7598
7665
7599
7666
/* ecdsa tests */
7600
- run_ec_illegal_argument_tests ();
7601
- run_pubkey_comparison ();
7602
- run_random_pubkeys ();
7603
- run_ecdsa_der_parse ();
7604
- run_ecdsa_sign_verify ();
7605
- run_ecdsa_end_to_end ();
7606
- run_ecdsa_edge_cases ();
7667
+ if (all_enabled || have_flag (argc , argv , "ecdsa" )) {
7668
+ run_ec_illegal_argument_tests ();
7669
+ run_pubkey_comparison ();
7670
+ run_random_pubkeys ();
7671
+ run_ecdsa_der_parse ();
7672
+ run_ecdsa_sign_verify ();
7673
+ run_ecdsa_end_to_end ();
7674
+ run_ecdsa_edge_cases ();
7675
+ }
7607
7676
7608
7677
#ifdef ENABLE_MODULE_RECOVERY
7609
7678
/* ECDSA pubkey recovery tests */
7610
- run_recovery_tests ();
7679
+ if (all_enabled || have_flag (argc , argv , "recovery" )) {
7680
+ run_recovery_tests ();
7681
+ }
7682
+ #endif
7683
+ #ifndef ENABLE_MODULE_RECOVERY
7684
+ if (module_unavailable (argc , argv , "recovery" )) {
7685
+ return EXIT_FAILURE ;
7686
+ }
7611
7687
#endif
7612
7688
7613
7689
#ifdef ENABLE_MODULE_EXTRAKEYS
7614
- run_extrakeys_tests ();
7690
+ if (all_enabled || have_flag (argc , argv , "extrakeys" )) {
7691
+ run_extrakeys_tests ();
7692
+ }
7693
+ #endif
7694
+ #ifndef ENABLE_MODULE_EXTRAKEYS
7695
+ if (module_unavailable (argc , argv , "extrakeys" )) {
7696
+ return EXIT_FAILURE ;
7697
+ }
7615
7698
#endif
7616
7699
7617
7700
#ifdef ENABLE_MODULE_SCHNORRSIG
7618
- run_schnorrsig_tests ();
7701
+ if (all_enabled || have_flag (argc , argv , "schnorrsig" )) {
7702
+ run_schnorrsig_tests ();
7703
+ }
7704
+ #endif
7705
+ #ifndef ENABLE_MODULE_SCHNORRSIG
7706
+ if (module_unavailable (argc , argv , "schnorrsig" )) {
7707
+ return EXIT_FAILURE ;
7708
+ }
7619
7709
#endif
7620
7710
7621
7711
/* util tests */
0 commit comments