CCSSubmissionTest.scala 7.31 KB
Newer Older
Christian Müller's avatar
Christian Müller committed
1 2
package de.tum.niwo.tests.papertests

Christian Müller's avatar
Christian Müller committed
3
import com.typesafe.scalalogging.LazyLogging
Christian Müller's avatar
Christian Müller committed
4
import de.tum.niwo.blocks.NISpec
Christian Müller's avatar
Christian Müller committed
5 6
import de.tum.niwo.foltl.{FOLTL, FOTransformers, FormulaFunctions}
import de.tum.niwo.foltl.FOLTL._
Christian Müller's avatar
Christian Müller committed
7 8 9
import de.tum.niwo.invariants.InvariantGenerator.genEq
import de.tum.niwo.{Examples, Utils}
import de.tum.niwo.invariants.{InvProperties, InvariantGenerator}
Christian Müller's avatar
Christian Müller committed
10
import de.tum.niwo.parser.{TransitionSystemParser, WorkflowParser}
Christian Müller's avatar
Christian Müller committed
11
import de.tum.niwo.tests.TestUtils.{checkSafe, checkSafeCausalElim}
Christian Müller's avatar
Christian Müller committed
12 13
import org.scalatest.FlatSpec

Christian Müller's avatar
Christian Müller committed
14
class CCSSubmissionTest extends FlatSpec with LazyLogging {
Christian Müller's avatar
Christian Müller committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

  def checkTS(name:String, properties:InvProperties):Boolean = {
    val spec = Examples.parseExampleTS(name).get
    Utils.check(name, "", spec, properties)
  }

  val properties = InvProperties(stubborn = true, eliminateA = true, eliminateB = true)

  "Single trace Easychair" should "be proven safe" in {
    val name = "tstests/easychair_singletrace"

    assert(checkTS(name, properties))
  }

  "Deterministic Leader election" should "be proven safe" in {
    val name = "tstests/leaderelection_inductive"

    assert(checkTS(name, properties))
  }


  it should "be proven safe with Bs" in {
    val name = "tstests/leaderelection_inductive_withB"

    assert(checkTS(name, properties))
  }

  it should "be proven safe with easier B" in {
    val name = "tstests/leaderelection_inductive_withB2"

    assert(checkTS(name, properties))
  }

48 49 50 51 52 53
  it should "be proven safe with looping Bs" in {
    val name = "tstests/leaderelection_inductive_withLoopB"

    assert(checkTS(name, properties))
  }

Christian Müller's avatar
Christian Müller committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  "Easychair" should "prove stubborn conference" in {
    val name = "omitting/conference_stubborn"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    checkSafe(name, "", inv, InvProperties(
      stubborn = true,
      approxElim = false
    ))
  }

  it should "prove stubborn conference with B" in {
    val name = "omitting/conference_stubborn_withB"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    checkSafe(name, "", inv, InvProperties(
      stubborn = true,
      approxElim = false
    ))
  }

  it should "prove linear causal stuff with B safe" in {
    val name = "tests/conference_linear_small_withB"
    val xt = Var("xt","X")
    val yt = Var("yt","X")
    val pt = Var("pt","P")
    //    val rt = Var("rt","R")
    val inv = Forall(List(xt, pt, yt), genEq("Comm", List(xt, yt, pt)))
    assert(checkSafe(name, "", _ => inv,
      InvProperties(stubborn = false, approxElim = false)))
  }

//  it should "fail to prove causal conference with approxElim" in {
//    val name = "omitting/conference"
//    val inv = InvariantGenerator.invariantNoninterSingleBS _
//    assert(checkSafe(name, "", inv, InvProperties(
//      stubborn = false,
//      approxElim = true
//    )))
//  }

  it should "prove causal unrolled conference with approxElim" in {
    val name = "omitting/conference_unrolled_withB"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      approxElim = true
    )))
  }

  // terminates, but gives strategy False
  it should "prove causal conference with approxElim" in {
    val name = "omitting/conference_withB"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      approxElim = true
    )))
  }

Christian Müller's avatar
Christian Müller committed
111
  // single choice
Christian Müller's avatar
Christian Müller committed
112
  ignore should "prove unrolled causal conference with single choice" in {
Christian Müller's avatar
Christian Müller committed
113 114 115 116 117 118 119 120 121 122
    val name = "omitting/conference_unrolled_withB"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      eliminateA = false,
      eliminateB = true,
      approxElim = false
    )))
  }

Christian Müller's avatar
Christian Müller committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  it should "prove stubborn omitting/conference_linear_fixed" in {
    val name = "omitting/conference_linear_fixed"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = true,
      approxElim = false
    )))
  }

  it should "prove causal omitting/conference_linear_fixed" in {
    val name = "omitting/conference_linear_fixed"
    val inv = InvariantGenerator.invariantNoninterSingleBS _
    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      approxElim = false
    )))
  }
Christian Müller's avatar
Christian Müller committed
140

