Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

Commit 8a77e51

Browse files
committed
test: assert ray_rowsel block size to actually catch over-allocation
The previous version of /rowsel/all_segments_compact only checked seg_offsets[] values, which are computed identically on both buggy and fixed code (they walk popcount[]). The bug was purely in the size of the underlying ray_alloc block — invisible from the seg_offsets surface. Add a real regression assertion: BSIZEOF(sel->order) must be strictly less than the buggy payload size (sized for total_pass). For the 4-morsel/3-ALL/1-MIX shape: fixed payload is 66 bytes (buddy order 7 -> 128 B block), buggy payload is 6210 bytes (buddy order 13 -> 8192 B block). Verified by temporarily re-introducing the bug — the assertion fires with 'actual_block < buggy_payload (8192 < 6210)'.
1 parent ed61890 commit 8a77e51

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

test/test_rowsel.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "munit.h"
77
#include <rayforce.h>
8-
#include "mem/heap.h"
8+
#include "mem/heap.h" /* BSIZEOF for block-size assertion */
99
#include "ops/ops.h"
1010
#include "ops/rowsel.h"
1111
#include <string.h>
@@ -279,16 +279,33 @@ static MunitResult test_rowsel_all_segments_compact(const void* params, void* fi
279279
munit_assert_int(flags[2], ==, RAY_SEL_ALL);
280280
munit_assert_int(flags[3], ==, RAY_SEL_MIX);
281281

282-
/* Critical: seg_offsets[n_segs] must equal 7 — the actual
283-
* idx[] occupancy — NOT total_pass. Verifies the allocation
284-
* is sized for MIX rows only. */
282+
/* seg_offsets[n_segs] must equal 7 — the actual idx[]
283+
* occupancy. This part is correct in BOTH the buggy and
284+
* fixed code (offsets are computed by walking popcounts) so
285+
* it's a sanity check, not the regression assertion. */
285286
const uint32_t* offsets = ray_rowsel_offsets(sel);
286287
munit_assert_int(offsets[0], ==, 0);
287288
munit_assert_int(offsets[1], ==, 0);
288289
munit_assert_int(offsets[2], ==, 0);
289290
munit_assert_int(offsets[3], ==, 0);
290291
munit_assert_int(offsets[4], ==, 7);
291292

293+
/* Real regression assertion: the underlying ray_alloc block
294+
* size must reflect idx_count=7, not idx_count=total_pass.
295+
*
296+
* Fixed payload = sizeof(meta)24 + pad8(4)8 + (4+1)*4 + 7*2 = 66 B
297+
* Buggy payload = sizeof(meta)24 + pad8(4)8 + (4+1)*4 + 3079*2 = 6210 B
298+
*
299+
* Buddy allocator rounds to the next power-of-two order, so
300+
* the fixed block is order 7 (128 B) and the buggy block is
301+
* order 13 (8 KB). Assert the block's actual size is less
302+
* than the buggy expectation. */
303+
size_t fixed_payload = ray_rowsel_payload_bytes(nrows, 7);
304+
size_t buggy_payload = ray_rowsel_payload_bytes(nrows, m->total_pass);
305+
munit_assert_size(fixed_payload, <, buggy_payload);
306+
size_t actual_block = BSIZEOF(sel->order);
307+
munit_assert_size(actual_block, <, buggy_payload);
308+
292309
/* Reconstruct: 3072 dense rows from segments 0..2, plus 7
293310
* indexed rows from segment 3. */
294311
int64_t* recon = (int64_t*)ray_data(ray_alloc((size_t)m->total_pass * sizeof(int64_t)));

0 commit comments

Comments
 (0)