Skip to content

Commit

Permalink
Fix an issue with parallel tests potentially clashing (#468)
Browse files Browse the repository at this point in the history
* Fix an issue with parallel tests potentially clashing

* Run pre-commit
  • Loading branch information
ANogin committed Jun 6, 2024
1 parent 336dacb commit 0a8d9c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions ofrak_core/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
autoflake==1.4
# pytest-lazy-fixture does not work with pytest 8.0.0 - https://github.com/TvoroG/pytest-lazy-fixture/issues/65
pytest<8.0
filelock
hypothesis~=6.39.3
hypothesis-trio
trio-asyncio
Expand Down
25 changes: 15 additions & 10 deletions ofrak_core/test_ofrak/components/test_patch_maker_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
import re
import subprocess
import filelock

from ofrak.core import MemoryRegion
from ofrak.model.resource_model import EphemeralResourceContextFactory, ClientResourceContextFactory
Expand Down Expand Up @@ -230,19 +231,23 @@ async def test_function_replacement_modifier(ofrak_context: OFRAKContext, config

await target_program.resource.run(FunctionReplacementModifier, function_replacement_config)
new_program_path = f"replaced_{Path(config.program.path).name}"
await target_program.resource.flush_data_to_disk(new_program_path)

# Check that the modified program looks as expected.
readobj_path = get_repository_config(config.toolchain_name, "BIN_PARSER")
# When running tests in parallel, do this one at a time
lock = filelock.FileLock(new_program_path + ".lock")
with lock:
await target_program.resource.flush_data_to_disk(new_program_path)

# LLVM-specific fix: use llvm-objdump, not llvm-readobj
if "readobj" in readobj_path:
readobj_path = readobj_path.replace("readobj", "objdump")
# Check that the modified program looks as expected.
readobj_path = get_repository_config(config.toolchain_name, "BIN_PARSER")

subprocess_result = subprocess.run(
[readobj_path, "-d", new_program_path], capture_output=True, text=True
)
readobj_output = subprocess_result.stdout
# LLVM-specific fix: use llvm-objdump, not llvm-readobj
if "readobj" in readobj_path:
readobj_path = readobj_path.replace("readobj", "objdump")

subprocess_result = subprocess.run(
[readobj_path, "-d", new_program_path], capture_output=True, text=True
)
readobj_output = subprocess_result.stdout

expected_objdump_output_str = "\n".join(config.expected_objdump_output)

Expand Down

0 comments on commit 0a8d9c3

Please sign in to comment.