Skip to content

Commit d21e198

Browse files
committed
wip
1 parent 678f683 commit d21e198

File tree

29 files changed

+390
-25
lines changed

29 files changed

+390
-25
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

key.core/src/test/java/de/uka/ilkd/key/macros/scripts/TestProofScriptCommand.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: GPL-2.0-only */
44
package de.uka.ilkd.key.macros.scripts;
55

6+
import java.io.File;
67
import java.io.FileNotFoundException;
78
import java.io.IOException;
89
import java.net.URI;
@@ -13,6 +14,7 @@
1314
import java.util.Arrays;
1415
import java.util.List;
1516

17+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
1618
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
1719
import de.uka.ilkd.key.control.KeYEnvironment;
1820
import de.uka.ilkd.key.java.Position;
@@ -31,6 +33,7 @@
3133
import org.junit.jupiter.params.provider.MethodSource;
3234

3335
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.assertj.core.api.Assertions.in;
3437
import static org.junit.jupiter.api.Assertions.assertTrue;
3538

3639

@@ -39,7 +42,7 @@
3942
*/
4043
public class TestProofScriptCommand {
4144
public record TestInstance(String name, String key, String script, String exception,
42-
String[] goals, Integer selectedGoal) {
45+
String[] goals, Integer selectedGoal) {
4346
}
4447

4548

@@ -49,9 +52,24 @@ public static List<Arguments> data() throws IOException, URISyntaxException {
4952
throw new FileNotFoundException("Cannot find resource 'cases'.");
5053
}
5154

52-
var objectMapper = new ObjectMapper(new YAMLFactory());
55+
var objectMapper = new ObjectMapper(new YAMLFactory()
56+
.configure(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR,true)
57+
.configure(YAMLGenerator.Feature.INDENT_ARRAYS,true)
58+
.configure(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE,true)
59+
.configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER,false)
60+
.configure(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS,false)
61+
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES,true));
62+
5363
objectMapper.findAndRegisterModules();
5464
TestInstance[] instances = objectMapper.readValue(url, TestInstance[].class);
65+
66+
for (TestInstance instance : instances) {
67+
objectMapper.writeValue(new File(
68+
"C:\\Users\\weigl\\IdeaProjects\\key\\key.core\\src\\test\\resources\\de\\uka\\ilkd\\key\\macros\\scripts",
69+
instance.name + ".yml"
70+
), instance);
71+
}
72+
5573
return Arrays.stream(instances).map(Arguments::of).toList();
5674
}
5775

key.core/src/test/java/de/uka/ilkd/key/smt/newsmt2/MasterHandlerTest.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import java.nio.charset.StandardCharsets;
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
12+
import java.nio.file.Paths;
1213
import java.util.*;
1314