Christian Müller's avatar
Christian Müller committed
141
  it should "prove counterexample for conference" in {
Christian Müller's avatar
Christian Müller committed
142
    val name = "omitting/conference_fixeduniverse"
Christian Müller's avatar
Christian Müller committed
143 144 145 146 147 148 149

    val inv = (spec:NISpec) => {
      val i = InvariantGenerator.invariantNoninterSingleBS(spec)
      val reninv = i.parallelRename(List(Var("xat","A")), List(Var("a1", "A")))
      FormulaFunctions.eliminateEq(reninv)
    }

Christian Müller's avatar
Christian Müller committed
150 151 152 153 154 155 156 157
//    universe = Some(
//      Map(
//        "A" -> List(Var("a1", "A"), Var("a2", "A")),
//        "P" -> List(Var("p1", "P"), Var("p2", "P")),
//        "R" -> List(Var("r1", "R"))
//      )
//    )

Christian Müller's avatar
Christian Müller committed
158 159 160
    assert(!checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      approxElim = false,
Christian Müller's avatar
Christian Müller committed
161
      eliminateA = true
Christian Müller's avatar
Christian Müller committed
162 163
    )))
  }
Christian Müller's avatar
Christian Müller committed
164

Christian Müller's avatar
Christian Müller committed
165 166
  it should "prove causal omitting/conference_withB for a given invariant" in {
    val name = "omitting/conference_invariant_synthesis"
Christian Müller's avatar
Christian Müller committed
167
//    val inv = InvariantGenerator.invariantNoninterSingleBS _
Christian Müller's avatar
Christian Müller committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
//    import InvariantGenerator.genEq
//
//    val x = Var("ix","A")
//    val xt = Var("xt","A")
//    val y = Var("iy", "A")
//    val z = Var("iz","A")
//    val p = Var("ip","P")
//    val q = Var("iq","P")
//    val r = Var("ir","R")
//    val ceq = Forall(List(x, p), genEq("Conf", List(x,p)))
//    val asseq = Forall(List(x, p), genEq("Assign", List(x,p)))
//
//    val xyass = Forall(List(y,p), (Fun("Assign", List(xt,p)) land Fun("Assign", List(y, p))) -->
//      (
//        Forall(List(q,r), genEq("Review", List(y,q,r))) land
//        Neg(Fun("informed", List(y))) land
//        Forall(List(q,r), genEq("Read", List(y,q,r))) land
//        Forall(List(q), Fun("Conf", List(xt, p)) --> Fun("Conf", List(y, q))) land
//        Forall(List(z,q), (Fun ("Assign", List(y, q)) land Fun("Assign", List(z,q))) -->
//          Fun("Assign", List(z,p))
//          )
//      )
//    )
////    val readimplass = Forall(List(y, q, r), Fun("Read", List(y,p,r)) --> Fun("Assign", List(y,p)))
//    val revimplass = Forall(List(y, p, r), Fun("Review", List(y,p,r)) --> Fun("Assign", List(y,p)))
Christian Müller's avatar
Christian Müller committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208


    //    val rt = Var("rt","R")
//    val i0 = "∀x:A,p:P,r:R (Read(x,p,r) ⟹ Assign(x,p))"
//    val i1 = "∀x:A,p:P,r:R (Review(x,p,r) ⟹ Assign(x,p))"
//    val i2 = "∀x:A,y:A,p:P,q:P ¬(Conf(x,p) ∧ Assign(x,q) ∧ Assign(y,p) ∧ Assign(y,q))"
//    val i3 = "∀x:A,p:P,y:A,q:P ¬(Assign(x,p) ∧ Review(y,p,r) ∧ Conf(x,q) ∧ Assign(y,q))"
//    val i3 = "∀x:A,y:A,p:P ¬(informed(y) ∧ Assign(x,p) ∧ Assign(y,p))"
//    val i4 = "∀x:A,p:P,r:R ¬(Read(x,p,r) ∧ ¬Assign(x,p))"

//    val invs = List(
//
//    )
//    val parsed = invs.map(TransitionSystemParser.parseFormula(_))
//    logger.info(parsed.mkString)
//    val ip = And.make(parsed.map(_.get))
Christian Müller's avatar
Christian Müller committed
209 210
//    val invs = List(asseq, ceq, xyass.in("t1"), revimplass.in("t1"), revimplass.in("t2"))

Christian Müller's avatar
Christian Müller committed
211 212

    //    val rt = Var("rt","R")
Christian Müller's avatar
Christian Müller committed
213 214 215
    val inv = (spec:NISpec) => {
      And.make(InvariantGenerator.invariantNoninterSingleBS(spec))
    }
Christian Müller's avatar
Christian Müller committed
216 217 218 219 220 221 222 223
//    val inv = InvariantGenerator.invariantNoninterSingleBS _

    assert(checkSafe(name, "", inv, InvProperties(
      stubborn = false,
      approxElim = false,
      eliminateA = true
    )))
  }
Christian Müller's avatar
Christian Müller committed
224
}