Add empty_namespacet for unit tests#8996
Open
tautschnig wants to merge 6 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8996 +/- ##
===========================================
- Coverage 80.55% 80.54% -0.02%
===========================================
Files 1707 1708 +1
Lines 189051 188897 -154
Branches 73 73
===========================================
- Hits 152299 152148 -151
+ Misses 36752 36749 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ee52ad7 to
704b2f1
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a reusable empty_namespacet for unit tests so callers can use a shared empty namespacet without repeatedly declaring a symbol_tablet + namespacet.
Changes:
- Introduced
unit/testing-utils/empty_namespace.{h,cpp}and wired it into the unit testing-utils build. - Updated many unit tests to use
empty_namespaceinstead of locally constructing empty symbol tables/namespaces. - Adjusted test module dependencies where needed.
Reviewed changes
Copilot reviewed 67 out of 67 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| unit/util/std_expr.cpp | Replaces local symbol_tablet/namespacet boilerplate with empty_namespace. |
| unit/util/simplify_expr.cpp | Uses empty_namespace for simplify-related unit tests. |
| unit/util/pointer_offset_size.cpp | Uses empty_namespace for namespace parameter in tests. |
| unit/util/lower_byte_operators.cpp | Uses empty_namespace instead of local namespace construction. |
| unit/util/interval/subtract.cpp | Removes unused local namespace boilerplate and includes empty_namespace. |
| unit/util/interval/multiply.cpp | Removes unused local namespace boilerplate and includes empty_namespace. |
| unit/util/interval/modulo.cpp | Removes unused local namespace boilerplate and includes empty_namespace. |
| unit/util/interval/get_extreme.cpp | Uses empty_namespace for simplify/namespace-dependent operations. |
| unit/util/interval/comparisons.cpp | Removes unused local namespace boilerplate and includes empty_namespace. |
| unit/util/interval/add.cpp | Removes unused local namespace boilerplate and includes empty_namespace. |
| unit/util/bitvector_expr.cpp | Uses empty_namespace for boolbvt construction in tests. |
| unit/testing-utils/empty_namespace.h | Introduces empty_namespacet and declares global empty_namespace. |
| unit/testing-utils/empty_namespace.cpp | Defines the global empty_namespace instance. |
| unit/testing-utils/Makefile | Adds empty_namespace.cpp to testing-utils build inputs. |
| unit/solvers/strings/string_refinement/string_refinement.cpp | Uses empty_namespace for string_refinement test environment. |
| unit/solvers/strings/string_format_builtin_function/length_of_decimal_int.cpp | Uses empty_namespace instead of local namespacet. |
| unit/solvers/strings/string_format_builtin_function/length_for_format_specifier.cpp | Uses empty_namespace instead of local namespacet. |
| unit/solvers/strings/string_constraint_generator_valueof/is_digit_with_radix.cpp | Uses empty_namespace for simplify/namespace usage. |
| unit/solvers/strings/string_constraint_generator_valueof/get_numeric_value_from_character.cpp | Uses empty_namespace for simplify/namespace usage. |
| unit/solvers/smt2_incremental/object_tracking.cpp | Uses empty_namespace in object tracking tests. |
| unit/solvers/smt2_incremental/convert_expr_to_smt.cpp | Uses empty_namespace for object tracking and conversions in tests. |
| unit/solvers/prop/bdd_expr.cpp | Removes local namespace boilerplate and includes empty_namespace. |
| unit/solvers/flattening/boolbv_update_bit.cpp | Uses empty_namespace for boolbvt construction. |
| unit/solvers/flattening/boolbv_onehot.cpp | Uses empty_namespace for boolbvt construction. |
| unit/solvers/flattening/boolbv_enumeration.cpp | Uses empty_namespace for boolbvt construction. |
| unit/solvers/flattening/boolbv.cpp | Uses empty_namespace for boolbvt construction. |
| unit/solvers/bdd/miniBDD/module_dependencies.txt | Adds flattening dependency to match updated includes/usage. |
| unit/solvers/bdd/miniBDD/miniBDD.cpp | Uses empty_namespace for boolbvt construction and related logic. |
| unit/goto-symex/shadow_memory_util.cpp | Uses empty_namespace when calling helpers requiring namespacet. |
| unit/goto-symex/is_constant.cpp | Uses empty_namespace for namespace parameter. |
| unit/goto-programs/xml_expr.cpp | Uses empty_namespace for XML conversion requiring namespacet. |
| unit/goto-programs/goto_trace_output.cpp | Uses empty_namespace for trace output requiring namespacet. |
| unit/ansi-c/expr2c.cpp | Uses empty_namespace instead of temporary namespacet{symbol_tablet{}}. |
| unit/analyses/variable-sensitivity/variable_sensitivity_test_helpers.cpp | Uses empty_namespace for from_expr in helper formatting. |
| unit/analyses/variable-sensitivity/variable_sensitivity_domain/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/value_set_pointer_abstract_object/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/widening_merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/meet.cpp | Uses empty_namespace in meet tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/extremes-go-top.cpp | Uses empty_namespace in extremes/top tests. |
| unit/analyses/variable-sensitivity/value_set_abstract_object/compacting.cpp | Uses empty_namespace in compacting tests. |
| unit/analyses/variable-sensitivity/value_expression_evaluation/expression_evaluation.cpp | Uses empty_namespace in expression evaluation tests. |
| unit/analyses/variable-sensitivity/value_expression_evaluation/assume_prune.cpp | Uses empty_namespace in assume/prune tests. |
| unit/analyses/variable-sensitivity/value_expression_evaluation/assume.cpp | Uses empty_namespace in assume tests. |
| unit/analyses/variable-sensitivity/interval_abstract_value/widening_merge.cpp | Uses empty_namespace in widening merge tests. |
| unit/analyses/variable-sensitivity/interval_abstract_value/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/interval_abstract_value/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/interval_abstract_value/meet.cpp | Uses empty_namespace in meet tests. |
| unit/analyses/variable-sensitivity/interval_abstract_value/extremes-go-top.cpp | Uses empty_namespace in extremes/top tests. |
| unit/analyses/variable-sensitivity/full_struct_abstract_object/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/full_struct_abstract_object/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/full_array_abstract_object/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/full_array_abstract_object/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/full_array_abstract_object/maximum_length.cpp | Uses empty_namespace in maximum length tests. |
| unit/analyses/variable-sensitivity/eval-member-access.cpp | Uses empty_namespace in member access evaluation tests. |
| unit/analyses/variable-sensitivity/constant_pointer_abstract_object/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/constant_abstract_value/to_predicate.cpp | Uses empty_namespace in predicate tests. |
| unit/analyses/variable-sensitivity/constant_abstract_value/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/constant_abstract_value/meet.cpp | Uses empty_namespace in meet tests. |
| unit/analyses/variable-sensitivity/abstract_object/merge.cpp | Uses empty_namespace in merge tests. |
| unit/analyses/variable-sensitivity/abstract_object/index_range.cpp | Uses empty_namespace in index range tests. |
| unit/analyses/variable-sensitivity/abstract_environment/to_predicate.cpp | Uses empty_namespace in environment predicate tests. |
| unit/analyses/does_remove_const/is_type_at_least_as_const_as.cpp | Removes local namespace boilerplate and includes empty_namespace. |
| unit/analyses/does_remove_const/does_type_preserve_const_correctness.cpp | Removes local namespace boilerplate and includes empty_namespace. |
| unit/analyses/does_remove_const/does_expr_lose_const.cpp | Removes local namespace boilerplate and includes empty_namespace. |
| unit/analyses/ai/ai_simplify_lhs.cpp | Uses empty_namespace in AI simplify LHS tests. |
Comments suppressed due to low confidence (3)
unit/testing-utils/empty_namespace.h:1
namespacet(base) is constructed beforesymbol_table(member). Passingsymbol_tableinto the base-class constructor before the member is constructed can lead to undefined behavior ifnamespacettouches the referenced symbol table during its construction. Fix by ensuring the symbol table is constructed before thenamespacetbase (e.g., use the base-from-member pattern via private inheritance fromsymbol_tablet, or store anamespacetmember instead of inheriting).
unit/testing-utils/empty_namespace.h:1- As written, the compiler-generated copy/move operations for
empty_namespacetare very likely to yield a broken object (thenamespacetbase will copy its internal references/pointers and keep referring to the source object's symbol table, while the destination has its ownsymbol_tablemember). This can produce dangling references after the source is destroyed. Makeempty_namespacetnon-copyable/non-movable (delete copy/move ctor and assignment), or implement them so thenamespacetbase is rebound to the destination's symbol table.
unit/testing-utils/empty_namespace.h:1 - A global
empty_namespaceintroduces a potential static-initialization-order dependency if any other global initializer in the unit test binary uses it. To avoid this class of issues, consider providing an accessor (e.g., a function returning a reference to a function-local static instance) and updating call sites to use that accessor.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
704b2f1 to
0ced341
Compare
The test uses boolbvt.
Introduce empty_namespacet, a namespacet subclass that self-contains an empty symbol_tablet member. This avoids the boilerplate of declaring a symbol_tablet and namespacet in every test that doesn't actually populate the symbol table. Follows the same pattern as the existing null_message_handler in testing-utils. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Replace boilerplate 'symbol_tablet symbol_table; namespacet ns{symbol_table};'
with 'auto &ns = empty_namespace;' (or the const variant) across 55 unit test
files where the symbol table was never populated.
In cases where the namespace variable was entirely unused, both the
symbol_tablet and namespacet declarations are removed.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Eight unit tests had a 'symbol_tablet symbol_table; namespacet
ns(symbol_table);' pair that was declared but never used. The
preceding commit removed those declarations as part of the migration
to empty_namespacet, but left both '#include <util/namespace.h>' and
the newly-added '#include <testing-utils/empty_namespace.h>' in
place. Neither header is referenced from these files: there is no
mention of 'namespacet' nor of 'empty_namespace' anywhere in their
bodies.
Drop both includes from:
- unit/util/interval/{add,comparisons,multiply,modulo,subtract}.cpp
- unit/analyses/does_remove_const/{does_expr_lose_const,
does_type_preserve_const_correctness,
is_type_at_least_as_const_as}.cpp
CODING_STANDARD.md asks to avoid unnecessary includes.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Add a smoke test that exercises empty_namespacet through a const namespacet & reference: an absent symbol lookup returns true and leaves the out-parameter null, and smallest_unused_suffix returns 0 for any prefix. The test documents the helper's contract and acts as a regression test if anyone ever changes the inheritance order or the base-from-member cast in empty_namespacet's constructor. Following the convention established by unit/get_goto_model_from_c_test.cpp, the new file lives at the top of unit/ rather than inside unit/testing-utils/: anything matched by testing-utils/*.cpp is removed from the unit executable's sources by unit/CMakeLists.txt and built into the testing-utils library instead, so a TEST_CASE placed there would never run. Also tighten the empty_namespacet constructor to use a reference static_cast (static_cast<symbol_tablet &>(*this)) rather than a pointer cast and dereference, which is slightly more idiomatic when the cast target is a base subobject. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
After the migration to empty_namespacet, around 50 unit tests had
declared a 'auto &ns = empty_namespace;' (or 'const auto &') alias.
Two issues with the auto& form:
1. The deduced type is the implementation class
'const empty_namespacet &' rather than the abstract
'const namespacet &', so test code is unnecessarily coupled to
the helper's class.
2. At sites where the alias was used only once or twice, the alias
declaration was longer than the inline form would have been.
Sweep these sites, applying a per-scope rule:
* If 'ns' is referenced no more than twice within the surrounding
brace scope, drop the alias and use 'empty_namespace' inline.
* Otherwise keep the alias but make the type explicit:
'const namespacet &ns = empty_namespace;'.
The choice is stylistic; the test bodies are unchanged. All 538 unit
test cases / 19053 assertions still pass.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
0ced341 to
5645a21
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce empty_namespacet, a namespacet subclass that self-contains an empty symbol_tablet member. This avoids the boilerplate of declaring a symbol_tablet and namespacet in every test that doesn't actually populate the symbol table.
Follows the same pattern as the existing null_message_handler in testing-utils.
Co-authored-by: Kiro kiro-agent@users.noreply.github.com