15+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
1416
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
1517
import de.uka.ilkd.key.control.KeYEnvironment;
1618
import de.uka.ilkd.key.logic.Sequent;
@@ -67,43 +69,50 @@ public class MasterHandlerTest {
6769

6870
public static List<Arguments> data()
6971
throws IOException, URISyntaxException, ProblemLoaderException {
70-
try (var input = MasterHandlerTest.class.getResourceAsStream("cases.yml")) {
71-
var om = new ObjectMapper(new YAMLFactory());
72-
TypeReference<HashMap<String, TestData>> typeRef = new TypeReference<>() {
73-
};
74-
Map<String, TestData> preData = om.readValue(input, typeRef);
75-
var result = new ArrayList<Arguments>(preData.size());
76-
for (var entry : preData.entrySet()) {
77-
final var value = entry.getValue();
72+
var om = new ObjectMapper(new YAMLFactory());
73+
var path = Paths.get("src/test/resources/de/uka/ilkd/key/smt/newsmt2/cases/");
74+
try (var walker = Files.walk(path)) {
75+
var files = walker.filter(it -> it.getFileName().endsWith("yml")).toList();
76+
var result = new ArrayList<Arguments>(files.size());
77+
for (Path pFile : files) {
78+
var file = pFile.toFile();
79+
80+
TestData value = om.readValue(file, TestData.class);
7881

7982
if (value.state == TestDataState.IGNORE) {
80-
LOGGER.info("Test {} case has been marked ignore", entry.getKey());
83+
LOGGER.info("Test {} case has been marked ignore", file);
8184
continue;
8285
}
83-
84-
final var testData = value.load(entry.getKey());
86+
final var testData = value.load(file.getName().replace(".yml", ""));
8587
result.add(Arguments.of(testData));
8688
}
8789
return result;
8890
}
8991
}
9092

93+
/**
94+
* Describes the state of a test instance.
95+
*/
9196
public enum TestDataState {
9297
EMPTY, EXTENDED, IGNORE
9398
}
9499

100+
/**
101+
* Expected outcome of a test instance.
102+
*/
95103
public enum Expectation {
96104
VALID, FAIL, IRRELEVANT
97105
}
98106

99107
/**
100108
* This class contains the information about the test fixtures that is loaded via the YAML.
101-
* @param contains a list of strings that are expected in the SMT translation
109+
*
110+
* @param contains a list of strings that are expected in the SMT translation
102111
* @param smtSettings required key/values in the smt settings.
103-
* @param expected expected output of Z3
104-
* @param state state of the test
105-
* @param javaSrc path to necessary java sources
106-
* @param keySrc contents of the key file to be loaded.
112+
* @param expected expected output of Z3
113+
* @param state state of the test
114+
* @param javaSrc path to necessary java sources
115+
* @param keySrc contents of the key file to be loaded.
107116
*/
108117
public record TestData(List<String> contains,
109118
Properties smtSettings,
@@ -119,7 +128,7 @@ private LoadedTestData load(String name) throws IOException, ProblemLoaderExcept
119128
Path srcDir = Files.createTempDirectory("SMT_key_" + name);
120129
Path tmpSrc = srcDir.resolve("src.java");
121130
Files.writeString(tmpSrc, javaSrc);
122-
keySrc += "\n\\javaSource \"%s\";\n".formatted(srcDir);
131+
keySrc += "\n/javaSource \"%s\";\n".formatted(srcDir);
123132
}
124133

125134
Path tmpKey = Files.createTempFile("SMT_key_%s".formatted(name), ".key");
@@ -170,7 +179,7 @@ void testTranslation(LoadedTestData data) throws Exception {
170179
void testZ3(LoadedTestData data) throws Exception {
171180
Assumptions.assumeTrue(Z3_SOLVER != null);
172181
Assumptions.assumeTrue(Z3_SOLVER.isInstalled(false),
173-
"Z3 is not installed, this testcase is ignored.");
182+
"Z3 is not installed, this testcase is ignored.");
174183

175184
var expectation = data.data.expected;
176185
Assumptions.assumeTrue(expectation != null, "No Z3 expectation.");
@@ -187,9 +196,9 @@ void testZ3(LoadedTestData data) throws Exception {
187196

188197
try {
189198
String lookFor = switch (expectation) {
190-
case VALID -> "unsat";
191-
case FAIL -> "(sat|timeout)";
192-
case IRRELEVANT -> null;
199+
case VALID -> "unsat";
200+
case FAIL -> "(sat|timeout)";
201+
case IRRELEVANT -> null;
193202
};
194203

195204
if (lookFor != null) {
@@ -205,7 +214,7 @@ void testZ3(LoadedTestData data) throws Exception {
205214

206215
if (!STRICT_TEST) {
207216
assumeFalse(data.data.state == TestDataState.EXTENDED,
208-
"This is an extended test (will be run only in strict mode)");
217+
"This is an extended test (will be run only in strict mode)");
209218
}
210219

211220
if (lookFor != null) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
contains:
3+
- (assert (not (=> (or (and u_b u_b) u_b) (= (not u_b) (and true false)))))
4+
smtSettings: null
5+
expected: VALID
6+
state: null
7+
javaSrc: null
8+
keySrc: |-
9+
\predicates { b; }
10+
11+
\problem { b&b | b -> (!b <-> true & false) }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
contains:
3+
- |-
4+
(declare-fun u_p () Bool)
5+
(declare-fun u_b () U)
6+
- (assert (not (=> (= u_p (= u_b (b2u true))) (= (not u_p) (= u_b (b2u false))))))
7+
smtSettings: null
8+
expected: VALID
9+
state: null
10+
javaSrc: null
11+
keySrc: |-
12+
\predicates { p; }
13+
\functions { boolean b; }
14+
15+
\problem { (p <-> b=TRUE) -> (!p <-> b=FALSE) }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
contains:
3+
- |-
4+
(assert (= (ite (< 2 1) (b2u true) (b2u false))
5+
(ite (> 2 1) (b2u true) (b2u false))))
6+
smtSettings: null
7+
expected: VALID
8+
state: null
9+
javaSrc: null
10+
keySrc: |-
11+
\predicates { p; }
12+
\functions { boolean b; }
13+
14+
\problem { \if(2<1)\then(TRUE)\else(FALSE) != \if(2>1)\then(TRUE)\else(FALSE) }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
contains:
3+
- |-
4+
(assert (forall ((x U) (t T)) (! (subtype (typeof (cast x t)) t) :pattern ((cast x t)))))
5+
(assert (forall ((x U) (t T)) (! (=> (subtype (typeof x) t) (= (cast x t) x)) :pattern ((cast x t)))))
6+
- (assert (not (= (cast (i2u 42) sort_int) (i2u 42))))
7+
smtSettings: null
8+
expected: VALID
9+
state: null
10+
javaSrc: null
11+
keySrc: "\\problem { (int)42 = 42 }"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
contains:
3+
- (assert (not (= (cast (k_select u_heap u_o u_FF) sort_int) (cast (k_seqGet u_s
4+
(i2u 42)) sort_int))))
5+
smtSettings: null
6+
expected: IRRELEVANT
7+
state: null
8+
javaSrc: null
9+
keySrc: |-
10+
\functions { Field FF; Seq s; java.lang.Object o; }
11+
12+
\problem { int::select(heap, o, FF) = int::seqGet(s, 42) }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
contains:
3+
- (assert (not (= (cast (i2u 42) sort_any) (i2u 42))))
4+
smtSettings: null
5+
expected: VALID
6+
state: EXTENDED
7+
javaSrc: null
8+
keySrc: "\\problem { (any)42 = 42 }"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
contains:
3+
- |-
4+
; --- Sequent
5+
(assert (not (exists ((var_x Int))
6+
(= (i2u (* 3 var_x)) (i2u 42)))))
7+
smtSettings: null
8+
expected: VALID
9+
state: null
10+
javaSrc: null
11+
keySrc: |-
12+
\programVariables { int p; }
13+
14+
\problem {
15+
\exists int x; (3*x = 42)
16+
}

0 commit comments

Comments
 (0)