Skip to content

Commit

Permalink
compare effects without encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Oct 10, 2024
1 parent 9b2065a commit c31b86b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/test_suite/fuzz_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
Both context and effects messages can have their own encode/decode functions.
"""

def encode_hex_compact(buf):
res = ""
skipped = 0
for i in range(0, len(buf), 16):
row = buf[i:i+16]
if row == bytes([0]*len(row)):
skipped += len(row)
else:
if skipped > 0:
res += f"...{skipped} zeros..."
res += "".join([f"{b:0>2x}" for b in buf[i:i+16]])
if skipped > 0:
res += f"...{skipped} zeros..."
return bytes(res, "ascii")


def generic_effects_prune(
ctx: str | None, effects: dict[str, str | None]
Expand Down
5 changes: 3 additions & 2 deletions src/test_suite/multiprocessing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def build_test_results(results: dict[str, str | None]) -> tuple[int, dict | None

ref_effects = globals.harness_ctx.effects_type()
ref_effects.ParseFromString(ref_result)
globals.harness_ctx.effects_human_encode_fn(ref_effects)

# Log execution results
all_passed = True
Expand All @@ -292,14 +291,16 @@ def build_test_results(results: dict[str, str | None]) -> tuple[int, dict | None
# Turn bytes into human readable fields
effects = globals.harness_ctx.effects_type()
effects.ParseFromString(result)
globals.harness_ctx.effects_human_encode_fn(effects)

# Note: diff_effect_fn may modify effects in-place
all_passed &= globals.harness_ctx.diff_effect_fn(ref_effects, effects)

globals.harness_ctx.effects_human_encode_fn(effects)
outputs[target] = text_format.MessageToString(effects)
else:
all_passed = False

globals.harness_ctx.effects_human_encode_fn(ref_effects)
outputs[globals.reference_shared_library] = text_format.MessageToString(ref_effects)

# 1 = passed, -1 = failed
Expand Down
6 changes: 3 additions & 3 deletions src/test_suite/syscall/codec_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import test_suite.vm_pb2 as vm_pb

from test_suite.fuzz_interface import encode_hex_compact

def encode_output(effects: vm_pb.SyscallEffects):
"""
Expand All @@ -10,5 +10,5 @@ def encode_output(effects: vm_pb.SyscallEffects):
Args:
- effects (vm_pb.SyscallEffects): Syscall effects (will be modified).
"""
effects.heap = base64.b16encode(effects.heap)
effects.stack = b""
effects.heap = encode_hex_compact(effects.heap)
effects.stack = encode_hex_compact(effects.stack)

0 comments on commit c31b86b

Please sign in to comment.