Skip to content

Commit fe14b53

Browse files
authored
Add GitHub Artifacts for samples that crash (#447)
1 parent 8bf3cf1 commit fe14b53

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.github/workflows/extended-pipeline.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@ jobs:
2222
run: |
2323
docker build -t dewolf .
2424
- name: Run Tests
25+
id: run_tests
2526
run: |
26-
docker run dewolf make extendedtests
27+
docker run -v "$(pwd)"/artifacts:/opt/dewolf/crash_reports dewolf make extendedtests
28+
- name: Upload Crash Reports
29+
if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} # Only run if previous steps fail
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: crash-reports
33+
path: artifacts/*
34+
retention-days: 7 # Adjust retention as needed

.github/workflows/pipeline.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,13 @@ jobs:
2626
run: |
2727
docker run dewolf make check-format
2828
- name: Run Tests
29+
id: run_tests
2930
run: |
30-
docker run dewolf make
31+
docker run -v "$(pwd)"/artifacts:/opt/dewolf/crash_reports dewolf make
32+
- name: Upload Crash Reports
33+
if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} # Only run if previous steps fail
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: crash-reports
37+
path: artifacts/*
38+
retention-days: 7 # Adjust retention as needed

tests/test_sample_binaries.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
2+
import shutil
23
import subprocess
4+
from pathlib import Path
35

46
import pytest
57
from decompiler.backend.codegenerator import FAIL_MESSAGE
@@ -8,8 +10,23 @@
810
def test_sample(test_cases):
911
"""Test the decompiler with the given test case."""
1012
sample, function_name = test_cases
11-
output = subprocess.run(("python", "decompile.py", sample, function_name), check=True, capture_output=True).stdout.decode("utf-8")
12-
assert FAIL_MESSAGE not in output
13+
try:
14+
output = subprocess.run(("python", "decompile.py", sample, function_name), check=True, capture_output=True).stdout.decode("utf-8")
15+
failed = FAIL_MESSAGE in output
16+
except subprocess.CalledProcessError as e:
17+
failed = True
18+
if failed:
19+
__add_sample_to_crashed_sample_folder(sample, function_name)
20+
assert not failed
21+
22+
23+
def __add_sample_to_crashed_sample_folder(sample, function_name):
24+
"""Copy the sample to the crashed sample folder."""
25+
crash_dir = Path("crash_reports")
26+
crash_dir.mkdir(exist_ok=True)
27+
# Copy the binary to the crash directory
28+
output_file = crash_dir / ("_".join(sample.parts[3:]) + "_" + function_name)
29+
shutil.copy(sample, output_file)
1330

1431

1532
def test_globals():

0 commit comments

Comments
 (0)