Skip to content

Commit 7ec13ad

Browse files
committed
fix(test-impact): mark conditionally registered runner suites CONDITIONAL on every selection path
A runner suite registered only under a preprocessor condition (the four coverage_* suites under `#if defined(CBM_TEST_COVERAGE) && !defined(_WIN32)` in tests/test_main.c) is absent from builds without that condition. The selection marked such a suite CONDITIONAL only on the per-registration path, and only when a registration of its own was conditional and contributed a reason. Every suite-level path (setup unknown or hit, suite-body, changed and rule triggers, inventory, rejected artifact) made the suite whole without it, and the runner registration's own condition was never recorded. PR CI on the x86 Linux gcc leg then failed with "the test selection names suites this build does not register: coverage_setup_success coverage_setup_uncertain" (DeusData#2679, DeusData#2680): the suite-body trigger and an incomplete setup row selected both suites whole without CONDITIONAL, so selection.py left them out of optional-suites.txt. The model now records whether a runner registration sits under a condition (conditional only when every site of the suite is), and the selection marks any selected conditionally registered suite whole with CONDITIONAL after every whole-suite path. Unconditionally registered suites keep the strict contract. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 354ccec commit 7ec13ad

4 files changed

Lines changed: 129 additions & 4 deletions

File tree

‎src/mcp/test_impact.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,11 @@ static void tm_add_runner_suite(tm_scan_t *sc, const tm_tok_t *name, bool perf)
630630
return;
631631
}
632632
m->runner = items;
633-
items[m->runner_count++] =
634-
(cbm_test_runner_suite_t){.name = copy, .perf = perf, .file = sc->file, .line = name->line};
633+
items[m->runner_count++] = (cbm_test_runner_suite_t){.name = copy,
634+
.perf = perf,
635+
.file = sc->file,
636+
.line = name->line,
637+
.conditional = sc->conditions > 0};
635638
}
636639

