Skip to content

Commit 30034bc

Browse files
committed
tests: clear the warnings the drivers emit on a full rebuild
A forced full rebuild emits 205 warnings, every one of them from the test drivers; the production build and the seventeen cross builds emit none. A warm tree hides them, since they return only when a header changes, but every CI run is a clean build and prints all 205. A real warning arriving there is indistinguishable from the furniture. Two thirds is duplication. test_engine declared each rule by hand even though the macro in engine_rules.h, included above it, already declares every one; test_render opened twenty-four functions with an extern for verbose, hardening_mode or map_mode, each defined at file scope in the orchestrator.c that file includes. Deleting 88 prototypes and 24 externs carries no risk in the useful direction: a symbol that was not already in scope fails the build rather than quietly changing meaning. The rest is statics a given translation unit does not call — helpers in the shared test header, which each driver uses a subset of, and the production files the drivers include, whose statics a test never reaches. Scoped pragmas at the nine include and definition sites keep that where it belongs, rather than annotating twenty-five places in production code for a test-only concern. ptdump_main is the same case, left without a prototype by the main redefinition that pulls it in. The full rebuild is now silent. The unit suite runs the same 685 cases, and the cross build and its test run stay clean across all seventeen targets.
1 parent 508764b commit 30034bc

6 files changed

Lines changed: 47 additions & 289 deletions

File tree

tests/test_engine.c

Lines changed: 3 additions & 265 deletions
Large diffs are not rendered by default.

tests/test_kasld.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
#endif
1919

2020
#include "../src/environment.c"
21+
/* The orchestrator is compiled into this test, so every static it does not
22+
* happen to call is unused here. Suppressed at the include rather than by
23+
* tagging the definitions: they are production code, and the property is a
24+
* fact about this translation unit, not about them. */
25+
#pragma GCC diagnostic push
26+
#pragma GCC diagnostic ignored "-Wunused-function"
27+
#pragma GCC diagnostic ignored "-Wunused-variable"
2128
#include "../src/orchestrator.c"
29+
#pragma GCC diagnostic pop
2230
/* The engine's value model, after orchestrator.c so its feature-test
2331
* macros are established first. engine_sync_authoritative projects
2432
* resolved estimates into `layout`, and reading an estimate means knowing
@@ -33,7 +41,10 @@
3341
#include "../src/render/markdown.c"
3442

3543
#include "../src/render/oneline.c"
44+
#pragma GCC diagnostic push
45+
#pragma GCC diagnostic ignored "-Wunused-function"
3646
#include "../src/render/text.c"
47+
#pragma GCC diagnostic pop
3748
#include "test_harness.h"
3849
#include "test_orch_common.h"
3950
#include "test_po_access.h"

tests/test_orch_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#ifndef KASLD_TEST_ORCH_COMMON_H
1313
#define KASLD_TEST_ORCH_COMMON_H
1414

15+
/* Helpers shared by the orchestrator tests; each includer uses a subset, so the
16+
* rest are unused in any one translation unit. */
17+
#pragma GCC diagnostic push
18+
#pragma GCC diagnostic ignored "-Wunused-function"
19+
1520
#include <assert.h>
1621
#include <limits.h>
1722

@@ -88,4 +93,6 @@ static const char *first_origin(const struct result *r) {
8893
return kasld_origin_name(origin_set_next(&r->origins, 0));
8994
}
9095

96+
#pragma GCC diagnostic pop
97+
9198
#endif /* KASLD_TEST_ORCH_COMMON_H */

tests/test_ptdump.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
* coupled-text arches, int main(int, char **) elsewhere), so it is not
2020
* forward-declared here — the include below defines the renamed function. */
2121
#define main ptdump_main
22+
/* No prototype for the renamed main: its signature is arch-dependent, as the
23+
* note above says, so there is nothing portable to declare it as. */
24+
#pragma GCC diagnostic push
25+
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
2226
#include "../src/components/ptdump_kernel_page_tables.c"
27+
#pragma GCC diagnostic pop
2328
#undef main
2429

2530
#include "test_harness.h"

tests/test_render.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
// <bcoles@gmail.com>
1515

