Ejemplo n.º 1
0
 def test_04(self):
     start = datetime.datetime.now()
     programs = {
         "Arm": progTwistAndTurnArm(),
         "Cart": progTwistAndTurnCart(),
         "Carrier": progTwistAndTurnCarrier()
     }
     prser = parser.Parser()
     parsed = dict(
         (name, prser.parse(txt)) for name, txt in programs.items())
     world = progTwistAndTurnWorld()
     arm = first_true(world.allProcesses(), None,
                      lambda x: x.name() == "Arm")
     cart = first_true(world.allProcesses(), None,
                       lambda x: x.name() == "Cart")
     carrier = first_true(world.allProcesses(), None,
                          lambda x: x.name() == "Carrier")
     annot = progTwistAndTurnAnnot(arm, cart, carrier)
     mc = GlobalModelChecking(world, parsed, annot, debug=False)
     mc.check()
     end = datetime.datetime.now()
     delta = end - start
     print("RES twist and turn")
     print("RES elapsed: ", delta)
     print("RES #VC:", len(mc.vcs))
     pass
Ejemplo n.º 2
0
def run(progs, shouldSucceed=True, debug=False):
    try:
        prser = parser.Parser()
        parsed = {(name, prser.parse(txt)) for name, txt in progs.items()}
        mc = spin.McMessages(parsed, debug)
        result, mps = mc.check()
        return result == shouldSucceed
    except Exception as e:
        if shouldSucceed:
            raise e
 def scenario(self, n, par):
     print("## n =", n, ", par =", par)
     w = self.world(n)
     if par:
         ch = self.choreo_par(n)
     else:
         ch = self.choreo_no_par(n)
     print(ch)
     progs = {}
     for i in range(0, n):
         a = "Arm" + str(i)
         c = self.code(n, i)
         progs[a] = c
         print(a)
         print(c)
     start = time.time()
     visitor = Projection()
     visitor.execute(ch, w)
     chor = visitor.choreography
     vectorize(chor, w)
     end = time.time()
     print("Syntactic checks:", end - start)
     start = end
     checker = CompatibilityCheck(chor, w)
     checker.localChoiceChecks()
     checker.generateTotalGuardsChecks()
     checker.computePreds()
     checker.generateCompatibilityChecks()
     end = time.time()
     print("VC generation:", end - start)
     start = end
     print("#VC:", len(checker.vcs))
     for i in range(0, len(checker.vcs)):
         vc = checker.vcs[i]
         #print("Checking VC", i, vc.title)
         if not vc.discharge():
             raise Exception(str(vc))
     end = time.time()
     print("VC solving:", end - start)
     start = end
     processes = w.allProcesses()
     for p in processes:
         visitor.choreography = deepcopy(chor)
         proj = visitor.project(p.name(), p)
         prser = parser.Parser()
         prog = prser.parse(progs[p.name()])
         ref = Refinement(prog, proj)
         if not ref.check():
             raise Exception("Refinement: " + p.name())
     end = time.time()
     print("refinement:", end - start)
     start = end
Ejemplo n.º 4
0
 def check(self, ch, w, contracts, progs):
     start = time.time()
     start0 = start
     env = Env(w, contracts)
     visitor = Projection()
     visitor.execute(ch, env)
     chor = visitor.choreography
     log.debug("parsed\n%s", chor)
     vectorize(chor, w)
     end = time.time()
     log.info("Syntactic checks: %s", end - start)
     start = end
     checker = CompatibilityCheck(chor, w)
     checker.localChoiceChecks()
     checker.generateTotalGuardsChecks()
     checker.computePreds()
     checker.generateCompatibilityChecks()
     end = time.time()
     log.info("VC generation: %s", end - start)
     start = end
     log.info("#VC: %s", len(checker.vcs))
     failed = []
     for i in range(0, len(checker.vcs)):
         vc = checker.vcs[i]
         log.info("Checking VC %s %s", i, vc.title)
         if not vc.discharge():
             log.warning("Failed VC %s", i)
             failed.append((i, vc))
             log.debug("%s", vc)
             if vc.hasModel():
                 log.debug("%s", vc.modelStr())
             else:
                 log.debug("Timeout")
     for (i, vc) in failed:
         log.info("Failed: %s %s", i, vc.title)
     end = time.time()
     log.info("VC solving: %s", end - start)
     start = end
     processes = w.allProcesses()
     for p in processes:
         visitor.choreography = deepcopy(chor)
         proj = visitor.project(p.name(), p)
         prser = parser.Parser()
         prog = prser.parse(progs[p.name()])
         ref = Refinement(prog, proj)
         if not ref.check():
             raise Exception("Refinement: " + p.name())
     end = time.time()
     log.info("refinement: %s", end - start)
     log.info("total time: %s", end - start0)
     self.assertTrue(failed == [])
