Skip to content

Daily Test Coverage Improver - Research and Plan #7884

@github-actions

Description

@github-actions

Repository Analysis

Purpose and Technology Stack

Z3 is Microsoft Research's theorem prover, written primarily in C++ with C++20 standard requirements. It provides various APIs (C++, C, Python, Java, .NET, OCaml, JavaScript/WASM) and uses CMake as its primary build system, with additional support for Visual Studio, Makefiles, vcpkg, and Bazel.

Current Test Coverage Infrastructure

**✅ (redacted)

  • Comprehensive unit test suite (src/test/) with 100+ test files covering core functionality
  • Robust CI infrastructure with multiple build configurations
  • Existing coverage workflow (.github/workflows/coverage.yml) that runs bi-weekly
  • Coverage collection infrastructure already configured (.github/actions/daily-test-improver/coverage-steps/action.yml)
  • Rich regression test suite via external z3test repository

**⚠️ Current (redacted)

  • Coverage report generation is failing due to gcovr merge conflicts with C++ template destructors
  • The error indicates: Got function (redacted)<(redacted)>::(redacted)) on multiple lines: 87, 116
  • Despite test execution success, HTML coverage reports aren't being generated

Test Organization and Structure

Unit Tests (src/test/):

  • Main test executable: test-z3 built via CMake
  • Tests cover: algebraic numbers, AST, bit vectors, arithmetic, SAT solving, SMT theories, parsers, utilities
  • Test execution command: ./build/test-z3 -a

**External (redacted)

  • Regression tests via z3test repository (SMT2 benchmarks)
  • Coverage-specific tests in z3test/coverage/cpp
  • Example programs that also serve as integration tests

Build and Coverage Commands

**Build (redacted)

# Configure with coverage instrumentation
CXXFLAGS="--coverage" CFLAGS="--coverage" LDFLAGS="-lgcov" CC=clang CXX=clang++ \
  cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=./build/install -G "Ninja"

# Build core library and tests
ninja -C build install
ninja -C build test-z3

**Test (redacted)

# Run unit tests
./build/test-z3 -a

# Run regression tests
python z3test/scripts/test_benchmarks.py build/z3 z3test/regressions/smt2
python z3test/scripts/test_coverage_tests.py ./build/install z3test/coverage/cpp

Coverage Report Generation (currently broken):

# This fails due to template merge conflicts
gcovr --html coverage.html --gcov-ignore-parse-errors --gcov-executable "llvm-cov gcov" .

Test Coverage Improvement Strategy

Immediate Priorities

  1. Fix Coverage Report Generation

    • Resolve gcovr merge conflict by adding --merge-mode-functions=separate flag
    • This will allow us to see actual coverage percentages and identify gaps
  2. High-Impact Areas for New Tests (based on codebase analysis):

    • Theory Solvers (src/smt/theory_*.cpp): Core SMT theory implementations
    • AST Operations (src/ast/): Expression manipulation and rewriting
    • SAT Solver Components (src/sat/): Boolean satisfiability solving
    • API Layer (src/api/): Public interface functions
    • Utility Libraries (src/util/): Core data structures and algorithms
  3. Coverage Expansion Strategies:

    • Edge Case Testing: Focus on boundary conditions, error paths, and exception handling
    • Integration Testing: Cross-theory interactions and complex formulas
    • API Boundary Testing: Parameter validation and error conditions
    • Performance Path Testing: Rarely-executed optimization paths

Test Organization Guidelines

**For New (redacted)

  • Add to existing files in src/test/ when extending functionality of tested modules
  • Create new test files following naming pattern <module_name>.cpp
  • Follow existing test patterns with simple functions and PASS/FAIL assertions
  • Update src/test/CMakeLists.txt when adding new test files

Fast Development Workflow

**Quick Test (redacted)

# Rebuild only tests after changes
ninja -C build test-z3

# Run specific test subset (when developing)
./build/test-z3 -a | grep -A5 -B5 "FAILED\|PASS.*<test-name>"

# Generate coverage after test runs
gcovr --merge-mode-functions=separate --gcov-ignore-parse-errors --gcov-executable "llvm-cov gcov" .

Opportunities for Major Coverage Improvements

  1. Theory Combination Testing: Z3's strength is combining multiple theories - test complex multi-theory problems
  2. Error Path Coverage: Many error handling paths are likely untested
  3. API Robustness: Stress testing of public APIs with invalid inputs
  4. Memory Management: Test resource cleanup and edge cases in allocators
  5. Parser Edge Cases: Complex SMT-LIB2 parsing scenarios

Questions for Maintainers

  1. Are there specific modules or theories that are known to need more test coverage?
  2. What are the performance implications of enabling coverage instrumentation in CI?
  3. Should we prioritize functional correctness tests or performance regression prevention?
  4. Are there any testing patterns or utilities we should avoid or prefer?

> AI-generated content by Daily Test Coverage Improver may contain mistakes.

Generated by Agentic Workflow Run

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions