Skip to content

Commit

Permalink
Merge pull request #82 from firedancer-io/exec-instr-fixture
Browse files Browse the repository at this point in the history
allow fixtures for exec-instr
  • Loading branch information
kbhargava-jump authored Sep 9, 2024
2 parents edbab65 + 4a5a232 commit f7a6955
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/test_suite/multiprocessing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ def get_feature_pool(library: ctypes.CDLL) -> FeaturePool:
return FeaturePool(supported, hardcoded)


def serialize_context(file: Path) -> str | None:
if file.suffix == ".fix":
fixture = globals.harness_ctx.fixture_type()
fixture.ParseFromString(file.open("rb").read())
serialized_instr_context = fixture.input.SerializeToString(deterministic=True)
else:
serialized_instr_context = read_context(file)

assert serialized_instr_context is not None, f"Unable to read {file.name}"
return serialized_instr_context


def run_test(test_file: Path) -> tuple[str, int, dict | None]:
"""
Runs a single test from start to finish.
Expand All @@ -337,14 +349,7 @@ def run_test(test_file: Path) -> tuple[str, int, dict | None]:
- Dictionary of target library names and file-dumpable serialized instruction effects
"""
# Process fixtures through this entrypoint as well
if test_file.suffix == ".fix":
fixture = globals.harness_ctx.fixture_type()
fixture.ParseFromString(test_file.open("rb").read())
serialized_instr_context = fixture.input.SerializeToString(deterministic=True)
else:
serialized_instr_context = read_context(test_file)
results = process_single_test_case(serialized_instr_context)
pruned_results = globals.harness_ctx.prune_effects_fn(
serialized_instr_context, results
)
context = serialize_context(test_file)
results = process_single_test_case(context)
pruned_results = globals.harness_ctx.prune_effects_fn(context, results)
return test_file.stem, *build_test_results(pruned_results)
4 changes: 2 additions & 2 deletions src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
initialize_process_output_buffers,
process_target,
run_test,
serialize_context,
)
import test_suite.globals as globals
from test_suite.debugger import debug_host
Expand Down Expand Up @@ -82,10 +83,9 @@ def exec_instr(
files_to_exec = file_or_dir.iterdir() if file_or_dir.is_dir() else [file_or_dir]
for file in files_to_exec:
print(f"Handling {file}...")
context = read_context(file)
assert context is not None, f"Unable to read {file.name}"

# Execute and cleanup
context = serialize_context(file)
effects = process_target(lib, context)

if not effects:
Expand Down

0 comments on commit f7a6955

Please sign in to comment.