1616
#include "../src/environment.c"
17+
/* The orchestrator is compiled into this test, so every static it does not
18+
* happen to call is unused here. Suppressed at the include rather than by
19+
* tagging the definitions: they are production code, and the property is a
20+
* fact about this translation unit, not about them. */
21+
#pragma GCC diagnostic push
22+
#pragma GCC diagnostic ignored "-Wunused-function"
23+
#pragma GCC diagnostic ignored "-Wunused-variable"
1724
#include "../src/orchestrator.c"
25+
#pragma GCC diagnostic pop
1826
/* The engine's value model, after orchestrator.c so its feature-test
1927
* macros are established first. engine_sync_authoritative projects
2028
* resolved estimates into `layout`, and reading an estimate means knowing
@@ -23,7 +31,10 @@
2331
#include "../src/estimate.c"
2432
#include "../src/quantities.c"
2533
#include "../src/region_info.c"
34+
#pragma GCC diagnostic push
35+
#pragma GCC diagnostic ignored "-Wunused-function"
2636
#include "../src/render.c"
37+
#pragma GCC diagnostic pop
2738
#include "../src/render/hardening.c"
2839
#include "../src/render/json.c"
2940
#include "../src/render/markdown.c"
@@ -371,7 +382,6 @@ static void test_render_json_with_rich_content(void) {
371382
* suggestion's enforcement surface and the hardware side-channel section. Raw
372383
* component stdout stays behind --verbose. */
373384
static void test_render_json_posture_always_present(void) {
374-
extern int hardening_mode, verbose;
375385
struct summary s;
376386
set_rich_render_state(&s);
377387
hardening_mode = 0; /* NOT in hardening mode */
@@ -411,7 +421,6 @@ static void test_render_likely_window(void) {
411421
reset_comp_logs();
412422
num_scalar_facts = 0;
413423
memset(&s, 0, sizeof(s));
414-
extern int verbose;
415424

416425
/* Guaranteed window is a range (no concrete vtext/ptext) with a tighter
417426
* speculative likely window. The likely sub-line/JSON read only s->kaslr,
@@ -474,7 +483,6 @@ static void test_render_vtext_speculative(void) {
474483
reset_comp_logs();
475484
num_scalar_facts = 0;
476485
memset(&s, 0, sizeof(s));
477-
extern int verbose;
478486
unsigned long sv_lo = layout.virt_kaslr_text_min,
479487
sv_hi = layout.virt_kaslr_text_max,
480488
sv_al = layout.virt_kaslr_align;
@@ -671,7 +679,6 @@ static void test_render_memory_likely_window(void) {
671679
reset_comp_logs();
672680
num_scalar_facts = 0;
673681
memset(&s, 0, sizeof(s));
674-
extern int verbose;
675682

676683
s.kaslr.vslots = 60; /* keep render_kaslr_text from early-returning */
677684
s.kaslr.vbits = 6;
@@ -1080,7 +1087,6 @@ static void test_render_memory_kaslr_uses_stored_slots(void) {
10801087
reset_comp_logs();
10811088
num_scalar_facts = 0;
10821089
memset(&s, 0, sizeof(s));
1083-
extern int verbose;
10841090

10851091
s.kaslr.vslots = 60; /* keep render_kaslr_text from early-returning */
10861092
s.kaslr.vbits = 6;
@@ -1170,7 +1176,6 @@ static void check_static_base_case(int posture_disabled, unsigned long lo,
11701176
const char *want_verdict, int json_mode,
11711177
int md_mode, int want_verbose) {
11721178
struct summary s;
1173-
extern int verbose;
11741179
reset_results();
11751180
reset_comp_logs();
11761181
num_scalar_facts = 0;
@@ -1304,7 +1309,6 @@ static void test_render_static_base_prefers_engine_window(void) {
13041309
* real addresses on the arch under test and cannot overflow a 32-bit word. */
13051310
static void test_render_map_directmap_extent_derived(void) {
13061311
struct summary s;
1307-
extern int verbose;
13081312
unsigned long sv_po = layout.virt_page_offset;
13091313
unsigned long sv_min = layout.virt_page_offset_min;
13101314
unsigned long sv_max = layout.virt_page_offset_max;
@@ -1407,7 +1411,6 @@ static void test_render_map_directmap_base_from_engine(void) {
14071411
reset_comp_logs();
14081412
num_scalar_facts = 0;
14091413
memset(&s, 0, sizeof(s));
1410-
extern int verbose;
14111414

14121415
unsigned long sv_po = layout.virt_page_offset;
14131416
unsigned long sv_min = layout.virt_page_offset_min;
@@ -1496,7 +1499,6 @@ static void test_render_map_overlapped_band_states_its_ceiling(void) {
14961499
reset_comp_logs();
14971500
num_scalar_facts = 0;
14981501
memset(&s, 0, sizeof(s));
1499-
extern int verbose;
15001502

15011503
unsigned long sv_ms = layout.modules_start;
15021504
unsigned long sv_me = layout.modules_end;
@@ -1573,8 +1575,6 @@ static void test_render_footer_hint_is_last(void) {
15731575
reset_comp_logs();
15741576
num_scalar_facts = 0;
15751577
memset(&s, 0, sizeof(s));
1576-
extern int verbose;
1577-
extern int map_mode;
15781578
s.kaslr.vslots = 60;
15791579
s.kaslr.vbits = 6;
15801580
verbose = 0;
@@ -1633,8 +1633,6 @@ static void test_render_phys_map_descends_strictly(void) {
16331633
reset_comp_logs();
16341634
num_scalar_facts = 0;
16351635
memset(&s, 0, sizeof(s));
1636-
extern int verbose;
1637-
extern int map_mode;
16381636
s.kaslr.vslots = 60;
16391637
s.kaslr.vbits = 6;
16401638
verbose = 0;
@@ -1691,8 +1689,6 @@ static void test_render_map_flag(void) {
16911689
reset_comp_logs();
16921690
num_scalar_facts = 0;
16931691
memset(&s, 0, sizeof(s));
1694-
extern int verbose;
1695-
extern int map_mode;
16961692
s.kaslr.vslots = 60;
16971693
s.kaslr.vbits = 6;
16981694

@@ -1737,7 +1733,6 @@ static void test_render_map_band_contains_its_leaks(void) {
17371733
reset_comp_logs();
17381734
num_scalar_facts = 0;
17391735
memset(&s, 0, sizeof(s));
1740-
extern int verbose;
17411736
unsigned long sv_max = layout.virt_image_base_max;
17421737

17431738
/* Narrow the base window so there is room between its ceiling and the next
@@ -1835,7 +1830,6 @@ static void test_render_map_ceiling_covers_high_mmio(void) {
18351830
reset_comp_logs();
18361831
num_scalar_facts = 0;
18371832
memset(&s, 0, sizeof(s));
1838-
extern int verbose;
18391833

18401834
/* Small, so both fit a 32-bit unsigned long; the property under test is
18411835
* only that the MMIO point sits above the leaked DRAM top. */
@@ -1907,7 +1901,6 @@ static void test_render_map_phys_buckets_partition(void) {
19071901
reset_comp_logs();
19081902
num_scalar_facts = 0;
19091903
memset(&s, 0, sizeof(s));
1910-
extern int verbose;
19111904

19121905
unsigned long sv_min = layout.phys_kaslr_text_min;
19131906
unsigned long sv_max = layout.phys_kaslr_text_max;
@@ -1985,7 +1978,6 @@ static void test_render_map_directmap_contains_text(void) {
19851978
reset_comp_logs();
19861979
num_scalar_facts = 0;
19871980
memset(&s, 0, sizeof(s));
1988-
extern int verbose;
19891981

19901982
unsigned long sv_po = layout.virt_page_offset;
19911983
/* The coupled default: the direct map begins exactly where the kernel image
@@ -2046,7 +2038,6 @@ static void test_render_map_draws_topmost_band_ceiling(void) {
20462038
reset_comp_logs();
20472039
num_scalar_facts = 0;
20482040
memset(&s, 0, sizeof(s));
2049-
extern int verbose;
20502041

20512042
unsigned long sv_po = layout.virt_page_offset;
20522043
unsigned long sv_tmin = layout.virt_image_base_min;
@@ -2160,7 +2151,6 @@ static void test_render_phys_ceiling_covers_bucket_footers(void) {
21602151
reset_comp_logs();
21612152
num_scalar_facts = 0;
21622153
memset(&s, 0, sizeof(s));
2163-
extern int verbose;
21642154

21652155
unsigned long sv_min = layout.phys_kaslr_text_min;
21662156
unsigned long sv_max = layout.phys_kaslr_text_max;
@@ -2205,7 +2195,6 @@ static void test_render_disabled_base_not_labeled_likely(void) {
22052195
reset_comp_logs();
22062196
num_scalar_facts = 0;
22072197
memset(&s, 0, sizeof(s));
2208-
extern int verbose;
22092198

22102199
s.kaslr.disabled = 1;
22112200
unsigned long vt = (unsigned long)KERNEL_VIRT_TEXT_DEFAULT;
@@ -2275,7 +2264,6 @@ static void test_render_leak_discloses_interior(void) {
22752264
static void test_render_markdown_with_rich_content(void) {
22762265
struct summary s;
22772266
set_rich_render_state(&s);
2278-
extern int verbose;
22792267
verbose = 1; /* per-record Evidence table (with the Pos column) */
22802268
set_render_mode(0, 0, 1);
22812269
capture_stdout(wrap_render_summary, &s);
@@ -2463,7 +2451,6 @@ static void test_render_oneline_entropy_and_failed(void) {
24632451
* compile-time-default remark must NOT appear, since the image did move. */
24642452
static void test_render_randomization_failed_posture(void) {
24652453
struct summary s;
2466-
extern int verbose;
24672454
/* The arch's own resolved window is left exactly as it is: this test is
24682455
about the posture line, not about any particular bounds, and narrowing
24692456
the window here would push the shared fixture's text result out of

tests/test_sysroot.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
#ifndef KASLD_TEST_SYSROOT_H
2929
#define KASLD_TEST_SYSROOT_H
3030

31+
/* Every includer uses a subset of the helpers below, so the rest are unused in
32+
* any given translation unit. Suppressed here rather than by tagging each
33+
* definition: the definitions are matched verbatim by tests/check-test-staging,
34+
* which reads their bodies to confirm the root is registered for removal, and
35+
* an attribute between `static` and the return type breaks that match. */
36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wunused-function"
38+
3139
#include <assert.h>
3240
#include <dirent.h>
3341
#include <stdio.h>
@@ -207,4 +215,6 @@ static void th_sysroot_fini(void) {
207215
th_sysroot_root[0] = '\0';
208216
}
209217

218+
#pragma GCC diagnostic pop
219+
210220
#endif /* KASLD_TEST_SYSROOT_H */

0 commit comments

Comments
 (0)