Ejemplo n.º 5
0
 def test_01(self):
     w = world()
     env = Env(w, [Xless, Xmore])
     ch = choreo1()
     progs = {"sensor": code_sensor(), "producer": code_producer()}
     start = time.time()
     visitor = Projection()
     visitor.execute(ch, env)
     chor = visitor.choreography
     vectorize(chor, w)
     end = time.time()
     print("Syntactic checks:", end - start)
     start = end
     checker = CompatibilityCheck(chor, w)
     checker.localChoiceChecks()
     checker.generateTotalGuardsChecks()
     checker.computePreds()
     checker.generateCompatibilityChecks()
     end = time.time()
     print("VC generation:", end - start)
     start = end
     print("#VC:", len(checker.vcs))
     failed = []
     for i in range(0, len(checker.vcs)):
         vc = checker.vcs[i]
         print("Checking VC", i, vc.title)
         if not vc.discharge():
             failed.append(vc)
             print("Failed")
             print(vc)
             if vc.hasModel():
                 print(vc.modelStr())
     end = time.time()
     print("VC solving:", end - start)
     self.assertTrue(failed == [])
     start = end
     processes = w.allProcesses()
     for p in processes:
         visitor.choreography = deepcopy(chor)
         proj = visitor.project(p.name(), p)
         prser = parser.Parser()
         prog = prser.parse(progs[p.name()])
         ref = Refinement(prog, proj)
         if not ref.check():
             raise Exception("Refinement: " + p.name())
     end = time.time()
     print("refinement:", end - start)
     start = end
Ejemplo n.º 6
0
 def test_01(self):
     start = datetime.datetime.now()
     programs = {"A": progFetchA(), "C": progFetchC()}
     prser = parser.Parser()
     parsed = dict(
         (name, prser.parse(txt)) for name, txt in programs.items())
     world = cartAndArmWorld()
     arm = first_true(world.allProcesses(), None, lambda x: x.name() == "A")
     cart = first_true(world.allProcesses(), None,
                       lambda x: x.name() == "C")
     annot = progFecthAnnot(arm, cart)
     mc = GlobalModelChecking(world, parsed, annot, debug=False)
     mc.check()
     end = datetime.datetime.now()
     delta = end - start
     print("RES fetch")
     print("RES elapsed: ", delta)
     print("RES #VC:", len(mc.vcs))
Ejemplo n.º 7
0
def run(ch, components, progs, shouldSucceed=True, debug=False):
    try:
        visitor = Projection()
        visitor.execute(ch)
        chor = visitor.choreography
        vectorize(chor, components)
        processes = components.allProcesses()
        for p in processes:
            visitor.choreography = deepcopy(chor)
            proj = visitor.project(p.name(), p, debug)
            prser = parser.Parser()
            prog = prser.parse(progs[p.name()])
            ref = Refinement(prog, proj, debug)
            if not ref.check():
                return not shouldSucceed
        return shouldSucceed
    except Exception as e:
        if shouldSucceed:
            raise e
Ejemplo n.º 8
0
 def scenario(self, n, m, par, debug=False, printCSV=False):
     if not printCSV:
         print("## n =", n, ", m =", m, ", par =", par)
     w = self.world(n, m)
     if par:
         ch = self.choreo_par(n, m)
     else:
         ch = self.choreo_no_par(n, m)
     if debug:
         print(ch)
     progs = {"Cart" + str(i): self.code(n, m) for i in range(0, n)}
     start = time.time()
     start0 = start
     visitor = Projection()
     visitor.execute(ch, w)
     chor = visitor.choreography
     vectorize(chor, w)
     end = time.time()
     time_syntax = end - start
     if not printCSV:
         print("  Syntactic checks:", time_syntax)
     start = end
     checker = CompatibilityCheck(chor, w)
     checker.localChoiceChecks()
     checker.generateTotalGuardsChecks()
     checker.computePreds()
     checker.generateCompatibilityChecks()
     end = time.time()
     time_vc_gen = end - start
     if not printCSV:
         print("  VC generation:", time_vc_gen)
     start = end
     if not printCSV:
         print("  #VC:", len(checker.vcs))
     for i in range(0, len(checker.vcs)):
         vc = checker.vcs[i]
         #print("Checking VC", i, vc.title)
         if not vc.discharge():
             print(n, ",", m, ",", par, ",", time_syntax, ",",
                   len(checker.vcs), ",", time_vc_gen, ", TO, NA, TO")
             return
     end = time.time()
     time_vc_solve = end - start
     if not printCSV:
         print("  VC solving:", time_vc_solve)
     start = end
     processes = w.allProcesses()
     for p in processes:
         visitor.choreography = deepcopy(chor)
         proj = visitor.project(p.name(), p)
         prser = parser.Parser()
         prog = prser.parse(progs[p.name()])
         ref = Refinement(prog, proj)
         if not ref.check():
             raise Exception("Refinement: " + p.name())
     end = time.time()
     time_refine = end - start
     if not printCSV:
         print("  refinement:", time_refine)
     time_total = end - start0
     if not printCSV:
         print("totat time:", time_total)
     else:
         print(n, ",", m, ",", par, ",", time_syntax, ",", len(checker.vcs),
               ",", time_vc_gen, ",", time_vc_solve, ",", time_refine, ",",
               time_total)