Skip to content

Commit 4451895

Browse files
committed
- benchmark now compares the results.
1 parent bf1cf27 commit 4451895

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

src/org/sosy_lab/java_smt/utils/ParseGenerateAndReparse.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import org.sosy_lab.java_smt.api.SolverException;
2626
import org.sosy_lab.java_smt.basicimpl.Generator;
2727

28-
/** This file is meant for the Evaluation of the Parser/Generator. */
28+
/**
29+
* This file is meant for the Evaluation of the Parser/Generator.
30+
*/
2931
class ParseGenerateAndReparse {
30-
private ParseGenerateAndReparse() {}
32+
private ParseGenerateAndReparse() {
33+
}
3134

3235
public static void main(String[] args)
3336
throws InvalidConfigurationException, InterruptedException, SolverException {
@@ -56,6 +59,18 @@ public static void main(String[] args)
5659
System.exit(1);
5760
return;
5861
}
62+
boolean expectedIsUnsat = false;
63+
boolean foundInFile = false;
64+
65+
if (smt2FileContent.contains("(set-info :status sat)")) {
66+
expectedIsUnsat = false;
67+
foundInFile = true;
68+
} else if (smt2FileContent.contains("(set-info :status unsat)")) {
69+
expectedIsUnsat = true;
70+
foundInFile = true;
71+
}
72+
73+
5974
String mode = args[2].toUpperCase(Locale.ROOT);
6075
Configuration config =
6176
Configuration.builder()
@@ -68,8 +83,8 @@ public static void main(String[] args)
6883
if (mode.equals("GENERATE_AND_REPARSE")) {
6984
// PARSE REGENERATE THEN NATIVE PARSE
7085
try (SolverContext solverLessContext =
71-
SolverContextFactory.createSolverContext(
72-
config, logger, shutdown.getNotifier(), Solvers.SOLVERLESS)) {
86+
SolverContextFactory.createSolverContext(
87+
config, logger, shutdown.getNotifier(), Solvers.SOLVERLESS)) {
7388

7489
// JAVASMT'S PARSER
7590
BooleanFormula formula =
@@ -78,42 +93,58 @@ public static void main(String[] args)
7893
Generator.assembleConstraint(formula);
7994
String regenerated = Generator.getSMTLIB2String();
8095
// NATIVE PARSE
81-
checkResult(checkNativeParseAndIsUnsat(solver, regenerated));
96+
checkResult(checkNativeParseAndIsUnsat(solver, regenerated), expectedIsUnsat, foundInFile);
8297
} catch (Exception pE) {
8398
printError(pE);
8499
}
85100
}
86101
if (mode.equals("NATIVE")) {
87102
try {
88103
// NATIVE PARSE
89-
checkResult(checkNativeParseAndIsUnsat(solver, smt2FileContent));
104+
checkResult(checkNativeParseAndIsUnsat(solver, smt2FileContent), expectedIsUnsat, foundInFile);
90105
} catch (Exception pE) {
91106
printError(pE);
92107
}
93108
}
94109
if (mode.equals("PARSE")) {
95110
try (SolverContext realSolverContext =
96-
SolverContextFactory.createSolverContext(
97-
config, logger, shutdown.getNotifier(), solver);
98-
ProverEnvironment realProverEnvironment =
99-
realSolverContext.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
111+
SolverContextFactory.createSolverContext(
112+
config, logger, shutdown.getNotifier(), solver);
113+
ProverEnvironment realProverEnvironment =
114+
realSolverContext.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
100115
try {
101116
// JAVASMT'S PARSER
102117
BooleanFormula javaSMTParsed =
103118
realSolverContext.getFormulaManager().universalParseFromString(smt2FileContent);
104119
realProverEnvironment.addConstraint(javaSMTParsed);
105120
// JAVASMT'S PARSE
106-
checkResult(realProverEnvironment.isUnsat());
121+
checkResult(realProverEnvironment.isUnsat(), expectedIsUnsat, foundInFile);
107122
} catch (Exception pE) {
108123
printError(pE);
109124
}
110125
}
111126
}
112127
}
113128

114-
public static void checkResult(boolean isUnsat) {
115-
System.out.println("SUCCESS: isUnsat = " + isUnsat);
116-
System.exit(0);
129+
public static void checkResult(
130+
boolean actualIsUnsat,
131+
boolean expectedIsUnsat,
132+
boolean foundInFile) {
133+
if (foundInFile) {
134+
if (actualIsUnsat != expectedIsUnsat) {
135+
System.out.println(
136+
"FALSE: actualIsUnsat :" + actualIsUnsat + " does not match expectedIsUnsat :"
137+
+ expectedIsUnsat);
138+
System.exit(1);
139+
} else{
140+
System.out.println("SUCCESS: PROPERTY HOLDS: expectedIsUnsat = " + expectedIsUnsat + " = "
141+
+ "actualIsUnsat = " + actualIsUnsat);
142+
System.exit(0);
143+
}
144+
}else {
145+
System.out.println("SUCCESS: isUnsat = " + actualIsUnsat);
146+
System.exit(0);
147+
}
117148
}
118149

119150
public static boolean checkNativeParseAndIsUnsat(Solvers solver, String smt2)

0 commit comments

Comments
 (0)