Skip to content

Commit ef90708

Browse files
committed
Merge origin/main into fix/issue-1548-python-nested-defs-v2 (pick up the Smart CI selection fix #2684)
Signed-off-by: Martin Vogel <[email protected]>
2 parents 090580b + c23f162 commit ef90708

4 files changed

Lines changed: 133 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: 115 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,92 @@ 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+
/* A map covers every function it lists, so the changed one (0) is covered
1724+
* by the setup of a suite no runner registers: alpha's own rows stay
1725+
* quiet and each variant reaches alpha by its one path. */
1726+
static const char *quiet_rows = "alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1727+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\n"
1728+
"alpha:quiet\tcomplete\t\t1\nomega:*\tcomplete\t\t0\n";
1729+
struct {
1730+
const char *rows;
1731+
bool admitted;
1732+
bool reached, changed, rule;
1733+
unsigned path;
1734+
} variants[] = {
1735+
{"alpha:*\tincomplete\tlost setup\t1\nalpha:stat\tcomplete\t\t1\n"
1736+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n"
1737+
"omega:*\tcomplete\t\t0\n",
1738+
true, false, false, false, CBM_TEST_SELECT_SETUP_UNKNOWN},
1739+
{"alpha:*\tcomplete\t\t0\nalpha:stat\tcomplete\t\t1\n"
1740+
"alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n",
1741+
true, false, false, false, CBM_TEST_SELECT_SETUP_HIT},
1742+
{quiet_rows, true, true, false, false, CBM_TEST_SELECT_STATIC},
1743+
{quiet_rows, true, false, true, false, CBM_TEST_SELECT_CHANGED},
1744+
{quiet_rows, true, false, false, true, CBM_TEST_SELECT_RULE},
1745+
{quiet_rows, false, false, false, false, CBM_TEST_SELECT_ARTIFACT_REJECTED},
1746+
/* One covered case alone would otherwise name `alpha:cov`. */
1747+
{"alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1748+
"alpha:cov\tcomplete\t\t0\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n",
1749+
true, false, false, false, CBM_TEST_SELECT_COVERAGE},
1750+
};
1751+
const char *runners[] = {
1752+
"void main(void) {\n#if defined(FEATURE) && !defined(_WIN32)\nRUN_SELECTED_SUITE(alpha);\n"
1753+
"#endif\n}\n",
1754+
"void main(void) { RUN_SELECTED_SUITE(alpha); }\n",
1755+
};
1756+
for (int r = 0; r < 2; r++) {
1757+
char source[1024];
1758+
snprintf(source, sizeof(source),
1759+
"TEST(stat) {}\nTEST(cov) {}\nTEST(changed) {}\nTEST(quiet) {}\n"
1760+
"SUITE(alpha) { RUN_TEST(stat); RUN_TEST(cov); RUN_TEST(changed); "
1761+
"RUN_TEST(quiet); }\n%s",
1762+
runners[r]);
1763+
cbm_test_model_t *model = selection_model(source);
1764+
ASSERT_NOT_NULL(model);
1765+
for (int i = 0; i < (int)(sizeof(variants) / sizeof(variants[0])); i++) {
1766+
cbm_coverage_map_t *map = selection_map(variants[i].rows);
1767+
ASSERT_NOT_NULL(map);
1768+
cbm_test_reach_t reach[] = SELECTION_REACH;
1769+
for (int k = 0; k < 4; k++)
1770+
reach[k].reached = reach[k].changed = false;
1771+
int changed[] = {0};
1772+
cbm_test_suite_trigger_t trigger = {.suite = "alpha",
1773+
.reached = variants[i].reached,
1774+
.changed = variants[i].changed,
1775+
.rule = variants[i].rule};
1776+
cbm_test_selection_input_t input = selection_input(model, map, reach, changed);
1777+
input.coverage_admitted = variants[i].admitted;
1778+
input.suite_triggers = &trigger;
1779+
input.suite_trigger_count = 1;
1780+
cbm_test_selection_t *result = cbm_test_select(&input);
1781+
ASSERT_NOT_NULL(result);
1782+
ASSERT_EQ(cbm_test_selection_run_all(result), 0);
1783+
int count;
1784+
const cbm_test_selected_suite_t *suites = cbm_test_selection_suites(result, &count);
1785+
ASSERT_EQ(count, 1);
1786+
ASSERT_TRUE(suites[0].reasons & variants[i].path);
1787+
if (r == 0) {
1788+
ASSERT_TRUE(suites[0].whole);
1789+
ASSERT_TRUE(suites[0].reasons & CBM_TEST_SELECT_CONDITIONAL);
1790+
cbm_test_selection_cases(result, &count);
1791+
ASSERT_EQ(count, 0);
1792+
} else {
1793+
/* Registered in every build: the strict contract stays. */
1794+
ASSERT_FALSE(suites[0].reasons & CBM_TEST_SELECT_CONDITIONAL);
1795+
}
1796+
cbm_test_selection_free(result);
1797+
cbm_coverage_map_free(map);
1798+
}
1799+
cbm_test_model_free(model);
1800+
}
1801+
PASS();
1802+
}
1803+
16911804
/* Uncertainty is scoped to the file it was found in. A file the model cannot
16921805
* read with certainty, but which defines its own suite, makes that suite
16931806
* uncertain (it can only run whole) and leaves every other suite narrowable.
@@ -3804,6 +3917,7 @@ SUITE(test_impact) {
38043917
RUN_TEST(test_selection_setup_and_rejected_artifacts_select_whole_suites);
38053918
RUN_TEST(test_selection_incomplete_global_evidence_never_narrows);
38063919
RUN_TEST(test_selection_inventory_ambiguity_and_conditionals_use_whole_suite);
3920+
RUN_TEST(test_selection_conditionally_registered_suite_is_conditional_on_every_path);
38073921
RUN_TEST(test_model_uncertainty_is_scoped_to_the_suites_of_its_file);
38083922
RUN_TEST(test_model_only_code_continuations_are_uncertain);
38093923
RUN_TEST(test_selection_scoped_uncertainty_runs_only_its_suite_whole);
@@ -3834,6 +3948,7 @@ SUITE(test_impact) {
38343948
RUN_TEST(test_model_ignores_comments_and_literals);
38353949
RUN_TEST(test_model_reads_suites_written_as_functions);
38363950
RUN_TEST(test_model_marks_what_is_under_a_condition);
3951+
RUN_TEST(test_model_marks_runner_suites_registered_under_a_condition);
38373952
RUN_TEST(test_model_keeps_brace_depth_across_else_branches);
38383953
RUN_TEST(test_model_resolves_registrations_in_their_own_file);
38393954
RUN_TEST(test_model_marks_suites_that_register_through_a_macro);

0 commit comments

Comments
 (0)