Skip to content

Commit c855581

Browse files
committed
test, bench, precompute_ecmult: use EXIT_... constants for main return values
1 parent 965393f commit c855581

9 files changed

+28
-22
lines changed

src/bench.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
***********************************************************************/
66

77
#include <stdio.h>
8+
#include <stdlib.h>
89
#include <string.h>
910

1011
#include "../include/secp256k1.h"
@@ -188,11 +189,11 @@ int main(int argc, char** argv) {
188189
|| have_flag(argc, argv, "--help")
189190
|| have_flag(argc, argv, "help")) {
190191
help(default_iters);
191-
return 0;
192+
return EXIT_SUCCESS;
192193
} else if (invalid_args) {
193194
fprintf(stderr, "./bench: unrecognized argument.\n\n");
194195
help(default_iters);
195-
return 1;
196+
return EXIT_FAILURE;
196197
}
197198
}
198199

@@ -201,23 +202,23 @@ int main(int argc, char** argv) {
201202
if (have_flag(argc, argv, "ecdh")) {
202203
fprintf(stderr, "./bench: ECDH module not enabled.\n");
203204
fprintf(stderr, "Use ./configure --enable-module-ecdh.\n\n");
204-
return 1;
205+
return EXIT_FAILURE;
205206
}
206207
#endif
207208

208209
#ifndef ENABLE_MODULE_RECOVERY
209210
if (have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) {
210211
fprintf(stderr, "./bench: Public key recovery module not enabled.\n");
211212
fprintf(stderr, "Use ./configure --enable-module-recovery.\n\n");
212-
return 1;
213+
return EXIT_FAILURE;
213214
}
214215
#endif
215216

216217
#ifndef ENABLE_MODULE_SCHNORRSIG
217218
if (have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "schnorrsig_sign") || have_flag(argc, argv, "schnorrsig_verify")) {
218219
fprintf(stderr, "./bench: Schnorr signatures module not enabled.\n");
219220
fprintf(stderr, "Use ./configure --enable-module-schnorrsig.\n\n");
220-
return 1;
221+
return EXIT_FAILURE;
221222
}
222223
#endif
223224

@@ -227,7 +228,7 @@ int main(int argc, char** argv) {
227228
have_flag(argc, argv, "ellswift_ecdh")) {
228229
fprintf(stderr, "./bench: ElligatorSwift module not enabled.\n");
229230
fprintf(stderr, "Use ./configure --enable-module-ellswift.\n\n");
230-
return 1;
231+
return EXIT_FAILURE;
231232
}
232233
#endif
233234

@@ -275,5 +276,5 @@ int main(int argc, char** argv) {
275276
run_ellswift_bench(iters, argc, argv);
276277
#endif
277278

278-
return 0;
279+
return EXIT_SUCCESS;
279280
}

src/bench.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int64_t gettime_i64(void) {
2424
struct timespec tv;
2525
if (!timespec_get(&tv, TIME_UTC)) {
2626
fputs("timespec_get failed!", stderr);
27-
exit(1);
27+
exit(EXIT_FAILURE);
2828
}
2929
return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
3030
#else

src/bench_ecmult.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66
#include <stdio.h>
7+
#include <stdlib.h>
78

89
#include "secp256k1.c"
910
#include "../include/secp256k1.h"
@@ -287,7 +288,7 @@ int main(int argc, char **argv) {
287288
|| have_flag(argc, argv, "--help")
288289
|| have_flag(argc, argv, "help")) {
289290
help(argv);
290-
return 0;
291+
return EXIT_SUCCESS;
291292
} else if(have_flag(argc, argv, "pippenger_wnaf")) {
292293
printf("Using pippenger_wnaf:\n");
293294
data.ecmult_multi = secp256k1_ecmult_pippenger_batch_single;
@@ -299,7 +300,7 @@ int main(int argc, char **argv) {
299300
} else {
300301
fprintf(stderr, "%s: unrecognized argument '%s'.\n\n", argv[0], argv[1]);
301302
help(argv);
302-
return 1;
303+
return EXIT_FAILURE;
303304
}
304305
}
305306

@@ -363,5 +364,5 @@ int main(int argc, char **argv) {
363364
free(data.output);
364365
free(data.expected_output);
365366

366-
return(0);
367+
return EXIT_SUCCESS;
367368
}

src/bench_internal.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66
#include <stdio.h>
7+
#include <stdlib.h>
78

89
#include "secp256k1.c"
910
#include "../include/secp256k1.h"
@@ -393,7 +394,7 @@ int main(int argc, char **argv) {
393394
|| have_flag(argc, argv, "--help")
394395
|| have_flag(argc, argv, "help")) {
395396
help(default_iters);
396-
return 0;
397+
return EXIT_SUCCESS;
397398
}
398399
}
399400

