Skip to content

Conversation

@dsyme
Copy link
Collaborator

@dsyme dsyme commented Sep 16, 2025

Summary

This PR adds comprehensive test coverage for Z3's AST map API functions, significantly improving test coverage from 0% to 84% for the src/api/api_ast_map.cpp module.

Problem Found

The AST map API functions (Z3_ast_map_*) had zero test coverage despite being a core part of Z3's AST manipulation capabilities:

  • src/api/api_ast_map.cpp: 0% coverage (0/111 lines covered)
  • No existing tests exercised the AST map API layer
  • Important functionality like map creation, insertion, lookup, deletion, and reference counting was untested

Actions Taken

  • Created comprehensive test suite in src/test/api_ast_map.cpp
  • Added test registration in src/test/main.cpp and src/test/CMakeLists.txt
  • Implemented tests for all major API functions:
    • Basic operations: Z3_mk_ast_map, Z3_ast_map_insert, Z3_ast_map_find, Z3_ast_map_contains, Z3_ast_map_size
    • Map manipulation: Z3_ast_map_erase, Z3_ast_map_reset
    • Reference counting: Z3_ast_map_inc_ref, Z3_ast_map_dec_ref
    • Utility functions: Z3_ast_map_to_string
  • Comprehensive test cases covering basic operations, value overwriting, entry deletion, map reset, and edge cases

Changes in Test Coverage Achieved

Before:

  • src/api/api_ast_map.cpp: 0% coverage (0/111 lines)
  • Overall project coverage: 47% (176,006/373,164 lines)

After:

  • src/api/api_ast_map.cpp: 84% coverage (94/111 lines) - +94 lines covered
  • Overall project coverage: 47% (176,040/373,341 lines) - +34 net covered lines

Coverage improvement breakdown:

  • 94 new lines covered in AST map API functions
  • Major functions now tested: All core AST map operations including creation, insertion, lookup, deletion, reset, and reference counting
  • Remaining uncovered areas: Error handling paths for invalid operations on lines 73-75, 135, 137-149

Validation Commands

To validate the coverage improvements:

# Build and run the new test
ninja -C build test-z3
./build/test-z3 api_ast_map

# Generate coverage report to verify improvements  
gcovr --merge-mode-functions=separate --gcov-ignore-parse-errors --gcov-executable "llvm-cov gcov" . | grep api_ast_map

Future Improvement Areas

Based on remaining uncovered areas in api_ast_map.cpp:

  • Error handling paths - Edge cases with invalid parameters or out-of-memory conditions
  • Advanced map operations - Complex scenarios with very large maps or unusual AST combinations

Other high-impact areas for future coverage improvements:

  • src/api/api_datalog.cpp (0% coverage, 486 lines) - Datalog API functions
  • src/api/api_fpa.cpp (0% coverage, 1090 lines) - Floating-point arithmetic API
  • src/api/api_pb.cpp (0% coverage, 64 lines) - Pseudo-boolean API functions

<details>
<summary>Workflow Details</summary>

Bash Commands Run

  • git checkout -b daily-test-improver-api-ast-map-tests
  • ninja -C build test-z3
  • ./build/test-z3 api_ast_map
  • gcovr --merge-mode-functions=separate --gcov-ignore-parse-errors --gcov-executable &quot;llvm-cov gcov&quot; . | grep api_ast_map
  • git add src/test/api_ast_map.cpp src/test/main.cpp src/test/CMakeLists.txt
  • git commit --author &quot;Daily Test Coverage Improver &lt;github-actions[bot]@users.noreply.github.com&gt;&quot; -m &quot;...&quot;

Web Searches Performed

None

Web Pages Fetched

None

</details>

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

Generated by Agentic Workflow Run

github-actions bot and others added 2 commits September 16, 2025 19:19
Improved test coverage from 0% to 84% for src/api/api_ast_map.cpp by adding comprehensive tests for:
- Basic map operations (creation, insertion, lookup, size)
- Map manipulation (overwrite values, erase entries, reset)
- Reference counting (inc_ref/dec_ref)
- String representation (to_string function)

This contributes 94 newly covered lines to overall project test coverage.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@NikolajBjorner NikolajBjorner marked this pull request as ready for review September 17, 2025 00:23
@NikolajBjorner NikolajBjorner merged commit ee083a2 into master Sep 17, 2025
6 of 19 checks passed
@nunoplopes nunoplopes deleted the daily-test-coverage-improver-46c4f98fe95fee0d branch September 18, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants