diff --git a/.github/workflows/extended-pipeline.yml b/.github/workflows/extended-pipeline.yml index b8cdeaf9..cfebc70c 100644 --- a/.github/workflows/extended-pipeline.yml +++ b/.github/workflows/extended-pipeline.yml @@ -22,5 +22,13 @@ jobs: run: | docker build -t dewolf . - name: Run Tests + id: run_tests run: | - docker run dewolf make extendedtests + docker run -v "$(pwd)"/artifacts:/opt/dewolf/crash_reports dewolf make extendedtests + - name: Upload Crash Reports + if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} # Only run if previous steps fail + uses: actions/upload-artifact@v4 + with: + name: crash-reports + path: artifacts/* + retention-days: 7 # Adjust retention as needed diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8841af98..bf4b20a9 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -26,5 +26,13 @@ jobs: run: | docker run dewolf make check-format - name: Run Tests + id: run_tests run: | - docker run dewolf make + docker run -v "$(pwd)"/artifacts:/opt/dewolf/crash_reports dewolf make + - name: Upload Crash Reports + if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} # Only run if previous steps fail + uses: actions/upload-artifact@v4 + with: + name: crash-reports + path: artifacts/* + retention-days: 7 # Adjust retention as needed diff --git a/tests/test_sample_binaries.py b/tests/test_sample_binaries.py index f98963af..80245cbb 100644 --- a/tests/test_sample_binaries.py +++ b/tests/test_sample_binaries.py @@ -1,5 +1,7 @@ import re +import shutil import subprocess +from pathlib import Path import pytest from decompiler.backend.codegenerator import FAIL_MESSAGE @@ -8,8 +10,23 @@ def test_sample(test_cases): """Test the decompiler with the given test case.""" sample, function_name = test_cases - output = subprocess.run(("python", "decompile.py", sample, function_name), check=True, capture_output=True).stdout.decode("utf-8") - assert FAIL_MESSAGE not in output + try: + output = subprocess.run(("python", "decompile.py", sample, function_name), check=True, capture_output=True).stdout.decode("utf-8") + failed = FAIL_MESSAGE in output + except subprocess.CalledProcessError as e: + failed = True + if failed: + __add_sample_to_crashed_sample_folder(sample, function_name) + assert not failed + + +def __add_sample_to_crashed_sample_folder(sample, function_name): + """Copy the sample to the crashed sample folder.""" + crash_dir = Path("crash_reports") + crash_dir.mkdir(exist_ok=True) + # Copy the binary to the crash directory + output_file = crash_dir / ("_".join(sample.parts[3:]) + "_" + function_name) + shutil.copy(sample, output_file) def test_globals():