Skip to content

Commit 154ac3f

Browse files
Kore Server: fix substitution result sort (#3386)
* Kore Server: fix substitution result sort * update expected sort in implication check endpoint tests * Add instructions to update golden files to README Co-authored-by: Jost Berthold <[email protected]>
1 parent 0bb5f8b commit 154ac3f

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

kore/src/Kore/JsonRpc.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ respond runSMT serializedModule =
347347
{ term =
348348
PatternJson.fromTermLike $ Pattern.term p
349349
, substitution =
350-
PatternJson.fromSubstitution $ Pattern.substitution p
350+
PatternJson.fromSubstitution sort $ Pattern.substitution p
351351
, predicate =
352352
case Pattern.predicate p of
353353
PredicateTrue -> Nothing
@@ -395,7 +395,7 @@ respond runSMT serializedModule =
395395
predicate =
396396
PatternJson.fromPredicate sort $ Condition.predicate pat
397397
mbSubstitution =
398-
PatternJson.fromSubstitution $ Condition.substitution pat
398+
PatternJson.fromSubstitution sort $ Condition.substitution pat
399399
noSubstitution = PatternJson.fromTermLike $ TermLike.mkTop sort
400400
in Condition
401401
{ predicate

kore/src/Kore/Syntax/Json.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ becomes
116116
117117
The result sort is fixed to a made-up sort variable.
118118
-}
119-
fromSubstitution :: Substitution VariableName -> Maybe KoreJson
120-
fromSubstitution subst
119+
fromSubstitution :: Kore.Sort -> Substitution VariableName -> Maybe KoreJson
120+
fromSubstitution sort subst
121121
| Substitution.null subst = Nothing
122122
| otherwise =
123123
Just
@@ -127,16 +127,11 @@ fromSubstitution subst
127127
. Substitution.unwrap
128128
$ subst
129129
where
130-
freshSort =
131-
Kore.SortVariableSort
132-
. Kore.SortVariable
133-
$ Kore.noLocationId "JSONSortVariable"
134-
135130
equals ::
136131
Kore.SomeVariable VariableName ->
137132
TermLike VariableName ->
138133
TermLike VariableName
139-
v `equals` t = TermLike.mkEquals freshSort (TermLike.mkVar v) t
134+
v `equals` t = TermLike.mkEquals sort (TermLike.mkVar v) t
140135

141136
asPair :: Assignment v -> (Kore.SomeVariable v, TermLike v)
142137
asPair (Substitution.Assignment v t) = (v, t)

test/rpc-server/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
# JSON RPC Roundtrip tests
22

3-
This README provides a guide for adding more tests to this test suite.
3+
## Requirements
44

5-
To add a test, you wil need to create a new folder in one of `execute/`, `simplify/`, etc. folders, corresponding to the API methods.
5+
The tests in this directory are run using the python-3 script `runTests.py`.
6+
It requires the library `jsonrpcclient` (simply use `pip install jsonrpcclient` to get it).
7+
8+
## Running tests
9+
10+
Tests are run using
11+
12+
```
13+
python3 ./runTests.py
14+
```
15+
16+
The command will stop at the first failure, highlighting the difference to the expected output in colour.
17+
18+
## Updating the tests when the expected output changes
19+
20+
When the expected JSON output of any tests is expected to change, you can
21+
run the tests with `RECREATE_BROKEN_GOLDEN=true` to overwrite the golden response files
22+
23+
```
24+
RECREATE_BROKEN_GOLDEN=true python3 ./runTests.py
25+
```
26+
27+
While running, the script will report the differences in the output, but overwrite the old files and continue running. The idea is to inspect changes in the output, or using `git diff` after the run.
28+
29+
## Adding more tests to this test suite
30+
31+
To add a test, you will need to create a new folder in one of `execute/`, `simplify/`, etc. folders, corresponding to the API methods.
632
Note that the folders for the API methods may not contain anything else but subfolders with tests.
733

834
The new folder must contain input components according to the different endpoints:
@@ -13,7 +39,8 @@ The new folder must contain input components according to the different endpoint
1339
* For `implies`:
1440
- `antecedent.json` - a JSON Kore pattern file containing the antecedent term
1541
- `consequent.json` - a JSON Kore pattern file containing the consequent term
16-
42+
* For `simplify`:
43+
- `state.json` - a JSON Kore pattern file containing the state to simplify
1744

1845
For all endpoints:
1946
* `definition.kore` - the definition file with a module `TEST` (this module name is hard coded for all tests)
@@ -53,7 +80,8 @@ kore-parser definition.kore --module TEST --pattern state.kore --print-pattern-j
5380
Finally, run the tests with `CREATE_MISSING_GOLDEN=true` to generate a golden response
5481

5582
```
56-
CREATE_MISSING_GOLDEN=true ./runTests.py
83+
CREATE_MISSING_GOLDEN=true python3 ./runTests.py
5784
```
5885

5986
Clean up the folder and commit the new test
87+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"jsonrpc":"2.0","id":1,"result":{"satisfiable":true,"implication":{"format":"KORE","version":1,"term":{"tag":"Implies","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Exists","sort":{"tag":"SortApp","name":"SortK","args":[]},"var":"Z","varSort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}},"condition":{"substitution":{"format":"KORE","version":1,"term":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortVar","name":"JSONSortVariable"},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}},"predicate":{"format":"KORE","version":1,"term":{"tag":"Top","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}
1+
{"jsonrpc":"2.0","id":1,"result":{"satisfiable":true,"implication":{"format":"KORE","version":1,"term":{"tag":"Implies","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Exists","sort":{"tag":"SortApp","name":"SortK","args":[]},"var":"Z","varSort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}},"condition":{"substitution":{"format":"KORE","version":1,"term":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}},"predicate":{"format":"KORE","version":1,"term":{"tag":"Top","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"jsonrpc":"2.0","id":1,"result":{"satisfiable":false,"implication":{"format":"KORE","version":1,"term":{"tag":"Implies","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Exists","sort":{"tag":"SortApp","name":"SortK","args":[]},"var":"Z","varSort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"And","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Not","sort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}}},"condition":{"substitution":{"format":"KORE","version":1,"term":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortVar","name":"JSONSortVariable"},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}},"predicate":{"format":"KORE","version":1,"term":{"tag":"Top","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}
1+
{"jsonrpc":"2.0","id":1,"result":{"satisfiable":false,"implication":{"format":"KORE","version":1,"term":{"tag":"Implies","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Exists","sort":{"tag":"SortApp","name":"SortK","args":[]},"var":"Z","varSort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"And","sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"Not","sort":{"tag":"SortApp","name":"SortK","args":[]},"arg":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}}},"condition":{"substitution":{"format":"KORE","version":1,"term":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortK","args":[]},"sort":{"tag":"SortApp","name":"SortK","args":[]},"first":{"tag":"EVar","name":"X","sort":{"tag":"SortApp","name":"SortK","args":[]}},"second":{"tag":"EVar","name":"Z","sort":{"tag":"SortApp","name":"SortK","args":[]}}}},"predicate":{"format":"KORE","version":1,"term":{"tag":"Top","sort":{"tag":"SortApp","name":"SortK","args":[]}}}}}}

0 commit comments

Comments
 (0)