Skip to content

Commit 05869c0

Browse files
committed
use separate functions not an enum
1 parent c18fba2 commit 05869c0

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

src/test_suite/fuzz_context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
context_human_decode_fn=instr_codec.decode_input,
2626
effects_human_encode_fn=instr_codec.encode_output,
2727
consensus_diff_effect_fn=instr_diff.consensus_instr_diff_effects,
28+
core_bpf_diff_effect_fn=instr_diff.core_bpf_instr_diff_effects,
2829
)
2930

3031
SyscallHarness = HarnessCtx(

src/test_suite/fuzz_interface.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class HarnessCtx:
8888
consensus_diff_effect_fn: Callable[[EffectsType, EffectsType], bool] = (
8989
generic_effects_diff
9090
)
91+
core_bpf_diff_effect_fn: Callable[[EffectsType, EffectsType], bool] = (
92+
generic_effects_diff
93+
)
9194
prune_effects_fn: Callable[
9295
[ContextType | None, dict[str, str | None]], dict[str, str | None] | None
9396
] = generic_effects_prune

src/test_suite/instr/diff_utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
from enum import Enum
21
import test_suite.invoke_pb2 as invoke_pb
32

43

5-
class DiffMode(Enum):
6-
STANDARD = 0
7-
CONSENSUS = 1
8-
CORE_BPF = 2
9-
10-
def apply_diff(self, a: invoke_pb.InstrEffects, b: invoke_pb.InstrEffects):
11-
"""Applies the specified diff effects.
12-
- STANDARD: No diff effects.
13-
- CONSENSUS: Consensus-only diff effects.
14-
- CORE_BPF: Core BPF diff effects for testing a BPF program against a builtin.
15-
"""
16-
if self == DiffMode.CONSENSUS:
17-
return consensus_instr_diff_effects(a, b)
18-
if self == DiffMode.CORE_BPF:
19-
return core_bpf_instr_diff_effects(a, b)
20-
21-
224
def consensus_instr_diff_effects(a: invoke_pb.InstrEffects, b: invoke_pb.InstrEffects):
235
a_san = invoke_pb.InstrEffects()
246
a_san.CopyFrom(a)

src/test_suite/multiprocessing_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,13 @@ def build_test_results(
314314
effects = harness_ctx.effects_type()
315315
effects.ParseFromString(result)
316316

317-
# Note: apply_diff may modify effects in-place
318-
all_passed &= globals.diff_mode.apply_diff(ref_effects, effects)
317+
if globals.consensus_mode:
318+
harness_ctx.diff_effect_fn = harness_ctx.consensus_diff_effect_fn
319+
if globals.core_bpf_mode:
320+
harness_ctx.diff_effect_fn = harness_ctx.core_bpf_diff_effect_fn
321+
322+
# Note: diff_effect_fn may modify effects in-place
323+
all_passed &= harness_ctx.diff_effect_fn(ref_effects, effects)
319324

320325
harness_ctx.effects_human_encode_fn(effects)
321326
outputs[target] = text_format.MessageToString(effects)

src/test_suite/test_suite.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
extract_context_from_fixture,
1818
write_fixture_to_disk,
1919
)
20-
from test_suite.instr.diff_utils import DiffMode
2120
from test_suite.log_utils import log_results
2221
from test_suite.multiprocessing_utils import (
2322
decode_single_test_case,
@@ -406,12 +405,10 @@ def run_tests(
406405
err=True,
407406
)
408407
raise typer.Exit(code=1)
409-
if consensus_mode:
410-
globals.diff_mode = DiffMode.CONSENSUS
411-
elif core_bpf_mode:
412-
globals.diff_mode = DiffMode.CORE_BPF
413-
else:
414-
globals.diff_mode = DIffMode.STANDARD
408+
# Set diff mode to consensus if specified
409+
globals.consensus_mode = consensus_mode
410+
# Set diff mode to core_bpf if specified
411+
globals.core_bpf_mode = core_bpf_mode
415412

416413
# Create the output directory, if necessary
417414
if globals.output_dir.exists():

0 commit comments

Comments
 (0)