Skip to content

Commit 92793f3

Browse files
feat: filter reference test with specified parameter
1 parent f036e39 commit 92793f3

File tree

9 files changed

+73
-34
lines changed

9 files changed

+73
-34
lines changed

packages/testing/src/execution_testing/cli/pytest_commands/plugins/shared/benchmarking.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,30 @@ def pytest_collection_modifyitems(
5050
# If --fixed-opcode-count is not specified, don't filter anything
5151
return
5252

53-
items = [
54-
item
55-
for item in items
56-
if not (
57-
item.get_closest_marker("benchmark") is not None
58-
and item.get_closest_marker("repricing") is None
59-
)
60-
]
53+
filtered = []
54+
for item in items:
55+
if not item.get_closest_marker("benchmark"):
56+
continue
57+
58+
repricing_marker = item.get_closest_marker("repricing")
59+
if not repricing_marker:
60+
continue
61+
62+
if not repricing_marker.kwargs:
63+
filtered.append(item)
64+
continue
65+
66+
if hasattr(item, "callspec"):
67+
if all(
68+
item.callspec.params.get(key) == value
69+
for key, value in repricing_marker.kwargs.items()
70+
):
71+
filtered.append(item)
72+
else:
73+
if not repricing_marker.kwargs:
74+
filtered.append(item)
75+
76+
items[:] = filtered
6177

6278

6379
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:

tests/benchmark/compute/instruction/test_account_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040

4141

42-
@pytest.mark.repricing
42+
@pytest.mark.repricing(contract_balance=0)
4343
@pytest.mark.parametrize("contract_balance", [0, 1])
4444
def test_selfbalance(
4545
benchmark_test: BenchmarkTestFiller,
@@ -359,7 +359,7 @@ def test_extcodecopy_warm(
359359
benchmark_test(tx=tx)
360360

361361

362-
@pytest.mark.repricing
362+
@pytest.mark.repricing(absent_target=False)
363363
@pytest.mark.parametrize(
364364
"opcode",
365365
[

tests/benchmark/compute/instruction/test_arithmetic.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,26 @@
3333
from tests.benchmark.compute.helpers import DEFAULT_BINOP_ARGS, make_dup, neg
3434

3535

36-
@pytest.mark.repricing
3736
@pytest.mark.parametrize(
3837
"opcode,opcode_args",
3938
[
40-
(
39+
pytest.param(
4140
Op.ADD,
4241
DEFAULT_BINOP_ARGS,
42+
marks=pytest.mark.repricing,
4343
),
44-
(
44+
pytest.param(
4545
Op.MUL,
4646
DEFAULT_BINOP_ARGS,
47+
marks=pytest.mark.repricing,
4748
),
48-
(
49+
pytest.param(
4950
# After every 2 SUB operations, values return to initial.
5051
Op.SUB,
5152
DEFAULT_BINOP_ARGS,
53+
marks=pytest.mark.repricing,
5254
),
53-
(
55+
pytest.param(
5456
# This has the cycle of 2:
5557
# v[0] = a // b
5658
# v[1] = a // v[0] = a // (a // b) = b
@@ -63,8 +65,9 @@
6365
# optimized paths for division by 1 and 2 words.
6466
0x100000000000000000000000000000033,
6567
),
68+
marks=pytest.mark.repricing,
6669
),
67-
(
70+
pytest.param(
6871
# This has the cycle of 2, see above.
6972
Op.DIV,
7073
(
@@ -75,16 +78,17 @@
7578
0x10000000000000033,
7679
),
7780
),
78-
(
81+
pytest.param(
7982
# Same as DIV-0
8083
# But the numerator made positive, and the divisor made negative.
8184
Op.SDIV,
8285
(
8386
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F,
8487
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCD,
8588
),
89+
marks=pytest.mark.repricing,
8690
),
87-
(
91+
pytest.param(
8892
# Same as DIV-1
8993
# But the numerator made positive, and the divisor made negative.
9094
Op.SDIV,
@@ -93,32 +97,36 @@
9397
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFCD,
9498
),
9599
),
96-
(
100+
pytest.param(
97101
# Not suitable for MOD, as values quickly become zero.
98102
Op.MOD,
99103
DEFAULT_BINOP_ARGS,
104+
marks=pytest.mark.repricing,
100105
),
101-
(
106+
pytest.param(
102107
# Not suitable for SMOD, as values quickly become zero.
103108
Op.SMOD,
104109
DEFAULT_BINOP_ARGS,
110+
marks=pytest.mark.repricing,
105111
),
106-
(
112+
pytest.param(
107113
# This keeps the values unchanged
108114
# pow(2**256-1, 2**256-1, 2**256) == 2**256-1.
109115
Op.EXP,
110116
(
111117
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
112118
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
113119
),
120+
marks=pytest.mark.repricing,
114121
),
115-
(
122+
pytest.param(
116123
# Not great, as we always sign-extend the 4 bytes.
117124
Op.SIGNEXTEND,
118125
(
119126
3,
120127
0xFFDADADA, # Negative to have more work.
121128
),
129+
marks=pytest.mark.repricing,
122130
),
123131
],
124132
ids=lambda param: "" if isinstance(param, tuple) else param,
@@ -150,7 +158,7 @@ def test_arithmetic(
150158
)
151159

152160

153-
@pytest.mark.repricing
161+
@pytest.mark.repricing(mod_bits=255)
154162
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
155163
@pytest.mark.parametrize("op", [Op.MOD, Op.SMOD])
156164
def test_mod(
@@ -269,6 +277,7 @@ def test_mod(
269277
)
270278

271279

280+
@pytest.mark.repricing(mod_bits=255)
272281
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
273282
@pytest.mark.parametrize("op", [Op.ADDMOD, Op.MULMOD])
274283
def test_mod_arithmetic(

tests/benchmark/compute/instruction/test_call_context.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_call_frame_context_ops(
4949
)
5050

5151

52-
@pytest.mark.repricing
52+
@pytest.mark.repricing(calldata_length=1_000)
5353
@pytest.mark.parametrize("calldata_length", [0, 1_000, 10_000])
5454
def test_calldatasize(
5555
benchmark_test: BenchmarkTestFiller,
@@ -64,6 +64,7 @@ def test_calldatasize(
6464
)
6565

6666

67+
@pytest.mark.repricing(non_zero_value=True, from_origin=True)
6768
@pytest.mark.parametrize("non_zero_value", [True, False])
6869
@pytest.mark.parametrize("from_origin", [True, False])
6970
def test_callvalue(
@@ -103,7 +104,7 @@ def test_callvalue(
103104
benchmark_test(tx=tx)
104105

105106

106-
@pytest.mark.repricing
107+
@pytest.mark.repricing(calldata=b"")
107108
@pytest.mark.parametrize(
108109
"calldata",
109110
[
@@ -233,7 +234,10 @@ def test_calldatacopy(
233234
benchmark_test(tx=tx)
234235

235236

236-
@pytest.mark.repricing
237+
@pytest.mark.repricing(
238+
returned_size=1,
239+
return_data_style=ReturnDataStyle.RETURN,
240+
)
237241
@pytest.mark.parametrize(
238242
"return_data_style",
239243
[
@@ -287,7 +291,7 @@ def test_returndatasize_zero(
287291
)
288292

289293

290-
@pytest.mark.repricing
294+
@pytest.mark.repricing(size=10 * 1024, fixed_dst=True)
291295
@pytest.mark.parametrize(
292296
"size",
293297
[

tests/benchmark/compute/instruction/test_log.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
)
1919

2020

21-
@pytest.mark.repricing
21+
@pytest.mark.repricing(
22+
size=1024 * 1024,
23+
non_zero_data=True,
24+
zeros_topic=False,
25+
fixed_offset=True,
26+
)
2227
@pytest.mark.parametrize(
2328
"opcode",
2429
[

tests/benchmark/compute/instruction/test_memory.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
@pytest.mark.repricing
22+
@pytest.mark.repricing(mem_size=1_000)
2323
@pytest.mark.parametrize("mem_size", [0, 1, 1_000, 100_000, 1_000_000])
2424
def test_msize(
2525
benchmark_test: BenchmarkTestFiller,
@@ -39,7 +39,11 @@ def test_msize(
3939
)
4040

4141

42-
@pytest.mark.repricing
42+
@pytest.mark.repricing(
43+
offset=31,
44+
offset_initialized=True,
45+
big_memory_expansion=True,
46+
)
4347
@pytest.mark.parametrize("opcode", [Op.MLOAD, Op.MSTORE, Op.MSTORE8])
4448
@pytest.mark.parametrize("offset", [0, 1, 31])
4549
@pytest.mark.parametrize("offset_initialized", [True, False])
@@ -73,7 +77,7 @@ def test_memory_access(
7377
)
7478

7579

76-
@pytest.mark.repricing
80+
@pytest.mark.repricing(size=10 * 1024, fixed_src_dst=True)
7781
@pytest.mark.parametrize(
7882
"size",
7983
[

tests/benchmark/compute/instruction/test_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from tests.benchmark.compute.helpers import StorageAction, TransactionResult
2828

2929

30+
@pytest.mark.repricing(key_mut=False, val_mut=False)
3031
# `key_mut` indicates the key isn't fixed.
3132
@pytest.mark.parametrize("key_mut", [True, False])
3233
# `val_mut` indicates that at the end of each big-loop, the value of the target
@@ -72,7 +73,7 @@ def test_tload(
7273
)
7374

7475

75-
@pytest.mark.repricing
76+
@pytest.mark.repricing(key_mut=False, dense_val_mut=False)
7677
@pytest.mark.parametrize("key_mut", [True, False])
7778
@pytest.mark.parametrize("dense_val_mut", [True, False])
7879
def test_tstore(

tests/benchmark/compute/instruction/test_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_creates_collisions(
431431
)
432432

433433

434-
@pytest.mark.repricing
434+
@pytest.mark.repricing(return_size=1024, return_non_zero_data=True)
435435
@pytest.mark.parametrize(
436436
"opcode",
437437
[Op.RETURN, Op.REVERT],

tests/benchmark/compute/instruction/test_tx_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_call_frame_context_ops(
4040
)
4141

4242

43-
@pytest.mark.repricing
43+
@pytest.mark.repricing(blob_index=0, blobs_present=0)
4444
@pytest.mark.parametrize(
4545
"blob_index, blobs_present",
4646
[

0 commit comments

Comments
 (0)