Skip to content

Commit fd51554

Browse files
hanno-beckermkannwischer
authored andcommitted
Tests: Add function prototype for main
Ordinarily, `main` is exempt from -Wmissing-prototypes. However, if it's re-#define'd, it isn't. To allow -Wmissing-prototypes in baremetal platforms wrapping `main`, this commit adds an explicit prototype for `main` in all test applications. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent d389c9c commit fd51554

10 files changed

Lines changed: 48 additions & 1 deletion

File tree

test/acvp/acvp_mlkem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ static MLK_NOINLINE void acvp_mlkem_keyGen_AFT(
192192
print_hex("dk", dk, sizeof(dk));
193193
}
194194

195+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
196+
#if defined(main)
197+
int main(int argc, char *argv[]);
198+
#endif
195199
int main(int argc, char *argv[])
196200
{
197201
acvp_mode mode;

test/bench/bench_components_mlkem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ static int bench(void)
362362
return 0;
363363
}
364364

365+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
366+
#if defined(main)
367+
int main(void);
368+
#endif
365369
int main(void)
366370
{
367371
enable_cyclecounter();

test/bench/bench_mlkem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ static int bench(void)
157157
return 0;
158158
}
159159

160+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
161+
#if defined(main)
162+
int main(void);
163+
#endif
160164
int main(void)
161165
{
162166
enable_cyclecounter();

test/src/gen_KAT.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ static void print_hex(const char *label, const uint8_t *data, size_t size)
4242
printf("\n");
4343
}
4444

45+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
46+
#if defined(main)
47+
int main(void);
48+
#endif
4549
int main(void)
4650
{
4751
unsigned i;

test/src/test_alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ static int test_check_sk_alloc_failure(test_ctx_t *ctx)
436436
} \
437437
} while (0)
438438

439+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
440+
#if defined(main)
441+
int main(void);
442+
#endif
439443
int main(void)
440444
{
441445
MLK_ALIGN uint8_t bump_buffer[MLK_BUMP_ALLOC_SIZE];

test/src/test_mlkem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ static int test_invalid_ciphertext(void)
160160
return 0;
161161
}
162162

163+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
164+
#if defined(main)
165+
int main(void);
166+
#endif
163167
int main(void)
164168
{
165169
unsigned i;

test/src/test_rng_fail.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ static int test_check_sk_rng_failure(void)
199199
return 0;
200200
}
201201

202+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
203+
#if defined(main)
204+
int main(void);
205+
#endif
202206
int main(void)
203207
{
204208
if (test_keygen_rng_failure() != 0)

test/src/test_stack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ static void test_decaps_only(void)
4343
(void)ret; /* Ignore return value - we only care about stack measurement */
4444
}
4545

46+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
47+
#if defined(main)
48+
int main(int argc, char *argv[]);
49+
#endif
4650
int main(int argc, char *argv[])
4751
{
4852
if (argc != 2)

test/src/test_unit.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#endif
3131
#endif /* !NUM_RANDOM_TESTS_REJ_UNIFORM */
3232

33+
/* Largest absolute constant-coefficient value the invNTT overflow test sweeps.
34+
* Defaults to a full INT16 sweep; an emulated target (e.g. QEMU) can lower it
35+
* to keep the run within its time budget. */
36+
#ifndef MAX_INTT_CONSTANT_COEFF
37+
#define MAX_INTT_CONSTANT_COEFF INT16_MAX
38+
#endif
39+
3340
/* Declarations for _c functions exposed by MLK_STATIC_TESTABLE= */
3441

3542
void mlk_poly_reduce_c(mlk_poly *r);
@@ -540,7 +547,7 @@ static int test_native_intt(void)
540547
*
541548
* Gradually increase absolute value to find smallest failure first.
542549
*/
543-
for (coeff = 0; coeff <= INT16_MAX; coeff++)
550+
for (coeff = 0; coeff <= MAX_INTT_CONSTANT_COEFF; coeff++)
544551
{
545552
generate_i16_array_constant(test_data, MLKEM_N, (int16_t)coeff);
546553
CHECK(test_intt_core(test_data, "intt_constant") == 0);
@@ -1216,6 +1223,10 @@ static int test_poly_rej_uniform_consistency(void)
12161223

12171224

12181225

1226+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
1227+
#if defined(main)
1228+
int main(void);
1229+
#endif
12191230
int main(void)
12201231
{
12211232
/* WARNING: Test-only

test/wycheproof/wycheproof_mlkem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ static void print_hex(const char *name, const unsigned char *raw, size_t len)
100100
printf("\n");
101101
}
102102

103+
/* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */
104+
#if defined(main)
105+
int main(int argc, char *argv[]);
106+
#endif
103107
int main(int argc, char *argv[])
104108
{
105109
if (argc < 2)

0 commit comments

Comments
 (0)