cgal icon indicating copy to clipboard operation
cgal copied to clipboard

STL_Extension: Add bisect_failures debugging utility

Open lrineau opened this issue 2 months ago • 11 comments

Summary

This PR adds a new debugging utility bisect_failures to the STL_Extension package. This function helps identify minimal failing test cases from complex input data by using a bisection-like approach.

Small feature: bisect failures debugging utility

Features

  • Multiple failure type support: Handles CGAL exceptions, std::exceptions, and exit codes
  • Automatic granularity adjustment: Starts with ratio=0.5, automatically halves when no fault is found
  • Debug output: Saves intermediate states (current, bad, error, final_bad)
  • Template-based design: Works with any copyable/assignable data type

Testing

Added comprehensive test suite (test_bisect_failures.cpp) with 14 tests:

  • ✅ Edge cases (empty data, no failures)
  • ✅ Single element failures (CGAL exception, std::exception, exit code)
  • ✅ Pair combinations (all 2-element permutations)
  • ✅ Triple combinations (all 3 failure types together)

All tests pass in both Debug and Release configurations.

Use Case

This utility is particularly useful for:

  • Debugging complex geometric algorithms with large input datasets
  • Finding minimal reproducible test cases from failing inputs
  • Isolating problematic elements in mesh processing, triangulation, etc.

Example Usage

auto get_size = [](const Mesh& m) { return m.number_of_faces(); };
auto simplify = [](Mesh& m, std::size_t start, std::size_t end) -> bool {
  // Remove faces from start to end
  for(std::size_t i = start; i < end && i < m.number_of_faces(); ++i) {
    m.remove_face(start);
  }
  return true;
};
auto run = [](const Mesh& m) -> int { return algorithm(m); };
auto save = [](const Mesh& m, const std::string& prefix) {
  std::ofstream out(prefix + ".off");
  out << m;
};

int result = bisect_failures(mesh, get_size, simplify, run, save);

Files Changed

  • STL_Extension/include/CGAL/bisect_failures.h (new) - Main utility header
  • STL_Extension/test/STL_Extension/test_bisect_failures.cpp (new) - Test suite
  • STL_Extension/test/STL_Extension/CMakeLists.txt (modified) - Added test

Checklist

  • [x] Code compiles without errors (Debug and Release)
  • [x] All tests pass
  • [x] Comprehensive documentation with Doxygen comments
  • [x] Example usage in documentation
  • [x] Follows CGAL coding style conventions
  • [x] Deal with false positive in the testsuite

lrineau avatar Oct 31 '25 14:10 lrineau

/build:v1

lrineau avatar Oct 31 '25 15:10 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/9118/v1/Manual/index.html

github-actions[bot] avatar Oct 31 '25 15:10 github-actions[bot]

/force-build:v1

lrineau avatar Oct 31 '25 21:10 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/9118/v1/Manual/index.html

github-actions[bot] avatar Oct 31 '25 21:10 github-actions[bot]

/build:v1-after-Andreas-review

lrineau avatar Nov 12 '25 14:11 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/9118/v1/Manual/index.html

github-actions[bot] avatar Nov 12 '25 14:11 github-actions[bot]

/force-build:v1-after-Andreas-review

lrineau avatar Nov 12 '25 16:11 lrineau

The documentation is built. It will be available, after a few minutes, here: https://cgal.github.io/9118/v1/Manual/index.html

github-actions[bot] avatar Nov 12 '25 16:11 github-actions[bot]

Fails in 50% of today's testsuites https://cgal.geometryfactory.com/CGAL/testsuite/summary-6.2-Ic-40.html?package=STL_Extension_Examples

afabri avatar Nov 13 '25 07:11 afabri

Segfault in CGAL-6.2-Ic-41

afabri avatar Nov 14 '25 06:11 afabri

Successfully tested in CGAL-6.2-Ic-53

sloriot avatar Dec 03 '25 10:12 sloriot