Skip to content

Commit 574fff4

Browse files
committed
tests: error when both env var and cmd line arg try to set iteration
`./tests a` results in the COUNT being set to 64 instead of erroring out as before. This is fixed in the next commit.
1 parent f46a31e commit 574fff4

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/tests.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7430,6 +7430,32 @@ static void run_cmov_tests(void) {
74307430
ge_storage_cmov_test();
74317431
}
74327432

7433+
static int process_args(int argc, char **argv) {
7434+
int is_count_arg_set = 0;
7435+
const char* env = getenv("SECP256K1_TEST_ITERS");
7436+
7437+
if (argc > 1) {
7438+
int count_arg = strtol(argv[1], NULL, 0);
7439+
if (count_arg > 0) {
7440+
is_count_arg_set = 1;
7441+
COUNT = count_arg;
7442+
}
7443+
}
7444+
7445+
if (env && strlen(env) > 0) {
7446+
COUNT = strtol(env, NULL, 0);
7447+
if (is_count_arg_set) {
7448+
fputs("Environment variable SECP256K1_TEST_ITERS and command line argument both try to set the iteration count.\n", stderr);
7449+
return 0;
7450+
}
7451+
if (COUNT <= 0) {
7452+
fputs("An iteration count of 0 or less is not allowed.\n", stderr);
7453+
return 0;
7454+
}
7455+
}
7456+
return 1;
7457+
}
7458+
74337459
static void help(void) {
74347460
printf("The command ./tests runs a test suite on the code base.\n");
74357461
printf("\n");
@@ -7463,17 +7489,8 @@ int main(int argc, char **argv) {
74637489
}
74647490
}
74657491

7466-
/* find iteration count */
7467-
if (argc > 1) {
7468-
COUNT = strtol(argv[1], NULL, 0);
7469-
} else {
7470-
const char* env = getenv("SECP256K1_TEST_ITERS");
7471-
if (env && strlen(env) > 0) {
7472-
COUNT = strtol(env, NULL, 0);
7473-
}
7474-
}
7475-
if (COUNT <= 0) {
7476-
fputs("An iteration count of 0 or less is not allowed.\n", stderr);
7492+
if (!process_args(argc, argv)) {
7493+
help();
74777494
return EXIT_FAILURE;
74787495
}
74797496
printf("test count = %i\n", COUNT);

0 commit comments

Comments
 (0)