637640
/* Virtual preset records are immutable. Original configured records are kept
@@ -1407,11 +1410,14 @@ bool cbm_test_model_finish(cbm_test_model_t *m) {
14071410
}
14081411
if (m->runner_count > 1) {
14091412
qsort(m->runner, (size_t)m->runner_count, sizeof(*m->runner), tm_cmp_runner);
1410-
/* One entry per suite; it is a perf suite when any site says so. */
1413+
/* One entry per suite; it is a perf suite when any site says so, and
1414+
* conditional only when every site is. */
14111415
int kept = 0;
14121416
for (int i = 1; i < m->runner_count; i++) {
14131417
if (strcmp(m->runner[kept].name, m->runner[i].name) == 0) {
14141418
m->runner[kept].perf = m->runner[kept].perf || m->runner[i].perf;
1419+
m->runner[kept].conditional =
1420+
m->runner[kept].conditional && m->runner[i].conditional;
14151421
} else {
14161422
m->runner[++kept] = m->runner[i];
14171423
}

‎src/mcp/test_impact.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ typedef struct {
7171
bool perf;
7272
const char *file; /* the runner file that registers it */
7373
int line;
74+
/* Every site registers it under a preprocessor condition: some builds do
75+
* not register this suite at all. */
76+
bool conditional;
7477
} cbm_test_runner_suite_t;
7578

7679
typedef struct cbm_test_model cbm_test_model_t;

‎src/mcp/test_impact_select.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,14 @@ cbm_test_selection_t *cbm_test_select(const cbm_test_selection_input_t *input) {
290290
for (int i = 0; i < input->reach_count; i++)
291291
if (reach[i].row->changed && !reach[i].registered)
292292
return sl_full(result, CBM_TEST_SELECT_CHANGED_UNREGISTERED);
293-
for (int i = 0; i < runner_count; i++)
293+
for (int i = 0; i < runner_count; i++) {
294294
if (definition_counts[i] != 1 || !registration_counts[i])
295295
sl_whole(&result->suites[i], CBM_TEST_SELECT_INVENTORY_UNKNOWN);
296+
/* After every whole-suite path: a selected suite that some builds do
297+
* not register at all may be absent from the runner that executes it. */
298+
if ((result->suites[i].whole || result->suites[i].reasons) && runners[i].conditional)
299+
sl_whole(&result->suites[i], CBM_TEST_SELECT_CONDITIONAL);
300+
}
296301
/* A later registration can promote an earlier test's suite to whole.
297302
* Compact cases while the complete, sorted suite table is still present. */
298303
int used = 0;

‎tests/test_test_impact.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,33 @@ TEST(test_model_marks_what_is_under_a_condition) {
274274
PASS();
275275
}
276276

277+
/* A runner registration under a condition means some builds lack the suite.
278+
* A suite registered twice is conditional only when every site is. */
279+
TEST(test_model_marks_runner_suites_registered_under_a_condition) {
280+
static const tm_source_t src[] = {{"tests/test_main.c", "int main(void) {\n"
281+
" RUN_SELECTED_SUITE(always);\n"
282+
"#if defined(COV) && !defined(_WIN32)\n"
283+
" RUN_SELECTED_SUITE(guarded);\n"
284+
" RUN_SELECTED_SUITE(twice);\n"
285+
"#endif\n"
286+
" RUN_SELECTED_SUITE(twice);\n"
287+
" return 0;\n"
288+
"}\n"}};
289+
cbm_test_model_t *m = model_of(src, 1);
290+
ASSERT_NOT_NULL(m);
291+
int n = 0;
292+
const cbm_test_runner_suite_t *suites = cbm_test_model_runner_suites(m, &n);
293+
ASSERT_EQ(n, 3);
294+
ASSERT_STR_EQ(suites[0].name, "always");
295+
ASSERT_FALSE(suites[0].conditional);
296+
ASSERT_STR_EQ(suites[1].name, "guarded");
297+
ASSERT_TRUE(suites[1].conditional);
298+
ASSERT_STR_EQ(suites[2].name, "twice");
299+
ASSERT_FALSE(suites[2].conditional);
300+
cbm_test_model_free(m);
301+
PASS();
302+
}
303+
277304
/* Both branches of an #if may open the same block. Counting both braces would
278305
* leave the scanner one level deep for the rest of the file, and every later
279306
* test and suite would be missed. */
@@ -1688,6 +1715,88 @@ TEST(test_selection_inventory_ambiguity_and_conditionals_use_whole_suite) {
16881715
PASS();
16891716
}
16901717

1718+
/* A suite the runner registers only under a preprocessor condition is absent
1719+
* from some builds, so however it is selected it must carry CONDITIONAL: the
1720+
* runner that lacks it then tolerates its absence. Its cases and registrations
1721+
* are unconditional here, so only the runner registration can say so. */
1722+
TEST(test_selection_conditionally_registered_suite_is_conditional_on_every_path) {
1723+
static const char *quiet_rows = "alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1724+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\n"
1725+
"alpha:quiet\tcomplete\t\t1\n";
1726+
struct {
1727+
const char *rows;
1728+
bool admitted;
1729+
bool reached, changed, rule;
1730+
unsigned path;
1731+
} variants[] = {
1732+
{"alpha:*\tincomplete\tlost setup\t1\nalpha:stat\tcomplete\t\t1\n"
1733+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n",
1734+
true, false, false, false, CBM_TEST_SELECT_SETUP_UNKNOWN},
1735+
{"alpha:*\tcomplete\t\t0\nalpha:stat\tcomplete\t\t1\n"
1736+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n",
1737+
true, false, false, false, CBM_TEST_SELECT_SETUP_HIT},
1738+
{quiet_rows, true, true, false, false, CBM_TEST_SELECT_STATIC},
1739+
{quiet_rows, true, false, true, false, CBM_TEST_SELECT_CHANGED},
1740+
{quiet_rows, true, false, false, true, CBM_TEST_SELECT_RULE},
1741+
{quiet_rows, false, false, false, false, CBM_TEST_SELECT_ARTIFACT_REJECTED},
1742+
/* One covered case alone would otherwise name `alpha:cov`. */
1743+
{"alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1744+
"alpha:cov\tcomplete\t\t0\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n",
1745+
true, false, false, false, CBM_TEST_SELECT_COVERAGE},
1746+
};
1747+
const char *runners[] = {
1748+
"void main(void) {\n#if defined(FEATURE) && !defined(_WIN32)\nRUN_SELECTED_SUITE(alpha);\n"
1749+
"#endif\n}\n",
1750+
"void main(void) { RUN_SELECTED_SUITE(alpha); }\n",
1751+
};
1752+
for (int r = 0; r < 2; r++) {
1753+
char source[1024];
1754+
snprintf(source, sizeof(source),
1755+
"TEST(stat) {}\nTEST(cov) {}\nTEST(changed) {}\nTEST(quiet) {}\n"
1756+
"SUITE(alpha) { RUN_TEST(stat); RUN_TEST(cov); RUN_TEST(changed); "
1757+
"RUN_TEST(quiet); }\n%s",
1758+
runners[r]);
1759+
cbm_test_model_t *model = selection_model(source);
1760+
ASSERT_NOT_NULL(model);
1761+
for (int i = 0; i < (int)(sizeof(variants) / sizeof(variants[0])); i++) {
1762+
cbm_coverage_map_t *map = selection_map(variants[i].rows);
1763+
ASSERT_NOT_NULL(map);
1764+
cbm_test_reach_t reach[] = SELECTION_REACH;
1765+
for (int k = 0; k < 4; k++)
1766+
reach[k].reached = reach[k].changed = false;
1767+
int changed[] = {0};
1768+
cbm_test_suite_trigger_t trigger = {.suite = "alpha",
1769+
.reached = variants[i].reached,
1770+
.changed = variants[i].changed,
1771+
.rule = variants[i].rule};
1772+
cbm_test_selection_input_t input = selection_input(model, map, reach, changed);
1773+
input.coverage_admitted = variants[i].admitted;
1774+
input.suite_triggers = &trigger;
1775+
input.suite_trigger_count = 1;
1776+
cbm_test_selection_t *result = cbm_test_select(&input);
1777+
ASSERT_NOT_NULL(result);
1778+
ASSERT_EQ(cbm_test_selection_run_all(result), 0);
1779+
int count;
1780+
const cbm_test_selected_suite_t *suites = cbm_test_selection_suites(result, &count);
1781+
ASSERT_EQ(count, 1);
1782+
ASSERT_TRUE(suites[0].reasons & variants[i].path);
1783+
if (r == 0) {
1784+
ASSERT_TRUE(suites[0].whole);
1785+
ASSERT_TRUE(suites[0].reasons & CBM_TEST_SELECT_CONDITIONAL);
1786+
cbm_test_selection_cases(result, &count);
1787+
ASSERT_EQ(count, 0);
1788+
} else {
1789+
/* Registered in every build: the strict contract stays. */
1790+
ASSERT_FALSE(suites[0].reasons & CBM_TEST_SELECT_CONDITIONAL);
1791+
}
1792+
cbm_test_selection_free(result);
1793+
cbm_coverage_map_free(map);
1794+
}
1795+
cbm_test_model_free(model);
1796+
}
1797+
PASS();
1798+
}
1799+
16911800
/* Uncertainty is scoped to the file it was found in. A file the model cannot
16921801
* read with certainty, but which defines its own suite, makes that suite
16931802
* uncertain (it can only run whole) and leaves every other suite narrowable.
@@ -3804,6 +3913,7 @@ SUITE(test_impact) {
38043913
RUN_TEST(test_selection_setup_and_rejected_artifacts_select_whole_suites);
38053914
RUN_TEST(test_selection_incomplete_global_evidence_never_narrows);
38063915
RUN_TEST(test_selection_inventory_ambiguity_and_conditionals_use_whole_suite);
3916+
RUN_TEST(test_selection_conditionally_registered_suite_is_conditional_on_every_path);
38073917
RUN_TEST(test_model_uncertainty_is_scoped_to_the_suites_of_its_file);
38083918
RUN_TEST(test_model_only_code_continuations_are_uncertain);
38093919
RUN_TEST(test_selection_scoped_uncertainty_runs_only_its_suite_whole);
@@ -3834,6 +3944,7 @@ SUITE(test_impact) {
38343944
RUN_TEST(test_model_ignores_comments_and_literals);
38353945
RUN_TEST(test_model_reads_suites_written_as_functions);
38363946
RUN_TEST(test_model_marks_what_is_under_a_condition);
3947+
RUN_TEST(test_model_marks_runner_suites_registered_under_a_condition);
38373948
RUN_TEST(test_model_keeps_brace_depth_across_else_branches);
38383949
RUN_TEST(test_model_resolves_registrations_in_their_own_file);
38393950
RUN_TEST(test_model_marks_suites_that_register_through_a_macro);

0 commit comments

Comments
 (0)