Skip to content

Commit

Permalink
Merge pull request #109 from firedancer-io/mjain/regenerate-features
Browse files Browse the repository at this point in the history
Support custom regeneration implementations
  • Loading branch information
mjain-jump authored Jan 10, 2025
2 parents 4231e78 + 25fe8f6 commit 9ea9b39
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/test_suite/fuzz_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import test_suite.txn.diff_utils as txn_diff
import test_suite.instr.codec_utils as instr_codec
import test_suite.instr.prune_utils as instr_prune
import test_suite.instr.transform_utils as instr_transform
import test_suite.instr.diff_utils as instr_diff
import test_suite.syscall.codec_utils as syscall_codec

Expand All @@ -26,6 +27,7 @@
effects_human_encode_fn=instr_codec.encode_output,
consensus_diff_effect_fn=instr_diff.consensus_instr_diff_effects,
core_bpf_diff_effect_fn=instr_diff.core_bpf_instr_diff_effects,
regenerate_transformation_fn=instr_transform.transform_fixture,
)

SyscallHarness = HarnessCtx(
Expand Down
12 changes: 12 additions & 0 deletions src/test_suite/fuzz_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ def generic_human_decode(obj: message.Message) -> None:
pass


def generic_transform(obj: message.Message) -> None:
"""
Allows for applying custom transformations to each fixture (mainly the context) before
rerunning through the harness. For now, this is only used for fixture regeneration.
As the user, you may modify `fixture` in-place before the fixture context gets run against
a target and regenerated. To keep this function customizable, the implementation is left
to the user to decide what they want to do with the data.
"""
pass


@dataclass
class HarnessCtx:
fuzz_fn_name: str
Expand All @@ -98,6 +109,7 @@ class HarnessCtx:
context_human_decode_fn: Callable[[ContextType], None] = generic_human_decode
effects_human_encode_fn: Callable[[EffectsType], None] = generic_human_encode
effects_human_decode_fn: Callable[[EffectsType], None] = generic_human_decode
regenerate_transformation_fn: Callable[[FixtureType], None] = generic_transform
fixture_type: Type[FixtureType] = field(init=False)
context_type: Type[ContextType] = field(init=False)
effects_type: Type[EffectsType] = field(init=False)
Expand Down
6 changes: 6 additions & 0 deletions src/test_suite/instr/transform_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fd58
import test_suite.invoke_pb2 as invoke_pb


def transform_fixture(fixture: invoke_pb.InstrFixture):
pass
4 changes: 4 additions & 0 deletions src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@ def regenerate_fixtures(
# Apply minimum compatible features
if features is not None:
features.features[:] = new_feature_set

# Apply any custom transformations to the data
harness_ctx.regenerate_transformation_fn(fixture)

regenerated_fixture = create_fixture_from_context(
harness_ctx, fixture.input
)
Expand Down

0 comments on commit 9ea9b39

Please sign in to comment.