Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaKe committed Oct 19, 2023
1 parent 6d32db7 commit 28d7b4a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 46 deletions.
19 changes: 12 additions & 7 deletions src/main/scala/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

package viper.silicon

import scala.annotation.implicitNotFound
import scala.collection.immutable.ArraySeq
import viper.silicon.state.terms.{Sort, Term, True, Var}
import viper.silicon.verifier.Verifier
import viper.silver
import viper.silver.ast.utility.Triggers.TriggerGenerationWithAddAndSubtract
import viper.silver.ast.utility.rewriter.Traverse
import viper.silver.components.StatefulComponent
import viper.silver.verifier.{VerificationError, errors}
import viper.silver.verifier.errors.Internal
import viper.silver.verifier.reasons.{FeatureUnsupported, UnexpectedNode}
import viper.silver.ast.utility.rewriter.Traverse
import viper.silicon.state.terms.{Sort, Term, Var}
import viper.silicon.verifier.Verifier
import viper.silver.ast.utility.Triggers.TriggerGenerationWithAddAndSubtract
import viper.silver.verifier.{VerificationError, errors}

import scala.annotation.implicitNotFound
import scala.collection.immutable.ArraySeq

package object utils {
def freshSnap: (Sort, Verifier) => Var = (sort, v) => v.decider.fresh(sort)
Expand Down Expand Up @@ -131,6 +132,10 @@ package object utils {
(e0: silver.ast.Exp, e1: silver.ast.Exp) => silver.ast.Or(e0, e1)(e0.pos, e0.info),
silver.ast.FalseLit()(emptyPos))

def removeKnownToBeTrueExp(exps: List[silver.ast.Exp], terms: List[Term]): List[silver.ast.Exp] = {
exps.zip(terms).filter(t => t._2 != True).map(e => e._1)
}

/** Note: be aware of Silver issue #95!*/
def rewriteRangeContains(program: silver.ast.Program): silver.ast.Program =
program.transform({
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/rules/MoreCompleteExhaleSupporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import viper.silicon.state._
import viper.silicon.state.terms._
import viper.silicon.state.terms.perms.{IsNonPositive, IsPositive}
import viper.silicon.supporters.functions.NoopFunctionRecorder
import viper.silicon.utils.ast.{BigAnd, removeKnownToBeTrueExp}
import viper.silicon.verifier.Verifier
import viper.silicon.{MList, MMap}
import viper.silver.ast
Expand Down Expand Up @@ -335,13 +336,12 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {

totalPermSum = PermPlus(totalPermSum, Ite(eq, ch.perm, NoPerm))
totalPermTaken = PermPlus(totalPermTaken, permTaken)
val constraintTerms = List(IsValidPermVar(permTaken), PermAtMost(permTaken, ch.perm), Implies(Not(eq), permTaken === NoPerm))
val constraintExp = BigAnd(removeKnownToBeTrueExp(List(ast.TrueLit()(), ast.TrueLit()(), ast.TrueLit()()), constraintTerms)) // TODO ake

val constraint = And(IsValidPermVar(permTaken),
PermAtMost(permTaken, ch.perm),
Implies(Not(eq), permTaken === NoPerm)
)
val constraint = And(constraintTerms)

v.decider.assume(constraint, new DebugExp("Test"))
v.decider.assume(constraint, new DebugExp(constraintExp, s.substituteVarsInExp(constraintExp)))
newFr = newFr.recordArp(permTaken, constraint)

ch.withPerm(PermMinus(ch.perm, permTaken))
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/viperDebugger/predicateFold.vpr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

predicate greater0(i : Int)
predicate greater0(i : Int, p : Perm)
{
i >= 0
}

method my_fold(n : Int)
requires n >= 0
ensures greater0(n)
ensures greater0(n, 1/2)
{
fold greater0(n)
fold greater0(n, 1/2)
}
13 changes: 13 additions & 0 deletions src/test/resources/viperDebugger/references.vpr
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@ method test_references(n : Ref)
i := i + n.val

assert i == n.val
}


method test_references2(n : Ref)
requires acc(n.val, 1/2) && n.val >= 0
{
var i : Ref
i := new(*)

i.val := 2
i.val := i.val + n.val

assert i.val == n.val
}
13 changes: 0 additions & 13 deletions src/test/resources/viperDebugger/references2.vpr

This file was deleted.

18 changes: 18 additions & 0 deletions src/test/resources/viperDebugger/sequences.vpr
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,22 @@ method test_sequence_append(s1 : Seq[Int], s2: Seq[Int])
var s : Seq[Int]
s := s1 ++ s2
assert |s| > 1
}

method seq_sum(list : Seq[Int])
{
var i : Int
var sum : Int

i := 0
sum := 0

while(i < |list|)
invariant 0 <= i && i <= |list|
{
sum := sum + list[i]
i := i + 1
}

assert i == |list|
}
18 changes: 0 additions & 18 deletions src/test/resources/viperDebugger/set.vpr

This file was deleted.

0 comments on commit 28d7b4a

Please sign in to comment.