Skip to content

Commit fc90bb5

Browse files
refactor: Tidy up main()
1 parent f32a36f commit fc90bb5

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/tests.c

+23-12
Original file line numberDiff line numberDiff line change
@@ -7351,16 +7351,9 @@ int main(int argc, char **argv) {
73517351
/* find random seed */
73527352
secp256k1_testrand_init(argc > 2 ? argv[2] : NULL);
73537353

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 ***/
73637355

7356+
/* Create a global context available to all tests */
73647357
ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
73657358
/* Randomize the context only with probability 15/16
73667359
to make sure we test without context randomization from time to time.
@@ -7370,23 +7363,41 @@ int main(int argc, char **argv) {
73707363
secp256k1_testrand256(rand32);
73717364
CHECK(secp256k1_context_randomize(ctx, rand32));
73727365
}
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 ***/
73737376

7377+
/* selftest tests */
73747378
run_selftest_tests();
7379+
7380+
/* context tests */
73757381
run_context_tests(0);
73767382
run_context_tests(1);
73777383
run_deprecated_context_flags_test();
7384+
7385+
/* scratch tests */
73787386
run_scratch_tests();
73797387

7388+
/* randomness tests */
73807389
run_rand_bits();
73817390
run_rand_int();
73827391

7392+
/* integer arithmetic tests */
73837393
#ifdef SECP256K1_WIDEMUL_INT128
73847394
run_int128_tests();
73857395
#endif
73867396
run_ctz_tests();
73877397
run_modinv_tests();
73887398
run_inverse_tests();
73897399

7400+
/* hash tests */
73907401
run_sha256_known_output_tests();
73917402
run_sha256_counter_tests();
73927403
run_hmac_sha256_tests();
@@ -7466,12 +7477,12 @@ int main(int argc, char **argv) {
74667477

74677478
run_cmov_tests();
74687479

7469-
secp256k1_testrand_finish();
7470-
7471-
/* shutdown */
7480+
/*** Tear down test environment ***/
74727481
free(sttc);
74737482
secp256k1_context_destroy(ctx);
74747483

7484+
secp256k1_testrand_finish();
7485+
74757486
printf("no problems found\n");
74767487
return 0;
74777488
}

0 commit comments

Comments
 (0)