-
Notifications
You must be signed in to change notification settings - Fork 160
Add flag --emit-json-spec to kprovex #2428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4ef1d22
kernel/unparser/ToJson: add apply method which takes a module
ehildenb 9be9bb2
kernel/{KProveOptions,kprovex/KProve}: add --emit-json-spec option
ehildenb 062aea9
kernel/kprove/KProve: add check for option not being used on kprove tool
ehildenb d709e54
kernel/{JsonParser,ToJson}: correct emitted nodes for KImport
ehildenb 33f5c0b
k-distribution/tests/pyk/Makefile: add --no-pager to diff check
tothtamas28 b9ccd43
Add test specification for kprovex --emit-json-spec
tothtamas28 802a17b
Add Python unit tests for kprovex --emit-json-spec
tothtamas28 b78923e
kernel/kprovex/KProve: use existing FileUtil
ehildenb 16e7072
java-backend/StateLog: use existing FileUtil
ehildenb e15489f
k-distribution/tests/pyk/Makefile: formatting, better clean target
ehildenb 2e800de
k-distribution/tests/pyk/Makefile: correct subtarget name for celan
ehildenb 45b43b3
kernel/kprovex/KProve: use saveToWorkingDirectory
ehildenb 31c0359
Merge remote-tracking branch 'upstream/master' into emit-json-kprovex
ehildenb 452b5d2
Revert "java-backend/StateLog: use existing FileUtil"
ehildenb ae9bf44
Merge branch 'master' into emit-json-kprovex
rv-jenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
k-distribution/tests/pyk/emit-json-spec-tests/emit_json_spec_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import json | ||
| import os | ||
| import shutil | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| from pyk.kast import KApply, KClaim, KDefinition, KRequire, KVariable | ||
| from pyk.kastManip import rewriteAnywhereWith | ||
| from pyk.ktool import KProve | ||
|
|
||
|
|
||
| class EmitJsonSpecTest(unittest.TestCase): | ||
| TEST_DIR = 'emit-json-spec-tests' | ||
| MAIN_FILE = 'verification.k' | ||
| USE_DIR = f'{TEST_DIR}/.kprove' | ||
|
|
||
| def setUp(self): | ||
| shutil.rmtree(self.USE_DIR, ignore_errors=True) | ||
| os.makedirs(self.USE_DIR) | ||
|
|
||
| self.kprove = KProve(f'{self.TEST_DIR}/verification-kompiled', self.MAIN_FILE, self.USE_DIR) | ||
| self.kprove.proverArgs += ['-I', '.'] | ||
| self._update_symbol_table(self.kprove) | ||
|
|
||
| with open(f'{self.TEST_DIR}/looping-spec.json', 'r') as spec_file: | ||
| module = json.load(spec_file)['term'] | ||
|
|
||
| claim = extract_claims(module)[0] | ||
| self.claim = KClaim( | ||
| body=eliminate_generated_top(claim['body']), | ||
| requires=claim['requires'], | ||
| ensures=claim['ensures'], | ||
| att=None | ||
| ) | ||
|
|
||
| module['localSentences'] = [self.claim] | ||
| self.module = module | ||
|
|
||
| def tearDown(self): | ||
| shutil.rmtree(self.USE_DIR) | ||
|
|
||
| @staticmethod | ||
| def _update_symbol_table(kprove): | ||
| def paren(f): | ||
| def unparse(*args): | ||
| return '(' + f(*args) + ')' | ||
| return unparse | ||
|
|
||
| kprove.symbolTable['_+Int_'] = paren(kprove.symbolTable['_+Int_']) | ||
|
|
||
| def test_prove_claim(self): | ||
| # When | ||
| result = self.kprove.proveClaim(self.claim, 'looping-1') | ||
|
|
||
| # Then | ||
| self.assertEqual(result['label'], '#Top') | ||
|
|
||
| def test_prove(self): | ||
| # Given | ||
| spec_name = 'looping-2-spec' | ||
| spec_path = Path(f'{self.USE_DIR}/{spec_name}.k') | ||
| spec_module_name = spec_name.upper() | ||
|
|
||
| self.module['name'] = spec_module_name | ||
| definition = KDefinition(self.module, [self.module], requires=[KRequire(self.MAIN_FILE)]) | ||
|
|
||
| with open(spec_path, 'x') as spec_file: | ||
| spec_file.write(self.kprove.prettyPrint(definition)) | ||
|
|
||
| # When | ||
| result = self.kprove.prove(spec_path, spec_module_name) | ||
|
|
||
| # Then | ||
| self.assertEqual(result['label'], '#Top') | ||
|
|
||
|
|
||
| def extract_claims(module): | ||
| return [claim for claim in module['localSentences'] if claim['node'] == 'KClaim'] | ||
|
|
||
|
|
||
| def eliminate_generated_top(term): | ||
| rule = KApply('<generatedTop>', [KVariable('CONFIG'), KVariable('_')]), KVariable('CONFIG') | ||
| return rewriteAnywhereWith(rule, term) | ||
|
tothtamas28 marked this conversation as resolved.
|
||
18 changes: 18 additions & 0 deletions
18
k-distribution/tests/pyk/emit-json-spec-tests/looping-spec.k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| requires "verification.k" | ||
|
|
||
| module LOOPING-SPEC | ||
| imports VERIFICATION | ||
|
|
||
| claim <k> while ( 1 <= $n ) { | ||
| $s = $s + $n ; | ||
| $n = $n + -1 ; | ||
| } | ||
| => . ... </k> | ||
| <state> $s |-> (S:Int => S +Int ((N +Int 1) *Int N /Int 2)) | ||
| $n |-> (N:Int => 0) | ||
| </state> | ||
| requires N >=Int 0 | ||
| andBool S >=Int 0 | ||
|
|
||
| endmodule | ||
|
|
12 changes: 12 additions & 0 deletions
12
k-distribution/tests/pyk/emit-json-spec-tests/verification.k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| requires "imp.k" | ||
|
|
||
| module VERIFICATION-SYNTAX | ||
| syntax Id ::= "$s" [token] | ||
| | "$n" [token] | ||
| endmodule | ||
|
|
||
| module VERIFICATION | ||
| imports VERIFICATION-SYNTAX | ||
| imports IMP | ||
| endmodule | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.