@@ -432,5 +433,5 @@ int main(int argc, char **argv) {
432433

433434
if (d || have_flag(argc, argv, "context")) run_benchmark("context_create", bench_context, bench_setup, NULL, &data, 10, iters);
434435

435-
return 0;
436+
return EXIT_SUCCESS;
436437
}

src/ctime_tests.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
***********************************************************************/
66

77
#include <stdio.h>
8+
#include <stdlib.h>
89
#include <string.h>
910

1011
#include "../include/secp256k1.h"
@@ -49,7 +50,7 @@ int main(void) {
4950
if (!SECP256K1_CHECKMEM_RUNNING()) {
5051
fprintf(stderr, "This test can only usefully be run inside valgrind because it was not compiled under msan.\n");
5152
fprintf(stderr, "Usage: libtool --mode=execute valgrind ./ctime_tests\n");
52-
return 1;
53+
return EXIT_FAILURE;
5354
}
5455
ctx = secp256k1_context_create(SECP256K1_CONTEXT_DECLASSIFY);
5556
/** In theory, testing with a single secret input should be sufficient:
@@ -69,7 +70,7 @@ int main(void) {
6970
CHECK(ret);
7071

7172
secp256k1_context_destroy(ctx);
72-
return 0;
73+
return EXIT_SUCCESS;
7374
}
7475

7576
static void run_tests(secp256k1_context *ctx, unsigned char *key) {

src/precompute_ecmult.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <inttypes.h>
88
#include <stdio.h>
9+
#include <stdlib.h>
910

1011
#include "../include/secp256k1.h"
1112

@@ -62,7 +63,7 @@ int main(void) {
6263
fp = fopen(outfile, "w");
6364
if (fp == NULL) {
6465
fprintf(stderr, "Could not open %s for writing!\n", outfile);
65-
return -1;
66+
return EXIT_FAILURE;
6667
}
6768

6869
fprintf(fp, "/* This file was automatically generated by precompute_ecmult. */\n");
@@ -86,5 +87,5 @@ int main(void) {
8687
fprintf(fp, "#undef S\n");
8788
fclose(fp);
8889

89-
return 0;
90+
return EXIT_SUCCESS;
9091
}

src/precompute_ecmult_gen.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <inttypes.h>
88
#include <stdio.h>
9+
#include <stdlib.h>
910

1011
#include "../include/secp256k1.h"
1112

@@ -64,7 +65,7 @@ int main(int argc, char **argv) {
6465
fp = fopen(outfile, "w");
6566
if (fp == NULL) {
6667
fprintf(stderr, "Could not open %s for writing!\n", outfile);
67-
return -1;
68+
return EXIT_FAILURE;
6869
}
6970

7071
fprintf(fp, "/* This file was automatically generated by precompute_ecmult_gen. */\n");
@@ -96,5 +97,5 @@ int main(int argc, char **argv) {
9697
fprintf(fp, "#undef S\n");
9798
fclose(fp);
9899

99-
return 0;
100+
return EXIT_SUCCESS;
100101
}

src/tests.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7837,5 +7837,5 @@ int main(int argc, char **argv) {
78377837
testrand_finish();
78387838

78397839
printf("no problems found\n");
7840-
return 0;
7840+
return EXIT_SUCCESS;
78417841
}

src/tests_exhaustive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ int main(int argc, char** argv) {
383383
this_core = strtol(argv[4], NULL, 0);
384384
if (num_cores < 1 || this_core >= num_cores) {
385385
fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]);
386-
return 1;
386+
return EXIT_FAILURE;
387387
}
388388
printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1);
389389
}
@@ -462,5 +462,5 @@ int main(int argc, char** argv) {
462462
testrand_finish();
463463

464464
printf("no problems found\n");
465-
return 0;
465+
return EXIT_SUCCESS;
466466
}

0 commit comments

Comments
 (0)