Skip to content

Commit f2beed1

Browse files
committed
wip picocli
1 parent d16b010 commit f2beed1

File tree

54 files changed

+744
-1732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+744
-1732
lines changed

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/Constants.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55

66
import org.key_project.util.java.StringUtil;
77

8-
public interface Constants {
9-
8+
public class Constants {
109
/**
1110
* Constant for the line break which is used by the operating system.
1211
* <p>
1312
* <b>Do not use {@code \n}!</b>
1413
*/
15-
String NEW_LINE = StringUtil.NEW_LINE;
16-
String NULLABLE = "/*@ nullable */";
17-
String ALL_OBJECTS = "allObjects";
18-
String ALL_INTS = "allInts";
19-
String ALL_BOOLS = "allBools";
20-
String ALL_HEAPS = "allHeaps";
21-
String ALL_FIELDS = "allFields";
22-
String ALL_SEQ = "allSeq";
23-
String ALL_LOCSETS = "allLocSets";
24-
25-
String OBJENESIS_NAME = "objenesis-2.2.jar";
26-
27-
String OLDMap = "old";
28-
29-
String TAB = " ";
14+
public static final String NEW_LINE = StringUtil.NEW_LINE;
15+
public static final String NULLABLE = "/*@ nullable */";
16+
public static final String ALL_OBJECTS = "allObjects";
17+
public static final String ALL_INTS = "allInts";
18+
public static final String ALL_BOOLS = "allBools";
19+
public static final String ALL_HEAPS = "allHeaps";
20+
public static final String ALL_FIELDS = "allFields";
21+
public static final String ALL_SEQ = "allSeq";
22+
public static final String ALL_LOCSETS = "allLocSets";
23+
public static final String OBJENESIS_NAME = "objenesis-2.2.jar";
24+
public static final String OLD_MAP = "old";
25+
public static final String TAB = " ";
26+
public static final String DUMMY_POSTFIX = "DummyImpl";
3027

31-
String DUMMY_POSTFIX = "DummyImpl";
28+
private Constants() {
29+
}
3230
}

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/Format.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/OutputEnvironment.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* This file is part of KeY - https://key-project.org
2+
* KeY is licensed under the GNU General Public License Version 2
3+
* SPDX-License-Identifier: GPL-2.0-only */
14
package de.uka.ilkd.key.testgen;
25

36
import java.io.IOException;
@@ -7,30 +10,38 @@
710
import java.util.Objects;
811

912
/**
13+
* This class manages the different paths in the output folder.
1014
* @author Alexander Weigl
1115
* @version 1 (02.02.24)
1216
*/
1317
public record OutputEnvironment(Path targetFolder) {
18+
/** Returns the source code folder */
1419
public Path getSourceDir() {
1520
return targetFolder.resolve("src");
1621
}
1722

23+
/** Returns the test code folder */
1824
public Path getTestSourceDir() {
1925
return targetFolder.resolve("test");
2026
}
2127

28+
/** Returns the path to the ANT build.xml file */
2229
public Path getAntFile() {
2330
return targetFolder.resolve("build.xml");
2431
}
2532

33+
/** Returns the path to the README.md file */
2634
public Path getReadmeFile() {
2735
return targetFolder.resolve("README.md");
2836
}
2937

38+
/**
39+
* Initialize/create the necessary directories.
40+
* @throws IOException if the output folder is not write or the folders can not be created.
41+
*/
3042
public void init() throws IOException {
3143
Files.createDirectories(getSourceDir());
3244
Files.createDirectories(getTestSourceDir());
33-
3445
installAntFile();
3546
}
3647

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/ProofInfo.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
import org.key_project.logic.op.Operator;
2727
import org.key_project.logic.sort.Sort;
2828

29-
import org.jspecify.annotations.Nullable;
30-
31-
import org.key_project.logic.sort.Sort;
32-
33-
import org.jspecify.annotations.Nullable;
3429
import org.jspecify.annotations.Nullable;
3530
import org.slf4j.Logger;
3631
import org.slf4j.LoggerFactory;
@@ -47,8 +42,8 @@ public ProofInfo(Proof proof) {
4742
public IProgramMethod getMUT() {
4843
SpecificationRepository spec = services.getSpecificationRepository();
4944
IObserverFunction f = spec.getTargetOfProof(proof);
50-
if (f instanceof IProgramMethod) {
51-
return (IProgramMethod) f;
45+
if (f instanceof IProgramMethod pm) {
46+
return pm;
5247
} else {
5348
return null;
5449
}
@@ -65,8 +60,8 @@ public String getMUTCall() {
6560
StringBuilder params = new StringBuilder();
6661
for (ParameterDeclaration p : m.getParameters()) {
6762
for (VariableSpecification v : p.getVariables()) {
68-
IProgramVariable var = v.getProgramVariable();
69-
params.append(",").append(var.name());
63+
IProgramVariable pvar = v.getProgramVariable();
64+
params.append(",").append(pvar.name());
7065
}
7166
}
7267
if (!params.isEmpty()) {
@@ -123,9 +118,8 @@ public JTerm getPreConTerm() {
123118
Contract c = getContract();
124119
if (c instanceof FunctionalOperationContract t) {
125120
OriginalVariables orig = t.getOrigVars();
126-
JTerm post = t.getPre(services.getTypeConverter().getHeapLDT().getHeap(), orig.self,
121+
return t.getPre(services.getTypeConverter().getHeapLDT().getHeap(), orig.self,
127122
orig.params, orig.atPres, services);
128-
return post;
129123
}
130124
// no pre <==> false
131125
return services.getTermBuilder().ff();

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/ReflectionClassCreator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.HashSet;
88
import javax.lang.model.element.Modifier;
99

10-
import de.uka.ilkd.key.logic.sort.Sort;
10+
import org.key_project.logic.sort.Sort;
1111

1212
import com.squareup.javapoet.*;
1313

@@ -77,8 +77,8 @@ public void addSort(String s) {
7777
*/
7878
private HashSet<String> sortsToString() {
7979
final HashSet<String> result = new HashSet<>();
80-
for (final Sort var : usedObjectSorts) {
81-
String sort = var.toString();
80+
for (final Sort s : usedObjectSorts) {
81+
String sort = s.toString();
8282
// We only want Object-Types
8383
if (!" jbyte jint jlong jfloat jdouble jboolean jchar ".contains(" " + sort + " ")) {
8484
if (" jbyte[] jint[] jlong[] jfloat[] jdouble[] jboolean[] jchar[] "
@@ -191,8 +191,6 @@ private void staticInitializer(boolean ghostMapActive, TypeSpec.Builder clazz) {
191191
* All calls to create objects for the given sorts
192192
*/
193193
private void instances(final HashSet<String> sorts, TypeSpec.Builder clazz) {
194-
// r.append(NEW_LINE).append(" // ---The methods for object creation---").append(NEW_LINE)
195-
// .append(NEW_LINE);
196194
for (final String sort : sorts) {
197195
clazz.addMethod(newRef(sort));
198196
}

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/TGMain.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,61 @@
1212
import java.util.concurrent.Future;
1313
import java.util.regex.Pattern;
1414

15-
import de.uka.ilkd.key.api.ProofManagementApi;
1615
import de.uka.ilkd.key.control.KeYEnvironment;
1716
import de.uka.ilkd.key.proof.Proof;
18-
import de.uka.ilkd.key.proof.io.ProblemLoaderException;
1917
import de.uka.ilkd.key.smt.solvertypes.SolverTypes;
2018
import de.uka.ilkd.key.speclang.Contract;
2119
import de.uka.ilkd.key.testgen.smt.testgen.TGPhase;
2220
import de.uka.ilkd.key.testgen.smt.testgen.TestGenerationLifecycleListener;
21+
22+
import org.jspecify.annotations.Nullable;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525
import picocli.CommandLine;
2626

27-
import java.io.File;
28-
import java.util.ArrayList;
29-
import java.util.LinkedList;
30-
import java.util.List;
31-
import java.util.concurrent.Callable;
32-
3327
@CommandLine.Command(name = "tcgen", mixinStandardHelpOptions = true,
34-
description = "Generator of Testcases based on Proof Attempts")
28+
description = "Generator of Testcases based on Proof Attempts")
3529
public class TGMain implements Callable<Integer> {
36-
private final static Logger LOGGER = LoggerFactory.getLogger("main");
30+
private static final Logger LOGGER = LoggerFactory.getLogger("main");
3731

38-
public static void main(String[] args) throws ProblemLoaderException, InterruptedException {
32+
public static void main(String[] args) {
3933
int exitCode = new CommandLine(new TGMain()).execute(args);
4034
System.exit(exitCode);
4135
}
4236

4337
@CommandLine.Parameters(description = "KeY or Java file.", arity = "1..*")
4438
private List<File> files = new LinkedList<>();
4539

46-
@CommandLine.Parameters(description = "Number of parallel jobs", defaultValue = "4")
40+
@CommandLine.Option(names = "-T", description = "Number of parallel jobs", defaultValue = "4")
4741
private int numberOfThreads = 4;
4842

49-
@CommandLine.Option(names = {"-s", "--symbex"},
43+
@CommandLine.Option(names = { "-s", "--symbex" },
5044
description = "apply symbolic execution", negatable = true)
5145
private boolean symbex;
5246

5347
@CommandLine.Option(names = { "-c", "--contract" }, arity = "*",
5448
description = "name of the contract to be loaded in the Java environment. Can be a regular expression")
5549
private List<String> contractNames = new ArrayList<>();
5650

57-
@CommandLine.Option(names = {"--all-contracts"},
51+
@CommandLine.Option(names = { "--all-contracts" },
5852
description = "test case generation for all contracts")
5953
private boolean allContracts = false;
6054

61-
@CommandLine.Option(names = {"-o", "--output"}, description = "Output folder")
55+
@CommandLine.Option(names = { "-o", "--output" }, description = "Output folder")
6256
private File outputFolder = new File("out");
6357

64-
@CommandLine.Option(names = {"-r", "--rfl"}, description = "Use Reflection class", negatable = true)
58+
@CommandLine.Option(names = { "-r", "--rfl" }, description = "Use Reflection class",
59+
negatable = true)
6560
private boolean useReflection = false;
6661

6762
@CommandLine.Option(names = { "-f", "--format" },
6863
description = "use Reflection class for instantiation")
69-
private Format format = Format.JUNIT_4;
64+
private JUnitFormat format = JUnitFormat.JUNIT_4;
7065

7166
@CommandLine.Option(names = { "--max-unwinds" }, description = "max unwinds of loops")
7267
private int maxUnwinds = 10;
7368

74-
@CommandLine.Option(names = {"--dups"}, description = "remove duplicates", negatable = true)
69+
@CommandLine.Option(names = { "--dups" }, description = "remove duplicates", negatable = true)
7570
private boolean removeDuplicates;
7671

7772
@CommandLine.Option(names = { "--only-tests" },
@@ -118,14 +113,15 @@ public Integer call() throws Exception {
118113
Proof proof = env.getLoadedProof();
119114
if (proof == null) { // non-key file
120115
var print = contractNames.isEmpty();
121-
final var api = new ProofManagementApi(env);
122-
var contracts = api.getProofContracts();
116+
var contracts = env.getProofContracts();
123117
for (Contract contract : contracts) {
124118
final var name = contract.getName();
125119
if (print) {
126120
LOGGER.info("Contract found: {}", name);
127121
} else if (allContracts || contractNameMatcher.test(name)) {
128-
proofs.add(api.startProof(contract).getProof());
122+
var p =
123+
env.createProof(contract.createProofObl(env.getInitConfig(), contract));
124+
proofs.add(p);
129125
}
130126
}
131127
} else { // key file
@@ -134,14 +130,13 @@ public Integer call() throws Exception {
134130

135131
LOGGER.info("Number of proof found: {}", proofs.size());
136132

137-
var exec = Executors.newFixedThreadPool(numberOfThreads);
138-
try {
133+
try (var exec = Executors.newFixedThreadPool(numberOfThreads);) {
139134
LOGGER.info("Start processing with {} threads", numberOfThreads);
140135
var tasks = proofs.stream().map(
141136
p -> TestgenFacade.generateTestcasesTask(env, p, settings, log)).toList();
142137
var futures = tasks.stream().map(exec::submit).toList();
143138
for (Future<?> future : futures) {
144-
future.wait();
139+
future.get();
145140
}
146141
} finally {
147142
proofs.forEach(Proof::dispose);
@@ -154,11 +149,13 @@ public Integer call() throws Exception {
154149

155150

156151
class SysoutTestGenerationLifecycleListener implements TestGenerationLifecycleListener {
157-
private final static Logger LOGGER = LoggerFactory.getLogger("main");
152+
private static final Logger LOGGER = LoggerFactory.getLogger("main");
158153

159154
@Override
160-
public void writeln(@Nullable String message) {
161-
if(message!=null){ LOGGER.info(message);}
155+
public void writeln(Object sender, @Nullable String message) {
156+
if (message != null) {
157+
LOGGER.info(message);
158+
}
162159
}
163160

164161
@Override

key.core.testgen/src/main/java/de/uka/ilkd/key/testgen/TGReporter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import de.uka.ilkd.key.testgen.smt.testgen.TestGenerationLifecycleListener;
88

99
/**
10+
* Reporter for test case generation.
11+
*
1012
* @author Alexander Weigl
1113
* @version 1 (24.05.24)
1214
*/

0 commit comments

Comments
 (0)