Child body: builds the store and runs the layout so a crash or hang cannot * take down the runner (alarm bounds a hang, fork isolates a SIGSEGV). * Deliberately NO memory rlimit: under a rlimit a failing calloc makes * octree_insert silently truncate and the UNFIXED code would complete — * turning this guard vacuously green. The alarm alone bounds the runaway. * Exit codes: 0 ok, 2 store setu
| 767 | * Exit codes: 0 ok, 2 store setup, 3 layout NULL, 4 node count/lookup, |
| 768 | * 5 fixture no longer coincident, 6 non-finite coordinate. Never returns. */ |
| 769 | static void layout_octree_guard_child(void) { |
| 770 | alarm(5); /* post-fix the whole child runs in milliseconds */ |
| 771 | cbm_store_t *store = cbm_store_open_memory(); |
| 772 | if (!store) |
| 773 | _exit(2); |
| 774 | if (cbm_store_upsert_project(store, "test", "/tmp/test") != CBM_STORE_OK) |
| 775 | _exit(2); |
| 776 | |
| 777 | /* Distinct QNs, one fnv1a hash — coincident after anchor + jitter. */ |
| 778 | static const char *cqn[3] = {"test::octree_c5988474", "test::octree_c11394919", |
| 779 | "test::octree_c33141700"}; |
| 780 | for (int i = 0; i < 3; i++) { |
| 781 | char name[32]; |
| 782 | snprintf(name, sizeof(name), "co%d", i); |
| 783 | cbm_node_t n = {.project = "test", |
| 784 | .label = "Function", |
| 785 | .name = name, |
| 786 | .qualified_name = cqn[i], |
| 787 | .file_path = "pkg/sub/mod/a.c", |
| 788 | .start_line = i + 1, |
| 789 | .end_line = i + 2}; |
| 790 | if (cbm_store_upsert_node(store, &n) <= 0) |
| 791 | _exit(2); |
| 792 | } |
| 793 | /* A few normally-spread nodes so the octree root box has realistic |
| 794 | * (non-degenerate) extent, as in the reported repositories. */ |
| 795 | for (int i = 0; i < 3; i++) { |
| 796 | char name[32], qn[64], fp[32]; |
| 797 | snprintf(name, sizeof(name), "fn%d", i); |
| 798 | snprintf(qn, sizeof(qn), "test::spread_fn%d", i); |
| 799 | snprintf(fp, sizeof(fp), "dir%d/f%d.c", i, i); |
| 800 | cbm_node_t n = {.project = "test", |
| 801 | .label = "Function", |
| 802 | .name = name, |
| 803 | .qualified_name = qn, |
| 804 | .file_path = fp, |
| 805 | .start_line = 1, |
| 806 | .end_line = 2}; |
| 807 | if (cbm_store_upsert_node(store, &n) <= 0) |
| 808 | _exit(2); |
| 809 | } |
| 810 | |
| 811 | cbm_layout_result_t *r = cbm_layout_compute(store, "test", CBM_LAYOUT_OVERVIEW, NULL, 0, 100); |
| 812 | if (!r) |
| 813 | _exit(3); |
| 814 | if (r->node_count != 6) |
| 815 | _exit(4); |
| 816 | |
| 817 | /* The colliding QNs must actually be coincident — identical output |
| 818 | * coordinates (identical seeds → identical positions, and coincident |
| 819 | * bodies receive identical forces every iteration, so they stay |
| 820 | * together). If a seeding change ever breaks this, the fixture no longer |
| 821 | * reproduces the bug: fail loudly instead of going vacuously green. */ |
| 822 | int ci[3], nc = 0; |
| 823 | for (int i = 0; i < r->node_count && nc < 3; i++) { |
| 824 | if (r->nodes[i].qualified_name && |
| 825 | strncmp(r->nodes[i].qualified_name, "test::octree_c", 14) == 0) |
| 826 | ci[nc++] = i; |
no test coverage detected