Add radare2 end-to-end integration tests - #14
Merged
Conversation
Cover the binary-analysis pipeline that the unit tests could not: compile a tiny program with the system compiler and run BinaryAnalyzer against a real radare2, asserting get_functions finds the defined functions, extract_function_features returns well-typed features with recovered bytes/tlsh/ssdeep/entropy, get_imports returns a list, and string_references resolves a known string literal. The tests skip when a C compiler, radare2, or the native deps are missing, and tolerate ELF/Mach-O and radare2 5.x/6.x naming differences. Install radare2 in CI so these run there too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
_extract_string_references called json.loads directly on izj/aflj/axlj output. Some radare2 versions return an empty string for axlj, which raised JSONDecodeError and aborted BinaryAnalyzer construction entirely. String references are best-effort metadata, so parse these commands through a _safe_json helper that degrades to an empty result instead of crashing the analysis. Surfaced by the new integration tests against the radare2 build in CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
extract_function_features indexed afij fields directly, but their names vary across radare2 versions (Ubuntu's 5.5.0 lacks 'ninstrs'), which raised KeyError. Read them with .get and sensible defaults, mirroring get_feature_dict, so extraction degrades gracefully on any version. CI now installs a pinned radare2 release (6.1.8) via the official .deb instead of the distro's ancient 5.5.0, so the integration tests run against a representative modern radare2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Closes the test-coverage gap flagged earlier: the radare2-backed extraction path (
BinaryAnalyzer) had no automated tests.tests/test_integration_r2.pycompiles a tiny program with the system C compiler and runsBinaryAnalyzeragainst a real radare2, asserting:get_functionsfinds the defined functions (compute,greet,main);extract_function_featuresreturns well-typed features with recoveredbytes/tlsh/ssdeep/entropy;get_importsreturns a list;string_referencesresolves a known string literal to its function.The tests skip when a C compiler,
radare2, or the native deps are unavailable, and tolerate ELF/Mach-O and radare2 5.x/6.x naming differences (prefix + leading-underscore stripping).CI now installs
radare2so the integration tests run there as well.Validation
pytest -vlocally against radare2 6.1.9 → 16 passed (12 unit + 4 integration). CI run on this PR validates them on radare2 from Ubuntu.🤖 Generated with Claude Code