Skip to content

Commit 57b1cd3

Browse files
authored
Merge pull request #103 from buffalojoec/core-bpf-mode
add core bpf mode with new diff fn
2 parents 7fdc056 + 05869c0 commit 57b1cd3

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

commands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ $ solana-test-suite run-tests [OPTIONS]
230230
* `-r, --randomize-output-buffer`: Randomizes bytes in output buffer before shared library execution
231231
* `-c, --chunk-size INTEGER`: Number of test results per file [default: 10000]
232232
* `-v, --verbose`: Verbose output: log failed test cases
233-
* `-c, --consensus-mode`: Only fail on consensus failures. One such effect is to normalize error codes when comparing results
233+
* `-c, --consensus-mode`: Only fail on consensus failures. One such effect is to normalize error codes when comparing results. Note: Cannot be used with --core-bpf-mode.
234+
* `-cb, --core-bpf-mode`: Deliberately skip known mismatches between BPF programs and builtins, only failing on genuine mimatches. For example, builtin programs may throw errors on readonly account state violations sooner than BPF programs, compute unit usage will be different, etc. This feature is primarily used to test a BPF program against a builtin. Note: Cannot be used with --consensus-mode.
234235
* `-f, --failures-only`: Only log failed test cases
235236
* `-sf, --save-failures`: Saves failed test cases to results directory
236237
* `-ss, --save-successes`: Saves successful test cases to results directory

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,29 @@ def consensus_instr_diff_effects(a: invoke_pb.InstrEffects, b: invoke_pb.InstrEf
1717
b_san.cu_avail = 0
1818

1919
return a_san == b_san
20+
21+
22+
def core_bpf_instr_diff_effects(a: invoke_pb.InstrEffects, b: invoke_pb.InstrEffects):
23+
a_san = invoke_pb.InstrEffects()
24+
a_san.CopyFrom(a)
25+
b_san = invoke_pb.InstrEffects()
26+
b_san.CopyFrom(b)
27+
28+
# If the result is an error (not 0), don't return modified accounts.
29+
if a_san.result != 0:
30+
while len(a_san.modified_accounts) > 0:
31+
a_san.modified_accounts.pop()
32+
if b_san.result != 0:
33+
while len(b_san.modified_accounts) > 0:
34+
b_san.modified_accounts.pop()
35+
36+
# Normalize error codes and cus
37+
a_san.result = 0
38+
a_san.custom_err = 0
39+
a_san.cu_avail = 0
40+
41+
b_san.result = 0
42+
b_san.custom_err = 0
43+
b_san.cu_avail = 0
44+
45+
return a_san == b_san

src/test_suite/multiprocessing_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ def build_test_results(
316316

317317
if globals.consensus_mode:
318318
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
319321

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

src/test_suite/test_suite.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,17 @@ def run_tests(
353353
False,
354354
"--consensus-mode",
355355
"-c",
356-
help="Only fail on consensus failures. One such effect is to normalize error codes when comparing results",
356+
help="Only fail on consensus failures. One such effect is to normalize error codes when comparing results. \
357+
Note: Cannot be used with --core-bpf-mode.",
358+
),
359+
core_bpf_mode: bool = typer.Option(
360+
False,
361+
"--core-bpf-mode",
362+
"-cb",
363+
help="Deliberately skip known mismatches between BPF programs and builtins, only failing on genuine mimatches. \
364+
For example, builtin programs may throw errors on readonly account state violations sooner than BPF programs, \
365+
compute unit usage will be different, etc. This feature is primarily used to test a BPF program against a builtin. \
366+
Note: Cannot be used with --consensus-mode.",
357367
),
358368
failures_only: bool = typer.Option(
359369
False,
@@ -388,8 +398,17 @@ def run_tests(
388398
globals.reference_shared_library = reference_shared_library
389399
globals.default_harness_ctx = HARNESS_MAP[default_harness_ctx]
390400

401+
# Set diff mode if specified
402+
if consensus_mode and core_bpf_mode:
403+
typer.echo(
404+
"Error: --consensus-mode and --core-bpf-mode cannot be used together.",
405+
err=True,
406+
)
407+
raise typer.Exit(code=1)
391408
# Set diff mode to consensus if specified
392409
globals.consensus_mode = consensus_mode
410+
# Set diff mode to core_bpf if specified
411+
globals.core_bpf_mode = core_bpf_mode
393412

394413
# Create the output directory, if necessary
395414
if globals.output_dir.exists():
@@ -703,6 +722,7 @@ def debug_mismatches(
703722
log_chunk_size=10000,
704723
verbose=True,
705724
consensus_mode=False,
725+
core_bpf_mode=False,
706726
failures_only=False,
707727
save_failures=True,
708728
save_successes=True,

0 commit comments

Comments
 (0)