Skip to content

Commit 1a55a33

Browse files
authored
Fix interp value analysis test termination assertion (#367)
* cleanup interp value analysis test termination assertion * make file match class name
1 parent 6cfc767 commit 1a55a33

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/test/scala/InterpretTestConstProp.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ConstPropInterpreterValidate extends AnyFunSuite with TestValueDomainWithI
6060
}.toMap
6161

6262
val result = runTestInterpreter(ictx, analysisres)
63-
assertCorrectResult(result)
63+
assert(result.getFailures.isEmpty)
6464

6565
}
6666

src/test/scala/util/TestValueAnalysisWithInterpreter.scala src/test/scala/util/TestValueDomainWithInterpreter.scala

+25-15
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,32 @@ trait TestValueDomainWithInterpreter[T] {
2323
case AllVarsInAbstract
2424
case VarsLiveInBlock
2525

26+
case class InterpreterTestResult(stopCondition: ExecutionContinuation, checks: List[CheckResult]) {
27+
def getFailures = {
28+
// require nonzero number of checks to ensure test is not vacuous
29+
var noChecks = if (checks.isEmpty) then Seq("no checks hit") else Seq()
30+
val termination =
31+
if (!normalTermination(stopCondition)) then Seq(s"Stopped with error condition: ${stopCondition}") else Seq()
32+
termination ++ noChecks ++ checksFailed
33+
}
34+
35+
def checksFailed = {
36+
// collected breakpoints evaluate to true
37+
checks.flatMap(b => {
38+
val loc = b.breakpoint.location match {
39+
case BreakPointLoc.CMD(c) => c.parent.label
40+
case _ => ??? /* not used here */
41+
}
42+
if (b.evaluatedTestExpr != TrueLiteral) then Seq(s"${b.name} @ $loc") else Seq()
43+
})
44+
}
45+
}
46+
2647
def runTestInterpreter(
2748
ictx: IRContext,
2849
testResultBefore: Map[Block, Map[Variable, T]],
2950
testVars: Heuristic = Heuristic.AllVarsInAbstract
30-
): List[CheckResult] = {
51+
): InterpreterTestResult = {
3152

3253
val breaks: List[BreakPoint] = ictx.program.collect {
3354
// convert analysis result to a list of breakpoints, each which evaluates an expression describing
@@ -56,25 +77,14 @@ trait TestValueDomainWithInterpreter[T] {
5677
// run the interpreter evaluating the analysis result at each command with a breakpoint
5778
val interpretResult = interpretWithBreakPoints(ictx, breaks.toList, NormalInterpreter, InterpreterState())
5879

59-
assert(interpretResult._1.nextCmd == Stopped())
6080
val breakres: List[(BreakPoint, _, List[(String, Expr, Expr)])] = interpretResult._2
61-
breakres.flatMap { case (bp, _, l) =>
81+
val checkResults = breakres.flatMap { case (bp, _, l) =>
6282
l.map { case (name, test, evaled) =>
6383
CheckResult(name, bp, test, evaled)
6484
}
6585
}.toList
66-
}
67-
68-
def assertCorrectResult(breakres: List[CheckResult]) = {
69-
assert(breakres.nonEmpty)
7086

71-
// assert all the collected breakpoint watches have evaluated to true
72-
for (b <- breakres) {
73-
val loc = b.breakpoint.location match {
74-
case BreakPointLoc.CMD(c) => c.parent.label
75-
case _ => ??? /* not used here */
76-
}
77-
assert(b.evaluatedTestExpr == TrueLiteral, s"${b.name} @ $loc")
78-
}
87+
InterpreterTestResult(interpretResult._1.nextCmd, checkResults)
7988
}
89+
8090
}

0 commit comments

Comments
 (0)