2
2
3
3
import logging
4
4
import sys
5
- from pathlib import Path
6
5
from typing import TYPE_CHECKING , NamedTuple
7
6
8
7
import pytest
24
23
25
24
if TYPE_CHECKING :
26
25
from collections .abc import Callable
26
+ from pathlib import Path
27
27
from typing import Final
28
28
29
29
from pyk .utils import BugReport
@@ -52,18 +52,17 @@ def spec_files(dir_name: str, glob: str) -> tuple[Path, ...]:
52
52
53
53
54
54
BENCHMARK_TESTS : Final = spec_files ('benchmarks' , '*-spec.k' )
55
- FUNCTIONAL_TESTS : Final = spec_files ('functional' , '*-spec.k' )
56
55
ERC20_TESTS : Final = spec_files ('erc20' , '*/*-spec.k' )
57
56
EXAMPLES_TESTS : Final = spec_files ('examples' , '*-spec.k' ) + spec_files ('examples' , '*-spec.md' )
58
57
MCD_TESTS : Final = spec_files ('mcd' , '*-spec.k' )
59
58
VAT_TESTS : Final = spec_files ('mcd' , 'vat*-spec.k' )
60
59
NON_VAT_MCD_TESTS : Final = tuple (test for test in MCD_TESTS if test not in VAT_TESTS )
61
60
KONTROL_TESTS : Final = spec_files ('kontrol' , '*-spec.k' )
61
+ FUNCTIONAL_TESTS : Final = spec_files ('functional' , '*-spec.k' )
62
62
63
- ALL_TESTS : Final = sum (
63
+ RULE_TESTS : Final = sum (
64
64
[
65
65
BENCHMARK_TESTS ,
66
- FUNCTIONAL_TESTS ,
67
66
ERC20_TESTS ,
68
67
EXAMPLES_TESTS ,
69
68
NON_VAT_MCD_TESTS ,
@@ -72,6 +71,11 @@ def spec_files(dir_name: str, glob: str) -> tuple[Path, ...]:
72
71
(),
73
72
)
74
73
74
+ ALL_TESTS : Final = sum (
75
+ [RULE_TESTS , FUNCTIONAL_TESTS , VAT_TESTS ],
76
+ (),
77
+ )
78
+
75
79
76
80
def exclude_list (exclude_file : Path ) -> list [Path ]:
77
81
res = [REPO_ROOT / test_path for test_path in exclude_file .read_text ().splitlines ()]
@@ -171,6 +175,72 @@ def _target_for_spec(spec_file: Path) -> Target:
171
175
return Target (main_file , main_module_name )
172
176
173
177
178
+ def _test_prove (
179
+ spec_file : Path ,
180
+ kompiled_target_for : Callable [[Path ], Path ],
181
+ tmp_path : Path ,
182
+ caplog : LogCaptureFixture ,
183
+ no_use_booster : bool ,
184
+ use_booster_dev : bool ,
185
+ bug_report : BugReport | None ,
186
+ spec_name : str | None ,
187
+ workers : int | None = None ,
188
+ direct_subproof_rules : bool = False ,
189
+ ) -> None :
190
+ caplog .set_level (logging .INFO )
191
+
192
+ if use_booster_dev and spec_file in FAILING_BOOSTER_DEV_TESTS :
193
+ pytest .skip ()
194
+
195
+ if spec_name is not None and str (spec_file ).find (spec_name ) < 0 :
196
+ pytest .skip ()
197
+
198
+ # Given
199
+ log_file = tmp_path / 'log.txt'
200
+ use_directory = tmp_path / 'kprove'
201
+ use_directory .mkdir ()
202
+
203
+ # When
204
+ try :
205
+ definition_dir = kompiled_target_for (spec_file )
206
+ name = str (spec_file .relative_to (SPEC_DIR ))
207
+ break_on_calls = name in TEST_PARAMS and TEST_PARAMS [name ].break_on_calls
208
+ break_on_basic_blocks = name in TEST_PARAMS and TEST_PARAMS [name ].break_on_basic_blocks
209
+ if workers is None :
210
+ workers = 1 if name not in TEST_PARAMS else TEST_PARAMS [name ].workers
211
+ options = ProveOptions (
212
+ {
213
+ 'spec_file' : spec_file ,
214
+ 'definition_dir' : definition_dir ,
215
+ 'includes' : [str (include_dir ) for include_dir in config .INCLUDE_DIRS ],
216
+ 'save_directory' : use_directory ,
217
+ 'md_selector' : 'foo' , # TODO Ignored flag, this is to avoid KeyError
218
+ 'use_booster' : not no_use_booster ,
219
+ 'use_booster_dev' : use_booster_dev ,
220
+ 'bug_report' : bug_report ,
221
+ 'break_on_calls' : break_on_calls ,
222
+ 'break_on_basic_blocks' : break_on_basic_blocks ,
223
+ 'workers' : workers ,
224
+ 'direct_subproof_rules' : direct_subproof_rules ,
225
+ }
226
+ )
227
+ exec_prove (options = options )
228
+ if name in TEST_PARAMS :
229
+ params = TEST_PARAMS [name ]
230
+ if params .leaf_number is not None and params .main_claim_id is not None :
231
+ apr_proof = APRProof .read_proof_data (
232
+ proof_dir = use_directory ,
233
+ id = params .main_claim_id ,
234
+ )
235
+ expected_leaf_number = params .leaf_number
236
+ actual_leaf_number = leaf_number (apr_proof )
237
+ assert expected_leaf_number == actual_leaf_number
238
+ except BaseException :
239
+ raise
240
+ finally :
241
+ log_file .write_text (caplog .text )
242
+
243
+
174
244
@pytest .mark .parametrize (
175
245
'spec_file' ,
176
246
ALL_TESTS ,
@@ -223,10 +293,6 @@ def __init__(
223
293
224
294
225
295
TEST_PARAMS : dict [str , TParams ] = {
226
- 'mcd/vat-slip-pass-rough-spec.k' : TParams (
227
- main_claim_id = 'VAT-SLIP-PASS-ROUGH-SPEC.Vat.slip.pass.rough' ,
228
- leaf_number = 1 ,
229
- ),
230
296
'functional/lemmas-spec.k' : TParams (workers = 8 ),
231
297
'examples/sum-to-n-foundry-spec.k' : TParams (break_on_basic_blocks = True ),
232
298
}
@@ -243,10 +309,10 @@ def leaf_number(proof: APRProof) -> int:
243
309
244
310
@pytest .mark .parametrize (
245
311
'spec_file' ,
246
- ALL_TESTS ,
247
- ids = [str (spec_file .relative_to (SPEC_DIR )) for spec_file in ALL_TESTS ],
312
+ RULE_TESTS ,
313
+ ids = [str (spec_file .relative_to (SPEC_DIR )) for spec_file in RULE_TESTS ],
248
314
)
249
- def test_pyk_prove (
315
+ def test_prove_rules (
250
316
spec_file : Path ,
251
317
kompiled_target_for : Callable [[Path ], Path ],
252
318
tmp_path : Path ,
@@ -256,56 +322,65 @@ def test_pyk_prove(
256
322
bug_report : BugReport | None ,
257
323
spec_name : str | None ,
258
324
) -> None :
259
- caplog .set_level (logging .INFO )
325
+ _test_prove (
326
+ spec_file ,
327
+ kompiled_target_for ,
328
+ tmp_path ,
329
+ caplog ,
330
+ no_use_booster ,
331
+ use_booster_dev ,
332
+ bug_report = bug_report ,
333
+ spec_name = spec_name ,
334
+ )
260
335
261
- if use_booster_dev and spec_file in FAILING_BOOSTER_DEV_TESTS :
262
- pytest .skip ()
263
336
264
- if spec_name is not None and str (spec_file ).find (spec_name ) < 0 :
265
- pytest .skip ()
337
+ @pytest .mark .parametrize (
338
+ 'spec_file' ,
339
+ FUNCTIONAL_TESTS ,
340
+ ids = [str (spec_file .relative_to (SPEC_DIR )) for spec_file in FUNCTIONAL_TESTS ],
341
+ )
342
+ def test_prove_functional (
343
+ spec_file : Path ,
344
+ kompiled_target_for : Callable [[Path ], Path ],
345
+ tmp_path : Path ,
346
+ caplog : LogCaptureFixture ,
347
+ no_use_booster : bool ,
348
+ use_booster_dev : bool ,
349
+ bug_report : BugReport | None ,
350
+ spec_name : str | None ,
351
+ ) -> None :
352
+ _test_prove (
353
+ spec_file ,
354
+ kompiled_target_for ,
355
+ tmp_path ,
356
+ caplog ,
357
+ no_use_booster ,
358
+ use_booster_dev ,
359
+ bug_report = bug_report ,
360
+ spec_name = spec_name ,
361
+ workers = 8 ,
362
+ )
266
363
267
- # Given
268
- log_file = tmp_path / 'log.txt'
269
- use_directory = tmp_path / 'kprove'
270
- use_directory .mkdir ()
271
364
272
- # When
273
- try :
274
- definition_dir = kompiled_target_for (spec_file )
275
- name = str (spec_file .relative_to (SPEC_DIR ))
276
- break_on_calls = name in TEST_PARAMS and TEST_PARAMS [name ].break_on_calls
277
- break_on_basic_blocks = name in TEST_PARAMS and TEST_PARAMS [name ].break_on_basic_blocks
278
- workers = 1 if name not in TEST_PARAMS else TEST_PARAMS [name ].workers
279
- options = ProveOptions (
280
- {
281
- 'spec_file' : spec_file ,
282
- 'definition_dir' : definition_dir ,
283
- 'includes' : [str (include_dir ) for include_dir in config .INCLUDE_DIRS ],
284
- 'save_directory' : use_directory ,
285
- 'md_selector' : 'foo' , # TODO Ignored flag, this is to avoid KeyError
286
- 'use_booster' : not no_use_booster ,
287
- 'use_booster_dev' : use_booster_dev ,
288
- 'bug_report' : bug_report ,
289
- 'break_on_calls' : break_on_calls ,
290
- 'break_on_basic_blocks' : break_on_basic_blocks ,
291
- 'workers' : workers ,
292
- }
293
- )
294
- exec_prove (options = options )
295
- if name in TEST_PARAMS :
296
- params = TEST_PARAMS [name ]
297
- if params .leaf_number is not None and params .main_claim_id is not None :
298
- apr_proof = APRProof .read_proof_data (
299
- proof_dir = use_directory ,
300
- id = params .main_claim_id ,
301
- )
302
- expected_leaf_number = params .leaf_number
303
- actual_leaf_number = leaf_number (apr_proof )
304
- assert expected_leaf_number == actual_leaf_number
305
- except BaseException :
306
- raise
307
- finally :
308
- log_file .write_text (caplog .text )
365
+ def test_prove_dss (
366
+ kompiled_target_for : Callable [[Path ], Path ],
367
+ tmp_path : Path ,
368
+ caplog : LogCaptureFixture ,
369
+ bug_report : BugReport | None ,
370
+ ) -> None :
371
+ spec_file = REPO_ROOT / 'tests/specs/mcd/vat-spec.k'
372
+ _test_prove (
373
+ spec_file ,
374
+ kompiled_target_for ,
375
+ tmp_path ,
376
+ caplog ,
377
+ False ,
378
+ False ,
379
+ bug_report = bug_report ,
380
+ spec_name = None ,
381
+ workers = 8 ,
382
+ direct_subproof_rules = True ,
383
+ )
309
384
310
385
311
386
def test_prove_optimizations (
@@ -355,45 +430,3 @@ def _get_optimization_proofs() -> list[APRProof]:
355
430
proof_display = '\n ' .join (' ' + line for line in proof_show .show (proof ))
356
431
_LOGGER .info (f'Proof { proof .id } :\n { proof_display } ' )
357
432
assert proof .passed
358
-
359
-
360
- def test_prove_dss (
361
- kompiled_target_for : Callable [[Path ], Path ],
362
- tmp_path : Path ,
363
- caplog : LogCaptureFixture ,
364
- bug_report : BugReport | None ,
365
- spec_name : str | None ,
366
- ) -> None :
367
- spec_file = Path ('../tests/specs/mcd/vat-spec.k' )
368
- caplog .set_level (logging .INFO )
369
-
370
- if spec_name is not None and str (spec_file ).find (spec_name ) < 0 :
371
- pytest .skip ()
372
-
373
- # Given
374
- log_file = tmp_path / 'log.txt'
375
- use_directory = tmp_path / 'kprove'
376
- use_directory .mkdir ()
377
-
378
- # When
379
- try :
380
- definition_dir = kompiled_target_for (spec_file )
381
- options = ProveOptions (
382
- {
383
- 'spec_file' : spec_file ,
384
- 'definition_dir' : definition_dir ,
385
- 'includes' : [str (include_dir ) for include_dir in config .INCLUDE_DIRS ],
386
- 'save_directory' : use_directory ,
387
- 'md_selector' : 'foo' , # TODO Ignored flag, this is to avoid KeyError
388
- 'use_booster' : True ,
389
- 'bug_report' : bug_report ,
390
- 'break_on_calls' : False ,
391
- 'workers' : 8 ,
392
- 'direct_subproof_rules' : True ,
393
- }
394
- )
395
- exec_prove (options = options )
396
- except BaseException :
397
- raise
398
- finally :
399
- log_file .write_text (caplog .text )
0 commit comments