Skip to content

Commit 25b6537

Browse files
regbromac
authored andcommitted
Yet another hack to go around CVC4 regb#32
1 parent 01b981d commit 25b6537

File tree

7 files changed

+74
-7
lines changed

7 files changed

+74
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(set-option :print-success true)
2+
(set-logic QF_UF)
3+
(declare-sort U 0)
4+
(declare-fun x0 () U)
5+
(declare-fun y0 () U)
6+
(define-fun x1 () U x0)
7+
(define-fun y1 () U y0)
8+
(assert (not (= x1 y1)))
9+
(check-sat)
10+
(exit)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(set-option :print-success true)
2+
(set-logic QF_UF)
3+
(declare-sort U 0)
4+
(declare-fun x0 () U)
5+
(declare-fun y0 () U)
6+
(define-fun-rec x1 ((z U)) U z)
7+
(define-fun-rec y1 ((z U)) U z)
8+
(exit)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
success
2+
success
3+
success
4+
success
5+
success
6+
success
7+
success
8+
success
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(set-option :print-success true)
2+
(set-logic QF_UF)
3+
(declare-sort U 0)
4+
(declare-fun x0 () U)
5+
(declare-fun y0 () U)
6+
(define-funs-rec ((x1 ((z U)) U)) (z))
7+
(exit)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
success
2+
success
3+
success
4+
success
5+
success
6+
success
7+
success

src/it/scala/smtlib/it/SmtLibRunnerTests.scala

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import interpreters._
1919
* Compare the result of running command by command with an interpreter against
2020
* running the corresponding executable directly on the .smt2 files.
2121
*
22-
* TODO: proper way to display warning when not all tests are run because of not found exectuables
22+
* TODO: proper way to display warning when not all tests are run because of not found executables.
2323
*/
2424
class SmtLibRunnerTests extends FunSuite with TestHelpers {
2525

@@ -47,23 +47,41 @@ class SmtLibRunnerTests extends FunSuite with TestHelpers {
4747
if(isCVC4Available) {
4848
filesInResourceDir("regression/smtlib/solving/cvc4", _.endsWith(".smt2")).foreach(file => {
4949
test("With CVC4: SMTLIB benchmark: " + file.getPath) {
50-
compareWithInterpreter(executeCVC4)(getCVC4Interpreter, file)
50+
compareWithWant(getCVC4Interpreter, file, new File(file.getPath + ".want"))
5151
}
5252
})
5353
}
5454

5555

5656
def compareWithInterpreter(executable: (File) => (String => Unit) => Unit)
5757
(interpreter: Interpreter, file: File) = {
58-
5958
val lexer = new Lexer(new FileReader(file))
6059
val parser = new Parser(lexer)
6160

6261
executable(file) { (expected: String) =>
63-
val res: String = interpreter.eval(parser.parseCommand).toString
62+
val cmd = parser.parseCommand
63+
assert(cmd !== null)
64+
val res: String = interpreter.eval(cmd).toString
6465
assert(expected.trim === res.trim)
6566
}
6667
assert(parser.parseCommand === null)
6768
}
6869

70+
def compareWithWant(interpreter: Interpreter, file: File, want: File) = {
71+
72+
val lexer = new Lexer(new FileReader(file))
73+
val parser = new Parser(lexer)
74+
75+
for(expected <- scala.io.Source.fromFile(want).getLines) {
76+
val cmd = parser.parseCommand
77+
assert(cmd !== null)
78+
val res: String = interpreter.eval(cmd).toString
79+
assert(expected.trim === res.trim)
80+
}
81+
assert(parser.parseCommand === null)
82+
intercept[smtlib.parser.Parser.UnexpectedEOFException] {
83+
// There shouldn't be anything left on the interpreter parser (the solver process).
84+
interpreter.parser.parseSExpr
85+
}
86+
}
6987
}

src/main/scala/smtlib/interpreters/CVC4Interpreter.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@ class CVC4Interpreter(executable: String, args: Array[String], tailPrinter: Bool
1414
parser.parseGenResponse
1515

1616
override def parseResponseOf(cmd: SExpr): SExpr = cmd match {
17-
case DefineFunsRec(funs, bodies) =>
18-
// CVC4 translates definefunsrec in three commands per function,
19-
// and thus emits 3x (success)
17+
case DefineFunsRec(funs, _) =>
18+
// CVC4 translates define-funs-rec in three commands per function,
19+
// and thus emits 3x success.
2020
val res = for (i <- 1 to funs.size*3) yield {
2121
parser.parseGenResponse
2222
}
2323

2424
res.find(_ != Success).getOrElse(Success)
2525

26+
case DefineFunRec(_) =>
27+
// CVC4 translates define-fun-rec in three commands,
28+
// and thus emits 3x success.
29+
val res = for (i <- 1 to 3) yield {
30+
parser.parseGenResponse
31+
}
32+
33+
res.find(_ != Success).getOrElse(Success)
34+
2635
case _ =>
2736
super.parseResponseOf(cmd)
2837
}

0 commit comments

Comments
 (0)