Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion decbench/models/decompilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ def function_count(self) -> int:

@property
def successful_count(self) -> int:
return len(self.functions) - len(self.decompiler.failed_functions)
"""Count returned function bodies that are nonempty and not marked failed."""
failed = set(self.decompiler.failed_functions) - {"all"}
return sum(
bool(function.decompiled_code.strip()) and key not in failed
for key, function in self.functions.items()
)

def to_c_file(self, path: Path) -> None:
"""Write combined decompilation to a C file."""
Expand Down
20 changes: 20 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ def test_decompilation_result(self) -> None:
assert result.function_count == 1
assert result.successful_count == 1

@pytest.mark.parametrize(
"failed", [["missing1", "missing2", "failed"], ["all", "missing1", "missing2", "failed"]]
)
def test_success_count_only_counts_returned_usable_results(self, failed: list[str]) -> None:
result = DecompilationResult(
binary_path=Path("binary"),
binary_name="binary",
decompiler=DecompilerMetadata(decompiler_name="test_dec", failed_functions=failed),
functions={
"good": FunctionDecompilation(
name="good", address=0x1000, decompiled_code="int good() { return 1; }"
),
"failed": FunctionDecompilation(
name="failed", address=0x2000, decompiled_code="incomplete"
),
"empty": FunctionDecompilation(name="empty", address=0x3000, decompiled_code=" \n"),
},
)
assert result.successful_count == 1

def test_legacy_function_toml_without_cost_fields(self, tmp_path: Path) -> None:
function = FunctionDecompilation(
name="main", address=0x1000, decompiled_code="int main() {}"
Expand Down