@@ -7351,16 +7351,9 @@ int main(int argc, char **argv) {
7351
7351
/* find random seed */
7352
7352
secp256k1_testrand_init (argc > 2 ? argv [2 ] : NULL );
7353
7353
7354
- /* initialize */
7355
- /* Make a writable copy of secp256k1_context_static in order to test the effect of API functions
7356
- that write to the context. The API does not support cloning the static context, so we use
7357
- memcpy instead. The user is not supposed to copy a context but we should still ensure that
7358
- the API functions handle copies of the static context gracefully. */
7359
- sttc = malloc (sizeof (* secp256k1_context_static ));
7360
- CHECK (sttc != NULL );
7361
- memcpy (sttc , secp256k1_context_static , sizeof (secp256k1_context ));
7362
- CHECK (!secp256k1_context_is_proper (sttc ));
7354
+ /*** Setup test environment ***/
7363
7355
7356
+ /* Create a global context available to all tests */
7364
7357
ctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
7365
7358
/* Randomize the context only with probability 15/16
7366
7359
to make sure we test without context randomization from time to time.
@@ -7370,23 +7363,41 @@ int main(int argc, char **argv) {
7370
7363
secp256k1_testrand256 (rand32 );
7371
7364
CHECK (secp256k1_context_randomize (ctx , rand32 ));
7372
7365
}
7366
+ /* Make a writable copy of secp256k1_context_static in order to test the effect of API functions
7367
+ that write to the context. The API does not support cloning the static context, so we use
7368
+ memcpy instead. The user is not supposed to copy a context but we should still ensure that
7369
+ the API functions handle copies of the static context gracefully. */
7370
+ sttc = malloc (sizeof (* secp256k1_context_static ));
7371
+ CHECK (sttc != NULL );
7372
+ memcpy (sttc , secp256k1_context_static , sizeof (secp256k1_context ));
7373
+ CHECK (!secp256k1_context_is_proper (sttc ));
7374
+
7375
+ /*** Run actual tests ***/
7373
7376
7377
+ /* selftest tests */
7374
7378
run_selftest_tests ();
7379
+
7380
+ /* context tests */
7375
7381
run_context_tests (0 );
7376
7382
run_context_tests (1 );
7377
7383
run_deprecated_context_flags_test ();
7384
+
7385
+ /* scratch tests */
7378
7386
run_scratch_tests ();
7379
7387
7388
+ /* randomness tests */
7380
7389
run_rand_bits ();
7381
7390
run_rand_int ();
7382
7391
7392
+ /* integer arithmetic tests */
7383
7393
#ifdef SECP256K1_WIDEMUL_INT128
7384
7394
run_int128_tests ();
7385
7395
#endif
7386
7396
run_ctz_tests ();
7387
7397
run_modinv_tests ();
7388
7398
run_inverse_tests ();
7389
7399
7400
+ /* hash tests */
7390
7401
run_sha256_known_output_tests ();
7391
7402
run_sha256_counter_tests ();
7392
7403
run_hmac_sha256_tests ();
@@ -7466,12 +7477,12 @@ int main(int argc, char **argv) {
7466
7477
7467
7478
run_cmov_tests ();
7468
7479
7469
- secp256k1_testrand_finish ();
7470
-
7471
- /* shutdown */
7480
+ /*** Tear down test environment ***/
7472
7481
free (sttc );
7473
7482
secp256k1_context_destroy (ctx );
7474
7483
7484
+ secp256k1_testrand_finish ();
7485
+
7475
7486
printf ("no problems found\n" );
7476
7487
return 0 ;
7477
7488
}
0 commit comments