Writing tests#
A cuGeo test should fail when a change breaks something a user or a host engine relies on, and pass on every change that does not. A test that checks how the code does its work, rather than what it returns, fails on correct changes: a correct change to when the native runtime releases its inputs failed 33 cugeo-geometry-cudf ctests and 12 live tests, with every result row still right.
Most sections below work through an example from cuGeo’s suites, before and after. An “after” is marked either in the tree, with the file that does it, or proposed, a rewrite the file does not have. The before of a proposed after is what the file does; the before of an after in the tree is what the file did before it. Coding agents load the same rules from the cugeo-test-writing skill, which also holds the review checklist, and its cugeo-geometry extension, the cugeo-geometry-test-writing skill.
Expected values#
Expected values come from an oracle that does not share the code or the intermediate state under test. Usually that is PostgreSQL 18.6 with PostGIS 3.6.4, pinned in tests/fixtures/reference-environment.json. Other oracles are another independent engine, a CPU brute force computed from the inputs, or a small model whose rows were checked against PostGIS. A brute force or model may run inside the test; only checked-in expected values need a generator.
Tests and fixture generators read stored PostgreSQL and PostGIS answers; none
runs PostgreSQL (tools/AGENTS.md, “Stored oracle values”).
The PostgreSQL connector’s tests (tests/planning/postgis_capture.rs, and
tests/live/postgis_capture_live.rs for the device) decode the stored COPY-binary
captures in tests/fixtures/postgis-copy-capture, the pinned server’s row
descriptions and PostGIS’s answers over the same rows; they connect to no
server. The planning tests also fail when a file or a manifest field differs
from the manifest, or when a geometry family or dimension case is missing;
tests/qualification/test_postgis_copy_capture_manifest.py checks
the recorded reference identity with oracle_manifest.check_identity.
The captures are stored in
crates/execution/tests/fixtures/postgis-copy-capture/.
The manifest’s gaps list names the typmod forms the planner accepts that no
case captures yet; remove a gap when a case covers it.
To give a new operation or case a PostgreSQL oracle:
Extend the
tools/*_file_fixture.pygenerator that owns the fixture, or add one; tools/AGENTS.md lists the generators and the files each owns.Capture the answers from the pinned reference outside the repository and store them with the SQL and inputs that produced them.
Seal the fixture’s manifest with
tools/oracle_manifest.py, which records the reference identity, the sha256 of each stored file and of the capture SQL, then run the generator’scheckcommand.Commit the fixture files and the manifest.
Never edit expected rows by hand. The fixture in crates/execution/tests/fixtures/region-join/ is an example: its expected rows are a hand-labelled model of which rows intersect or cover, and every query’s model rows were checked against PostGIS before they were stored.
Choosing the surface#
Test a behavior at the highest public surface that can reach it:
Surface |
Tests |
Runner |
|---|---|---|
SQL over local files, the |
|
|
Stage programs on the cugeo-geometry-cudf C ABI, |
|
ctest in the cugeo-geometry-cudf build, in the merge gate |
The CUDA SDK, |
|
ctest in the SDK build, in the merge gate |
Binding, Select and admission on the CPU |
|
|
SQL from Python, |
|
|
The merge gate runs tests/test_cugeo.py with CUGEO_RUN_GPU_TESTS=1 and
CUGEO_GEOMETRY_CUDF_LIBRARY set (tools/run_all_suites.sh), so its GPU
classes run there. Outside the gate they skip through unittest.skipUnless
unless you set both. Run them under the native build env’s interpreter, as the
gate does. The tests that run the cugeo-geometry-query command line read the release
binary from CUGEO_GEOMETRY_QUERY, which the gate sets after building it; build it
yourself and set it to run them:
cargo build --release --locked -p cugeo-geometry-execution \
--features cudf-request,postgis --bin cugeo-geometry-query
UV_PYTHON=build/native/env/bin/python UV_PROJECT_ENVIRONMENT=build/native/python-api-venv \
CUGEO_RUN_GPU_TESTS=1 CUGEO_GEOMETRY_CUDF_LIBRARY=build/native/cugeo-geometry-cudf-build/libcugeo_geometry_cudf.so \
CUGEO_GEOMETRY_QUERY=target/release/cugeo-geometry-query \
uv run --group test python -m unittest tests/test_cugeo.py
The python/cugeo/geometry/README.md states why.
Put a Python API test in tests/test_cugeo.py, and a GPU
test of SQL behavior across cases and delivery modes in a *_live.rs module
of crates/execution/tests/live/.
A query test runs the parser, binder, planner, native admission and the GPU together. It catches a defect in any of them, and it keeps passing when the work moves from one of them to another.
crates/execution/tests/live/region_join_live.rs is a model. It runs 84 cases: SQL queries over Parquet tables that mix Points, LineStrings, Polygons with holes and MultiPolygons, with NULL and EMPTY rows. Each case runs four ways: on the default route and forced generic, each read whole and in 3-row scan chunks. All four runs are compared with the generator’s expected rows, which PostGIS confirmed. Unordered results are compared as sorted bags, ordered ones row by row.
Plan shape in a query test#
Before. The SF1 test of SpatialBench Q9 compared the result rows, then
also checked the plan in the profile that cugeo-geometry-query prints:
assert_eq!(event("select")["selection"], STAGE_SELECTION);
assert_eq!(count(read, "columns"), 2);
assert_eq!(count(program, "region_pair_runs"), 1);
assert_eq!(count(program, "region_pair_index_preparations"), 1);
A new fused implementation for Q9, or a Read that loads one more column, failed this test while every row stayed correct.
After, in the tree. The live test compares the rows, and
assert_complete_profile in
crates/execution/tests/support/spatialbench_q9_result.rs
checks only what the profile promises for any plan: each stage event is
present and in pipeline order, every read and decode covers the building
table’s rows, and the stage program publishes the result rows. Select’s
choice for Q9 is a planning decision, and
canonical_s3_queries_select_their_region_implementations in
crates/cases/tests/stage_select/stage_select.rs checks on the CPU that Q9
plans a SpatialJoin stage with pair output. A change to that choice
fails there, where it is reviewed as a planning change.
Where the route is the property under test, read it from a typed field. The
Q12 SF1 live test grades the default route against the oracle, so it requires
the strategies event to name the demand strategy KNN_GROUP_BOUND, not the
whole selection string.
Unit tests#
A unit test fits an algorithm whose answer an independent oracle can compute for the same input: an index query against a brute-force filter, a numeric kernel against PostgreSQL’s values. It does not fit wiring, such as which function calls which, or in what order. Query and stage tests cover wiring.
A sequential model of the code under test is a valid oracle for a contract the model shares, such as an output order. It is not independent of the state it reads: if the model walks the same built index, a defect in the build reaches both. Pair it with an oracle computed from the inputs.
Before. index_traversal_differential compared the parallel cursors’
ordered candidate sequences with single-thread walks of the same built
index. It also required equal visited-node and visited-leaf counters, but
did not compare candidates with the input rows. Counter equality would
reject a traversal that prunes differently while publishing the same
candidates. If the index build drops an input row, both walks can omit that
row and still produce equal sequences.
After, in the tree. index_traversal_differential obtains the ordered
reference sequence from the single-thread traversals in
backends/cuda/tests/index/reference_traversal.cuh.
For each query, differential() calls complete() on that sequence before
checking the cursors and batch schedules. The brute-force rows come from
filtering every input box or point, independently of the built index.
In backends/cuda/tests/index/traversal_differential.cu,
complete() sorts a copy of the reference sequence and checks it against
the sorted brute-force rows:
std::sort(sequence.begin(), sequence.end());
REQUIRE(std::adjacent_find(sequence.begin(), sequence.end()) ==
sequence.end());
REQUIRE(sequence.empty() || sequence.back() < rows);
if (completeness == Completeness::Exact)
REQUIRE(sequence == brute);
else
REQUIRE(std::includes(sequence.begin(), sequence.end(), brute.begin(),
brute.end()));
The duplicate and row-range checks apply to both strategies. Packed STR filters each leaf row’s box, so its candidates must equal the brute-force set. Quadtree traversal publishes whole leaves, so it may include extra points but must include every point in the query box.
The sort does not change the reference sequence used for the order check.
differential() compares
single-query cursor rows in order and passes the unsorted sequences to
batch_checks(), which compares pairs across schedules, page capacities down
to 1, and switches between walk forms mid-cursor. That order is the contract
in backends/cuda/src/index/candidate_index.h: schedules may
change throughput, but publish the same pairs in the same order.
Real code and fakes#
Run the real runtime, libcudf and the SDK. A fake replaces code, so a test against a fake checks the test author’s model of that code, not the code.
A fake is acceptable at a boundary the product exposes and a test cannot otherwise provoke, and then it replaces the boundary, not the logic behind it. Two examples in the tree:
inject_every_spatial_callin backends/cudf/tests/live_stage_support.hpp makes one spatial provider call fail and runs the real stage program around it.backends/cudf/tests/host_allocator_library.cpp supplies a device allocator through the public
cugeo_geometry_cudf_allocatorhook, so a test can run a real query in host-allocator mode and check that no bytes are still held at exit.
Before. An earlier form of backends/cudf/tests/checked_gather_test.cpp, which runs the checked gather against a fake runtime, required in its success case one exact sequence of 21 runtime events:
std::vector<Event> const expected{
Event::retain_context, Event::retain, Event::enter, Event::rows,
Event::allocate_narrowed, /* ... 15 more ... */ Event::release_context};
assert(fake.events == expected);
Adding a synchronization, or moving one independent release before another, fails it, and neither changes what a caller can observe.
After, in the tree. The fake stays for what only a fake can do: fail a context retain, a synchronization or a buffer release at a chosen call. Each such case asserts the documented outcome of that failure:
Rollback. The call returns its status, publishes no output, and
assert_released()holds: no live buffers, results, resource or context references remain (test_sync_failuresinbackends/cudf/tests/checked_gather_test.cpp, its first case).Quarantine. When the device work cannot be retired, the call returns
CUGEO_GEOMETRY_CUDF_INTERNAL_FAILUREand deliberately keeps the buffers, a resource reference and the pending host status until recovery, so the device never writes into freed memory. The test asserts that state, recovers, and then assertsassert_released()(test_sync_failures, its second case).
The event log still carries the ordering invariants that matter for safety,
and assert_safe_ordering(), which assert_released()
calls, asserts them: a gather after the validation launch follows a
successful synchronization after the status read, every destroy follows a
successful synchronization after the last device work, and the resource is
released only after a successful synchronization after the last destroy. It
asserts no exact sequence. The success path is also covered in the tree
on the real runtime by
backends/cudf/tests/live_checked_gather_test.cpp, which
compares the gathered values, including duplicates and NULLs.
Inputs#
Use inputs that reach the cases users hit. A toy input may isolate a failure, but it is never the only coverage. Include, where they apply:
NULL and EMPTY geometry, of each family the operation accepts;
duplicate rows and duplicate pairs, so row multiplicity is checked;
boundaries: shapes that touch, a point on an edge, a distance equal to the radius, ties under
ORDER BYwithLIMIT;degenerate shapes: zero-width boxes, holes, rings that collapse, columns that mix families;
sizes at which the code takes another path: page capacities 1 and 3, scan chunks that split a table (
CUGEO_GEOMETRY_CUDF_TEST_SCAN_CHUNK_ROWS), more Points than resident lanes, Int64 offsets past 2 GiB, and a device with little free memory (CUGEO_GEOMETRY_CUDF_TEST_DEVICE_FREE_BYTEScaps the free bytes cugeo-geometry-cudf admission andcugeo_geometry_cudf_device_free_getread, as backends/cudf/contracts/device-memory.md states, so a test holds no more of the device than its query needs).
Run each case through the delivery modes the query can take: whole and in
chunks, fused and forced generic, resident and streamed.
crates/execution/tests/live/region_join_live.rs runs four of them per
case.
For realistic geometry, use SpatialBench data, the Point and zone operands in tests/fixtures/point-zone-intersects.json, and fixture generators that mix families with NULL and EMPTY rows.
backends/cuda/tests/index/packed_str.cu shows both kinds of input.
deterministic_duplicate_empty_boundary builds six boxes by hand,
including a duplicate and an EMPTY box, and queries the single point (1, 1),
which three of the boxes touch only at a corner. randomized_differential
builds 513 boxes from a fixed seed and checks 64 queries against the
brute-force filter. After row 0, every 29th row is an EMPTY box and each
remaining 17th row duplicates its predecessor, so row 493, a multiple of both,
is EMPTY.
Size that changes the code path#
Before. The lanes_below_points case of
backends/cuda/tests/sdk/proximity_claim_order.cpp
reaches more Points than lanes by building resident + 1009
Points, where resident is the device’s resident thread count. The input,
and with it the run time, grows with the GPU.
After, proposed. Limit the lanes instead of growing the
input. backends/cuda/tests/fragments/pair_lanes.cpp
(its header comment) does this in the tree for the persistent-lane pair cursor: a
context budget too small for the wide lane state leaves 1 or 33 lanes for
about 9,700 Points, on any GPU. That reaches the same condition on different
code; lanes_below_points would need the same kind of budget or
point_tile setting for the DWithin cursor it covers.
When a path needs a large input, size the test for it and let it report a skip
when the machine cannot hold it. sdk_wkb_decode_large decodes a WKB payload
over 2 GiB to reach Int64 offsets, and exits 77, which ctest reports as
skipped, when the device lacks the memory
(backends/cuda/cmake/IoTargets.cmake). Such a
test must fit the GPU the merge gate runs on, or it never runs. The reference
machine in tests/fixtures/reference-environment.json records an RTX 6000 Ada
with 48 GiB.
Assertions#
Each assertion answers one question: which user-visible result, documented contract or guarantee breaks if it fails? Results, NULL and EMPTY behavior, row multiplicity, order where the query defines it, statuses, and documented lifetimes and limits qualify. Internal counts, call orders, memory layouts, telemetry and timing do not, unless a contract documents them. Then the test cites that contract.
Lifetimes#
Before. A cugeo-geometry-cudf parity test releases the caller’s table and program, then requires that the input’s external owner has already run (the literal projection test of crates/execution/tests/cugeo_geometry_cudf_native_parity/cugeo_geometry_cudf_projection_live.inc):
native.release_table(table);
native.release_program(program);
assert_eq!(owner_calls.load(Ordering::Acquire), 1);
cugeo/geometry/cudf/api.h does not say when the release callback of
cugeo_geometry_cudf_external_owner_desc runs relative to a result’s lifetime. Both 0 and
1 at this point are correct implementations, and switching between them
failed the 45 tests above.
After. Assert what a caller relies on:
After the caller releases its table and program, the result’s values still read correctly.
After the caller releases every handle (table, program, result and export), the owner’s release callback has run exactly once.
The context’s
used_bytesfromcugeo_geometry_cudf_context_get_device_memoryis back to the value it had before the query.
Leave unasserted whether the owner has run while the result is still live.
Items 1 and 2 are in the tree for the literal and direct projection tests
in crates/execution/tests/cugeo_geometry_cudf_native_parity/cugeo_geometry_cudf_projection_live.inc
and crates/execution/tests/cugeo_geometry_cudf_native_parity/cugeo_geometry_cudf_direct_projection_live.inc:
they require owner_calls <= 1 after the caller’s release (in run_native_live_literal_projection in the
first file) and read the result’s values, then owner_calls == 1 after the
last holder’s release (in the same function). A count alone misses a premature release,
because the test’s input allocations outlive the result, so once the owner has
run, poison_released_input
(crates/execution/tests/support/parity_support.rs)
overwrites them before the values are
read; a result that still aliases them then reads wrong values. The grouped,
geometry-is-null and equality tests it includes check the counts the same
way; the equality tests also poison, while the grouped and geometry-is-null
inputs are SDK geometry objects with no test-owned allocation to overwrite. A check that the owner has not run while the caller’s table is
live stays exact, as does the one in the grouped test’s quarantine path,
where the runtime keeps the inputs for the process lifetime. Item 3 is a
check in the tree:
backends/cudf/tests/live_stage_hull_aggregate_limit.inc
reads used_bytes before its runs and requires the same value after them,
in device_memory_limit.
Internal counters#
Before. An earlier form of the stress function in
backends/cudf/tests/live_stage_hull_top_k_test.cpp compared
its result with the stage oracle, configured the hook to decline 4 frames
starting at the third attempt, and then pinned the count:
CHECK(observed.hooks.fused_fast_frames != 0 &&
observed.hooks.fused_generic_frames == 4, ...);
== 4 checks that the hook honored its configuration. It fails whenever a
change to chunking or frame sizes leaves too few frames for all four declines,
though the generic path still ran and the result is still right. The same
pattern pinned one index preparation in every oracle case of
backends/cudf/tests/live_stage_knn_top_k_test.cpp
and one hash-join build per execution in every case of
backends/cudf/tests/live_stage_equi_join_test.cpp.
After, in the tree. Keep the oracle comparison. Reduce the counter to a
check that the forced path ran: stress requires fused_fast_frames != 0 && fused_generic_frames != 0. Keep a
performance property, such as one build per execution, in one dedicated case
that says it checks performance and cites the contract that documents it, not
in every oracle case: equi_joins() in
backends/cudf/tests/live_stage_equi_join_test.cpp and
generic_regions() in
backends/cudf/tests/live_stage_knn_top_k_test.cpp cite the
EQUI_JOIN “Hash table” in
backends/cudf/contracts/equi-join.md#execution-and-resources
and KNN_JOIN “Target index” in
backends/cudf/contracts/knn-join.md#execution-and-resources.
A counter a contract documents is a contract check, in the tree:
backends/cuda/tests/sdk/proximity_size_classes.cpp checks
that the pair cursor’s branch is
CUGEO_GEOMETRY_CUDA_POINT_REGION_BRANCH_DWITHIN_MORTON_RANGE, which
backends/cuda/contracts/proximity-morton-range.md defines.
Counts of cases#
Before. crates/execution/tests/live/region_join_live.rs asserted
cases.len() == 84 against its own manifest, so adding a case to the
generator failed the test until someone edited the number.
After, in the tree. The live tests that read a generated manifest run
every case it lists. The manifest’s completeness belongs to its generator:
manifest_sets() maps each owned fixture directory to its list names, derived
from the corpus without a reference database. In tools/manifest_cases.py,
problems(manifest, names) compares the lists and reports a manifest that
lacks, adds, renames or reorders a case, or lists none. A generator’s check
compares its FIXTURE manifest by calling check(path, manifest_sets()[FIXTURE]),
which runs problems() for that manifest.
In tests/qualification/test_manifest_cases.py, audit()
loads every producer through generator_manifests(path), validates its map and
compares every declared directory through problems(). The test finds each
manifest from its generator, so emptied lists remain audited. Its negative
controls drop one case from each list and empty each list. The region
join test also checks that each case’s expected rows are not empty; that
suits this fixture, and a fixture whose correct answer is empty for some case
checks instead that each case has its expected file.
Order, ties and determinism#
Unordered results are compared as bags: sort both sides, as
crates/execution/tests/live/region_join_live.rsdoes for cases its manifest marks unordered.Ties under
ORDER BY ... LIMIT. Which of the rows tied at the cap PostgreSQL returns is unspecified, and so is cuGeo’s choice. The rule a test states is: rows outside the tie group at the cap equal the reference’s, in order where the query orders them; each row inside the tie group ties the reference’s last row on theORDER BYkeys and is a distinct row of the reference query rerun with a largerLIMIT. A row that cannot be proven that way fails; an unavailable larger reference is a failure to compare, not a pass.BoundaryTiein tools/spatialbench_generalization/run.py applies this rule to tier 2, andrun.py report --gatefails the gate on a tie it cannot prove. When a test does not need ties, choose data where no tie straddles the cap, and test ties in their own case under this rule.Floating-point results use the tolerance the contract states, and exact comparison where the contract is exact. crates/execution/tests/support/overlay_tolerance.rs holds the overlay contract’s vertex tolerance for the Rust tests; a SpatialBench case states its tolerance in the
[compare]table of itscase.toml(tools/spatialbench_generalization/cases/README.md).Random inputs come from a fixed seed in the source, as
randomized_differentialdoes, or print their seed on failure.No timing assertions. Wall-clock checks belong in benchmarks, run on demand.
Flaky tests are defects. A test that fails intermittently has a race in the product or the test; find it.
tools/run_all_suites.shreruns a ctest entry once after a timeout, for a contended GPU, and names it on a TIMEOUT line. That retry is not a license for a test that hangs some of the time. A sanitizer ctest whose compute-sanitizer failed to attach to the device checked nothing and runs once more; the gate names it on a SANITIZER ATTACH RETRY line. Repeated runs that look for nondeterminism belong in the nightly tier.
Errors and refusals#
Decide on codes, never on message text. Each surface reports its codes:
the local-file query path:
LocalFileQueryError::native_status()andstage_failure(), whosestage(),layer()andrefusal_class()name where and why a query failed,sql_code()the frontend’s diagnostic, andselect_refusal()the subject and reason of Select’s refusal (crates/execution/src/query_cli.rs and crates/execution/src/file_query.rs);Python:
cugeo.geometry.QueryErrorwithrefusal_class,stage,layerandnative_status;the C ABI: the
cugeo_geometry_cudf_statusa call returns.
A diagnostic may still be checked for what cuGeo’s contract requires it to
name, derived from the input: a CUGEO_GEOMETRY_CUDF_NOT_EXECUTABLE refusal names the
stage, operation and reason (backends/cudf/AGENTS.md), and a
refused row is named by its row in the table. Decide the outcome by code,
then check the named items, not the sentence around them.
Before. non_point_row_is_not_executable in
crates/execution/tests/live/streamed_edges_live.rs reads a table
with a Polygon at row 250 into a Point operand, whole and in 100-row chunks.
It checked the refusal by its message:
let error = run(&request, bootstrap, rows).unwrap_err().to_string();
assert!(error.contains("during InputLoad") && error.contains("status 25")
&& error.contains("NotExecutable{op: ..., column: trip.t_pickuploc, \
family: Polygon, row: 250}"));
// ... and the message is the same for both chunkings.
The test exists to check that a streamed read names the table row, 250, and not the row within its chunk, 50. The status and stage were read from text.
After, in the tree. fails_alike in the same file reads the status and
stage by code, and keeps the row-identity checks:
let failure = error.stage_failure().unwrap();
assert_eq!(
(failure.stage(), failure.native_status()),
(FileQueryStage::InputLoad, Some(CUGEO_GEOMETRY_CUDF_NOT_EXECUTABLE))
);
// The message names the column, family and row 250, and is equal
// across the whole and chunked runs.
assert_refusal in
crates/execution/tests/live/region_overlay_live.rs
classifies a refusal by layer, native status and refusal class the same way. In the
planning tests, cugeo_geometry_cases::select_refusal checks that a failure is
Select’s refusal by stage, layer and refusal class, and returns its typed
subject and reason.
PostgreSQL error parity#
Where cuGeo must raise the error PostgreSQL raises, compare with what PostgreSQL returned, never with a string written for the test.
Before. The window-function fixture generator checked that
PostgreSQL raises an error for LAG(x, 2147483648), then stored a cuGeo
message for the test to match:
"lag-int8-offset": ("SELECT id, LAG(x, 2147483648) OVER (ORDER BY id) FROM wt",
"the offset must be an integer (int4)",
"function lag(integer, bigint) does not exist"),
PostgreSQL says the function does not exist. The test checked cuGeo’s own wording, so nothing compared cuGeo’s error with PostgreSQL’s.
After, in the tree. invalid_operands_are_refused in
crates/execution/tests/live/region_overlay_live.rs
reads the SQLSTATE that PostgreSQL returned, recorded in the manifest of
crates/execution/tests/fixtures/region-overlay/, and checks cuGeo’s refusal by its native
status. crates/execution/tests/live/window_functions_live.rs
does the same through support/postgres_errors.rs. Where the message itself
is the contract, the test compares cuGeo’s message with the postgresql text
the generator recorded.
The status a PostgreSQL error maps to follows the taxonomy in backends/cudf/AGENTS.md:
The status of the SQLSTATE’s condition when cuGeo decides the same error from the same data:
CUGEO_GEOMETRY_CUDF_NUMERIC_VALUE_OUT_OF_RANGE(SQLSTATE 22003),CUGEO_GEOMETRY_CUDF_DIVISION_BY_ZERO(22012) orCUGEO_GEOMETRY_CUDF_DATETIME_VALUE_OUT_OF_RANGE(22008).CUGEO_GEOMETRY_CUDF_INVALID_NTILE_ARGUMENT(35, SQLSTATE 22014) for an evaluated nonpositive NTILE bucket, andCUGEO_GEOMETRY_CUDF_INVALID_PRECEDING_OR_FOLLOWING_SIZE(36, SQLSTATE 22013) for an invalid evaluated RANGE size. Both are data errors, with no refusal, retry or host/device exhaustion.CUGEO_GEOMETRY_CUDF_NEGATIVE_RADIUSfor PostGIS’s XX000 on a negativeST_DWithinradius, andCUGEO_GEOMETRY_CUDF_NON_FINITE_DISTANCEfor its XX000 on a non-finiteST_Bufferdistance at a row that is neither NULL nor EMPTY.CUGEO_GEOMETRY_CUDF_MIXED_SRIDfor PostGIS’s XX000 on operands of different SRIDs.CUGEO_GEOMETRY_CUDF_SRID_MISMATCHfor PostGIS’s 22023 on a geometry whose SRID contradicts its nonzero declared SRID. Contradictions in normalized imports under SRID 0 remainCUGEO_GEOMETRY_CUDF_DATA_CONTRACT, with no PostgreSQL SQLSTATE. Without an explicit label override, final typed row evidence of an encoded SRID an undeclared uniform SRID-0 decode cannot retain selectsCUGEO_GEOMETRY_CUDF_NOT_EXECUTABLE(0A000), a missing capability.CUGEO_GEOMETRY_CUDF_NOT_EXECUTABLEorCUGEO_GEOMETRY_CUDF_BACKEND_MISMATCHwhen cuGeo cannot evaluate the case and a host routes it to PostgreSQL, which then raises its own error: the first when cugeo-geometry-cudf refuses it, the second when the SDK does not execute the evaluation. The invalid overlay operands above, on which PostGIS raises XX000, areCUGEO_GEOMETRY_CUDF_BACKEND_MISMATCH.CUGEO_GEOMETRY_CUDF_INTERNAL_FAILUREnever; it means a native invariant broke (backends/cudf/contracts/statuses.md).
The stage oracle holds this mapping in
backends/cudf/tests/fixtures/stage_oracle/oracle_cases.py.
SQLSTATE_TO_STATUS maps each SQLSTATE but XX000. XX000 is PostgreSQL’s catch-all, so error_status
classifies it by the PostGIS error it carries (XX000_STATUS) and
stops the generator on one it does not know. The harness decides by status
and, for CUGEO_GEOMETRY_CUDF_NEGATIVE_RADIUS and CUGEO_GEOMETRY_CUDF_MIXED_SRID, also requires the
message PostgreSQL recorded (backends/cudf/tests/live_stage_support.hpp,
compare_or_status). cugeo_geometry_cudf_status_sqlstate, which the
crates/execution/src/data/c_abi/status_classes.rs module
includes from the build’s rendering of
backends/cudf/contracts/status-classes.toml, maps each status
back to the SQLSTATE cuGeo raises, where it has one, and data_c_abi.rs
checks that the two agree.
The live tests compare with the manifest’s error cases through
crates/execution/tests/support/postgres_errors.rs, which
checks the status, cuGeo’s SQLSTATE and PostgreSQL’s message; a case where
cuGeo’s error differs from PostgreSQL’s records the divergence and the issue
that tracks it.
Tests that can fail#
A test must be able to fail, and it must say when it did not run. Before you commit a new test, break the code it protects: flip a boundary comparison, drop the NULL handling, return one row fewer. Watch the test fail. At the least, change one expected row and watch it fail.
Skips#
A check whose optional service is missing prints one SKIP <reason> line and
exits 77 (tools/AGENTS.md). Exit 0 always means the check ran and
passed. tools/run_all_suites.sh prints SKIP for a suite that exits 77
after its SKIP line, with the reason from its log, and fails the gate,
because every gate suite is required. A ctest entry registered with
SKIP_RETURN_CODE 77 is reported as skipped in the ctest log, and the gate
prints one PASS line for the whole ctest suite.
The gate’s last suite, test-membership, compares the per-test record of
every suite with the tests its build lists. It fails on a listed test that did
not run, on a run that names a test its build does not list, and on a test
that skipped
without a declared skip, the file
tests/membership/skips/<suite>/<test>.txt that gives the reason, and prints
SKIP <suite>: <test>: <detail> (waived: <reason>) for each test that
skipped under one, so the gate log names every skip. A declared skip that no test of
its suite’s listing matches fails too. An entry that needs a
host tool, such as a sanitizer ctest that needs compute-sanitizer 2026.3, is
registered on every host and exits 77 where the tool is missing; its skip is
then waived by name instead of the entry being absent from the tree. The
rules and their inputs are in the Test membership section of
tools/AGENTS.md.
A sanitizer report reproduced by a minimal program without cuGeo code, kept
outside the repository with its description, is an external defect. Declare
its name, tool, the exit statuses it can end with and its output signatures
with backends/cuda/cmake/ComputeSanitizer.cmake. An entry
naming it exits 77 only when its status is a declared one, every signature
matches, every diagnostic is covered by a signature, a benign line or a
summary, and its one summary, of its tool’s kind, counts exactly the reports
it printed. A clean run passes;
remove the waiver when the defect is known fixed. test-membership accepts
the skip only with the waiver line naming that defect; a declared skip
cannot waive it otherwise.
The ctest-cugeo-geometry-cudf-interop-whole-gpu suite is whole-device: test-membership
fails any skip of its entries, and tests/membership/skips/ may hold no
declaration for it.
unittest cannot exit 77: a skipped test exits 0, and a failed one exits 1.
A Python check that needs a service is therefore a script, not a skipped
test case.
Before. backends/cudf/tests/check_cudf_forward_port_contract.py
printed SKIP and exited 0 when the adjacent cuDF checkout was absent, so
ctest counted a pass.
After, in the tree.
backends/cudf/tests/check_cudf_forward_port_contract.py exits
77, and its ctest entry sets SKIP_RETURN_CODE 77. Never append || true to
a check.
Comparing a route with itself#
Before. The forced-generic differential ran each SpatialBench case on
the default route and with --force-generic, then graded the generic rows
against the fused rows:
ref = typed_tsv(fused["tsv"], types[0])
A defect in code both routes share, such as reading, decoding or exporting the result, passed. Where both routes selected the same plan, the comparison checked a run against a rerun of itself.
After, in the tree. tools/spatialbench_generalization/run.py
grades the generic route against the case’s reference with the case’s
[compare] rule, the same way it grades the default route. The reference
rows come from run.py ref, which queries the case’s reference engines and
caches the answer per case and scale. The generic route runs only where the
default route’s select profile event lists a fused implementation; where it
lists none, Select builds the same plan with fusion disabled, and
every_reaching_case_routes_by_family in
crates/cases/tests/stage_select/stage_select.rs checks that on the CPU for
every case that reaches the native engine. crates/execution/tests/live/region_join_live.rs grades both
Fusion::Enabled and Fusion::Disabled against its fixture the same way.
A comparison of two cuGeo routes remains useful where the contract is
transparency and the base route has its own oracle check.
backends/cudf/tests/live_stage_hull_top_k_test.cpp requires each
spilled run to equal the unspilled run bit for bit, and its oracle section
compares the unspilled runs with the stage oracle.
Cases that never run#
Before. An earlier form of
backends/cuda/tests/sdk/proximity_claim_order.cpp said that
boundary_tiny covers the one-step quantum for window arithmetic. The case was
excluded from the default run, and no ctest entry named it. The
sdk_proximity_claim_order_registration entry checked only that the registered
cases equalled the default cases, so nothing noticed.
After, in the tree. The runner has no default-case filter: a plain run
executes every case in the table, and --registered fails unless the cases
the ctest registration names are exactly the cases of the table. The CASES
list of sdk_proximity_claim_order in
backends/cuda/cmake/ProximitySdkTargets.cmake names
boundary_tiny, so it runs as sdk_proximity_claim_order_boundary_tiny. A
case that the binary compiles but no runner calls protects nothing; register
it or delete it and its claim.
Cost and tiers#
Every test states its tier:
every merge: correctness for the change under review, at a size that keeps the merge gate short;
nightly: exhaustive sweeps, repeated runs, full fault-injection matrices, sanitizer runs beyond the merge tier’s representatives, and performance checks;
on demand: profiles, timing and investigations someone starts by hand.
A test that moves to nightly leaves a small representative case in the merge tier.
Every merge-tier ctest entry, sanitizer runs included, runs within 60 seconds on the merge-train gate host. Make an entry over that budget smaller first, with fewer rows, a smaller grid or fewer repetitions, so that it still runs the same kernels and branches. Where that is not possible, move the full entry to nightly and keep a small representative under 60 seconds in the merge tier. The budget holds for every merge-tier entry, not only when one is added.
A test without a declaration is in the merge tier. Declare another tier in the test’s own source, where it is registered:
a ctest entry: the label
tier:nightlyortier:on-demandbeside its other labels;a Python test: the decorator
@tiers.tier("nightly")from tools/tiers.py;a live Rust test: a
tier:nightlyclause in its ignore reason,#[ignore = "live: needs VAR; tier:nightly; run tools/live_tests.py"], which tools/live_tests.py reads.
tools/run_all_suites.sh runs the merge tier, and tools/run_all_suites.sh --tier nightly runs the merge and nightly tiers. The “Test tiers” section of
tools/AGENTS.md lists how each runner selects them.
Before. index_traversal_corruption runs the corruption checks 100
times, because an uninitialized walk once crashed about one run in 20
(backends/cuda/tests/index/traversal_differential.cmake). The
fix makes the walk return BadQuery, and without it the check fails on the
first corrupted case of every run. Most of the 100 repeats add cost and no
coverage.
After, proposed. The merge tier runs --corrupt 3, and
the nightly tier runs --corrupt 100. The traversal differential’s existing
--small mode is the merge-tier form of the full differential.
For sanitizers, the merge tier keeps one memcheck run per kernel family on a
small input. A sanitizer whose hazards the kernels cannot produce goes
nightly: racecheck and synccheck find shared-memory and warp hazards, and
sdk_text_scan_racecheck runs racecheck over the kernels in
backends/cuda/src/io/text/scan_primitives.cuh, which use no
shared memory or warp operations, so it checks only CUB’s. Which sanitizers a
change must run before it merges is a separate rule, “Sanitizer by change
class” in backends/cuda/AGENTS.md.
Running the tests#
The checks that need no GPU, cargo test and the Python qualification and
documentation suites, are in Run development checks.
tools/live_tests.py runs the live Rust tests as described there.
Each native library’s README has its ctest recipe. The merge gate runs every
suite with:
tools/run_all_suites.sh [--log-dir DIR] <build-dir> <sf1-dir>
The gate holds two of the GPU’s slots, one per GPU lane (the only slot of a
one-slot GPU), through tools/gpu_run, and waits until they are free; other
jobs run beside it in the remaining slots.
It prints one PASS, FAIL or SKIP line per suite, a TIMEOUT line naming every ctest entry it reran after a timeout, a SANITIZER ATTACH RETRY line naming every sanitizer ctest that ran once more after its sanitizer failed to attach to the device, and a last line counting pass, skip and fail. It exits 0 only when every suite passed.
Reviewing a test change#
The review checklist is in the
cugeo-test-writing skill.
A reviewer loads it and its cugeo-geometry extension before reviewing a
change that adds or edits a test. Start a separate review session and give
the reviewer the exact base and head. The repository’s root AGENTS.md
links to the shared skills and library extensions.