Commit 9efcecbe authored by Christian Müller's avatar Christian Müller
Browse files

add invariants

parent 81b7e2b3
...@@ -16,26 +16,26 @@ import de.tum.workflows.foltl.FormulaFunctions ...@@ -16,26 +16,26 @@ import de.tum.workflows.foltl.FormulaFunctions
import de.tum.workflows.toz3.InvariantChecker import de.tum.workflows.toz3.InvariantChecker
object Main extends App with LazyLogging { object Main extends App with LazyLogging {
val MAXAGENTS = 8 val MAXAGENTS = 8
val FOLDER = "results" val FOLDER = "results"
val checkinvariants = true val checkinvariants = true
def clear() { def clear() {
def recclear(folder:File) { def recclear(folder: File) {
for (fol <- folder.listFiles() if fol.isDirectory()) { for (fol <- folder.listFiles() if fol.isDirectory()) {
recclear(fol) recclear(fol)
} }
folder.listFiles().foreach(_.delete()) folder.listFiles().foreach(_.delete())
} }
val fol = new File(FOLDER) val fol = new File(FOLDER)
fol.mkdirs() fol.mkdirs()
recclear(fol) recclear(fol)
} }
def write(name: String, prop:String) { def write(name: String, prop: String) {
val file = new File(name) val file = new File(name)
file.getParentFile.mkdirs() file.getParentFile.mkdirs()
val writer = new PrintWriter(file) val writer = new PrintWriter(file)
...@@ -43,48 +43,64 @@ object Main extends App with LazyLogging { ...@@ -43,48 +43,64 @@ object Main extends App with LazyLogging {
writer.close() writer.close()
} }
def writeExample(name: String, spec:Spec, prop: Formula) { def timeNoninter(spec:Spec) = {
val inv = InvariantChecker.invariantNoninterStubborn(spec)
val (t, (safe, msg)) = time {
InvariantChecker.checkInvariant(spec.w, inv, true)
}
s"Noninterference Invariant (took $t ms):\n$msg\n"
}
def timeAllEqual(spec:Spec) = {
val inv = InvariantChecker.invariantAllEqual(spec)
val (t, (safe, msg)) = time {
InvariantChecker.checkInvariant(spec.w, inv, true)
}
s"All Equal Invariant (took $t ms):\n$msg\n"
}
def writeExample(name: String, spec: Spec, prop: Formula) {
var metrics = List[String]() var metrics = List[String]()
write(s"${name}.foltl", prop.pretty()) write(s"${name}.foltl", prop.pretty())
metrics :+= s"${name}.foltl: ${prop.opsize()}" metrics :+= s"${name}.foltl: ${prop.opsize()}"
if (!FormulaFunctions.checkSanity(prop)) { if (!FormulaFunctions.checkSanity(prop)) {
logger.error("Property didn't pass sanity check") logger.error("Property didn't pass sanity check")
return return
} }
// Do FOLTL to LTL // Do FOLTL to LTL
if (spec.w.isomitting) { if (spec.w.isomitting) {
logger.info("Omitting spec - no embedding in LTL possible") logger.info("Omitting spec - no embedding in LTL possible")
} else { } else {
logger.info("Nonomitting spec - embedding FOLTL formula in LTL") logger.info("Nonomitting spec - embedding FOLTL formula in LTL")
val (agents, res) = LTL.eliminateExistentials(prop) val (agents, res) = LTL.eliminateExistentials(prop)
val universe = agents.map(_.withType()).mkString(", ") val universe = agents.map(_.withType()).mkString(", ")
logger.info(s"Using universe $universe") logger.info(s"Using universe $universe")
if (agents.groupBy(_.typ).exists(_._2.size > MAXAGENTS)) { if (agents.groupBy(_.typ).exists(_._2.size > MAXAGENTS)) {
logger.error(s"Universe has more than $MAXAGENTS agents for a single type. Aborting.") logger.error(s"Universe has more than $MAXAGENTS agents for a single type. Aborting.")
return return
} }
val quantfree = LTL.eliminateUniversals(res, agents) val quantfree = LTL.eliminateUniversals(res, agents)
val ltlprop = LTL.eliminatePredicates(quantfree) val ltlprop = LTL.eliminatePredicates(quantfree)
metrics :+= s"${name}.ltl: ${ltlprop.opsize()}" metrics :+= s"${name}.ltl: ${ltlprop.opsize()}"
metrics :+= s"Universe: $universe" metrics :+= s"Universe: $universe"
write(s"${name}.ltl", ltlprop.toString()) write(s"${name}.ltl", ltlprop.toString())
write(s"${name}.ppltl", ltlprop.pretty()) write(s"${name}.ppltl", ltlprop.pretty())
} }
write(s"${name}.metrics", metrics.mkString("", "\n", "\n")) write(s"${name}.metrics", metrics.mkString("", "\n", "\n"))
logger.info(s"Written all files for $name") logger.info(s"Written all files for $name")
} }
def generate(name: String, spec:Spec) { def generate(name: String, spec: Spec) {
logger.info(s"Encoding Spec:\n$spec") logger.info(s"Encoding Spec:\n$spec")
val t1 = "pi1" val t1 = "pi1"
val t2 = "pi2" val t2 = "pi2"
...@@ -97,40 +113,41 @@ object Main extends App with LazyLogging { ...@@ -97,40 +113,41 @@ object Main extends App with LazyLogging {
val cprop = Properties.noninterCausal(spec) val cprop = Properties.noninterCausal(spec)
writeExample(s"$FOLDER/${name}_causal", spec, cprop) writeExample(s"$FOLDER/${name}_causal", spec, cprop)
} }
if (checkinvariants) { if (checkinvariants) {
val inv = InvariantChecker.invariantNoninterStubborn(spec) def invariants = List(
val (t,(safe, msg)) = time { timeNoninter _,
InvariantChecker.checkInvariant(spec.w, inv, true) timeAllEqual _
} )
val noninter = s"Noninterference Invariant (took $t ms):\n$msg"
def msgs = invariants.map(_(spec))
write(s"$FOLDER/${name}.inv", noninter)
write(s"$FOLDER/${name}.inv", msgs.mkString("\n"))
} }
} }
def generateExample(name: String) { def generateExample(name: String) {
logger.info(s"Generating $name") logger.info(s"Generating $name")
val spec = ExampleWorkflows.parseExample(name) val spec = ExampleWorkflows.parseExample(name)
if (!spec.isDefined) { if (!spec.isDefined) {
logger.error(s"Not a valid spec: $name") logger.error(s"Not a valid spec: $name")
} }
spec.map(generate(name, _)) spec.map(generate(name, _))
} }
def generateAllExamples() { def generateAllExamples() {
clear() clear()
// Fill results alphabetically // Fill results alphabetically
for (k <- ExampleWorkflows.examples.keys.toList.sorted) { for (k <- ExampleWorkflows.examples.keys.toList.sorted) {
generateExample(k) generateExample(k)
} }
} }
// clear() // clear()
// generateExample("omitting/conference") // generateExample("omitting/conference")
// generateExample("tests/declasstest") // generateExample("tests/declasstest")
generateAllExamples() generateAllExamples()
} }
\ No newline at end of file
...@@ -115,4 +115,10 @@ object InvariantChecker extends LazyLogging { ...@@ -115,4 +115,10 @@ object InvariantChecker extends LazyLogging {
Forall(agent, premise conclusion).simplify() Forall(agent, premise conclusion).simplify()
} }
def invariantAllEqual(spec: Spec) = {
And.make(for (r <- spec.w.sig.preds.toList) yield {
Forall(r.params, genEq(r, r.params))
})
}
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment