def test_seq_a_b_n_actions(self): depgraph = digraph() na = random.randint(5, 10) actions = [] for i in range(0, na): actions.append(("Rule"+str(i), "Cmd"+str(i))) add_action(depgraph, "a#ta", actions) nb = random.randint(5, 10) actions = [] for i in range(0, nb): actions.append(("Rule"+str(i), "Cmd"+str(i))) add_action(depgraph, "b#tb", actions) depgraph.add_edge(("a#ta", "b#tb")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, na+nb) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) seq = instructions.pop() actions = self.assertSequence(seq, na+nb) for i in range(0, nb): self.assertAction(actions[i], id="b#tb/Rule"+str(i), cs="b#tb", cmd="Cmd"+str(i)) for i in range(0, na): self.assertAction(actions[nb+i], id="a#ta/Rule"+str(i), cs="a#ta", cmd="Cmd"+str(i))
def test_par_a_b_n_actions(self): depgraph = digraph() na = random.randint(5, 10) actions = [] for i in range(0, na): actions.append(("Rule"+str(i), "Cmd"+str(i))) add_action(depgraph, "a#ta", actions) nb = random.randint(5, 10) actions = [] for i in range(0, nb): actions.append(("Rule"+str(i), "Cmd"+str(i))) add_action(depgraph, "b#tb", actions) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, na+nb) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() seqs = self.assertParallel(par, 2) seqa = self.assertSequence(seqs[0], na) for i in range(0, na): self.assertAction(seqa[i], id="a#ta/Rule"+str(i), cs="a#ta", cmd="Cmd"+str(i)) seqb = self.assertSequence(seqs[1], nb) for i in range(0, nb): self.assertAction(seqb[i], id="b#tb/Rule"+str(i), cs="b#tb", cmd="Cmd"+str(i))
def test_single_one_action(self): depgraph = digraph() add_action(depgraph, "a#ta", [("Rule1", "cmd1")]) print("Graph: %s" % depgraph.nodes()) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 1) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) a = instructions[0] self.assertAction(a, id="a#ta/Rule1", cs="a#ta", cmd="cmd1")
def test_nop2many(self): depgraph = digraph() add_action(depgraph, "a#ta", [("Rule1", "cmd1")]) add_action(depgraph, "b#tb", [("Rule2", "cmd2")]) depgraph.add_node("nop#t") depgraph.add_edge(('nop#t', 'a#ta')) depgraph.add_edge(('nop#t', 'b#tb')) print("Graph: %s" % depgraph.nodes()) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 2) self.assertTrue("a#ta/Rule1" in ise_model.actions) self.assertTrue("b#tb/Rule2" in ise_model.actions)
def test_par_a_b_single_action(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, nb=2) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() actions = self.assertParallel(par, nb=2) self.assertAction(actions[0], id="a#ta/Rule", cs="a#ta", cmd="Cmd") self.assertAction(actions[1], id="b#tb/Rule", cs="b#tb", cmd="Cmd")
def test_nop_a(self): depgraph = digraph() depgraph.add_node("nop#t") add_action(depgraph, "a#ta", [("Rule1", "cmd1")]) depgraph.add_edge(('nop#t', 'a#ta')) print("Graph: %s" % depgraph.nodes()) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 1) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) a = instructions[0] self.assertAction(a, id="a#ta/Rule1", cs="a#ta", cmd="cmd1")
def test_a_nop_b(self): depgraph = digraph() add_action(depgraph, "a#ta", [("Rule1", "cmd1")]) add_action(depgraph, "b#tb", [("Rule2", "cmd2")]) depgraph.add_node("nop#t") depgraph.add_edge(('a#ta', 'nop#t')) depgraph.add_edge(('nop#t', 'b#tb')) print("Graph: %s" % depgraph.nodes()) (ise_model, xml, error) = self.order(depgraph) print("Tranformed Graph: %s" % ise_model.dag.nodes()) self.assertActionsNb(ise_model, 2) self.assertTrue("a#ta/Rule1" in ise_model.actions) self.assertTrue("b#tb/Rule2" in ise_model.actions) self.assertTrue(self._pathExist(ise_model.dag, 'a#ta/Rule1', 'b#tb/Rule2'))
def test_a_b_c_d_square(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "d#td")) depgraph.add_edge(("c#tc", "b#tb")) depgraph.add_edge(("c#tc", "d#td")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 4) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) seq = instructions.pop() instructions = self.assertSequence(seq, nb=2) par = instructions[0] actions = self.assertParallel(par, nb=2) self.assertContainsAction(actions, "b#tb/Rule") self.assertContainsAction(actions, "d#td/Rule") par = instructions[1] actions = self.assertParallel(par, nb=2) self.assertContainsAction(actions, "a#ta/Rule") self.assertContainsAction(actions, "c#tc/Rule")
def test_a_b_c_d_square(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "d#td")) depgraph.add_edge(("c#tc", "b#tb")) depgraph.add_edge(("c#tc", "d#td")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 4) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() actions = self.assertParallel(par, nb=4) a = self.assertContainsAction(actions, "a#ta/Rule") b = self.assertContainsAction(actions, "b#tb/Rule") c = self.assertContainsAction(actions, "c#tc/Rule") d = self.assertContainsAction(actions, "d#td/Rule") self.assertAction(a, id="a#ta/Rule", deps=set(['b#tb/Rule', 'd#td/Rule'])) self.assertAction(b, id="b#tb/Rule", deps=set()) self.assertAction(c, id="c#tc/Rule", deps=set(['b#tb/Rule', 'd#td/Rule'])) self.assertAction(d, id="d#td/Rule", deps=set())
def test_seq_a_b_single_action(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") depgraph.add_edge(("a#ta", "b#tb")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, nb=2) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) seq = instructions.pop() actions = self.assertSequence(seq, nb=2) self.assertAction(actions[0], id="b#tb/Rule", cs="b#tb", cmd="Cmd") self.assertAction(actions[1], id="a#ta/Rule", cs="a#ta", cmd="Cmd")
def test_single_n_actions(self): depgraph = digraph() n = random.randint(5, 10) actions = [] for i in range(0, n): actions.append(("Rule"+str(i), "Cmd"+str(i))) add_action(depgraph, "a#ta", actions) print("Graph: %s" % depgraph) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, n) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) container = instructions.pop() actions = self.assertContainer(container, nb=n) for i in range(0, n): a = actions[i] self.assertAction(a, id="a#ta/Rule"+str(i), cs="a#ta", cmd="Cmd"+str(i))
def test_many2nop2many(self): depgraph = digraph() add_action(depgraph, "a#ta", [("Rule1", "cmd1")]) add_action(depgraph, "b#tb", [("Rule2", "cmd2")]) depgraph.add_node("nop#t") add_action(depgraph, "c#tc", [("Rule3", "cmd3")]) add_action(depgraph, "d#td", [("Rule4", "cmd4")]) depgraph.add_edge(('a#ta', 'nop#t')) depgraph.add_edge(('b#tb', 'nop#t')) depgraph.add_edge(('nop#t', 'c#tc')) depgraph.add_edge(('nop#t', 'd#td')) print("Graph: %s" % depgraph.nodes()) (ise_model, xml, error) = self.order(depgraph) print("Tranformed Graph: %s" % ise_model.dag.nodes()) self.assertActionsNb(ise_model, 4) self.assertTrue("a#ta/Rule1" in ise_model.actions) self.assertTrue("b#tb/Rule2" in ise_model.actions) self.assertTrue("c#tc/Rule3" in ise_model.actions) self.assertTrue("d#td/Rule4" in ise_model.actions) self.assertTrue(self._pathExist(ise_model.dag, 'a#ta/Rule1', 'c#tc/Rule3')) self.assertTrue(self._pathExist(ise_model.dag, 'a#ta/Rule1', 'd#td/Rule4')) self.assertTrue(self._pathExist(ise_model.dag, 'b#tb/Rule2', 'c#tc/Rule3')) self.assertTrue(self._pathExist(ise_model.dag, 'b#tb/Rule2', 'd#td/Rule4'))
def test_a_b_c_d_useless(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("b#tb", "c#tc")) depgraph.add_edge(("b#tb", "d#td")) depgraph.add_edge(("a#ta", "c#tc")) depgraph.add_edge(("a#ta", "d#td")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 4) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) instructions = instructions.pop() seq = self.assertSequence(instructions, nb=3) par = self.assertParallel(seq[0], nb=2) self.assertAction(par[0], id="c#tc/Rule", deps=set()) self.assertAction(par[1], id="d#td/Rule", deps=set()) self.assertAction(seq[1], id="b#tb/Rule", deps=set()) self.assertAction(seq[2], id="a#ta/Rule", deps=set())
def test_a_dep_b_c(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "c#tc")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 3) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() actions = self.assertParallel(par, nb=3) self.assertContainsAction(actions, "a#ta/Rule") self.assertContainsAction(actions, "b#tb/Rule") self.assertContainsAction(actions, "c#tc/Rule")
def test_a_b_dep_c(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") depgraph.add_edge(("a#ta", "c#tc")) depgraph.add_edge(("b#tb", "c#tc")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 3) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() instructions = self.assertParallel(par, nb=2) seq = self.assertSequence(instructions[0], nb=2) self.assertAction(seq[0], id="c#tc/Rule") self.assertAction(seq[1], id="a#ta/Rule") self.assertAction(instructions[1], id="b#tb/Rule")
def test_complex_case_a_b_c_f_e_d_diamond(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") add_action(depgraph, "e#te") add_action(depgraph, "f#tf") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "c#tc")) depgraph.add_edge(("d#td", "e#te")) depgraph.add_edge(("d#td", "f#tf")) depgraph.add_edge(("f#tf", "b#tb")) depgraph.add_edge(("c#tc", "e#te")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 6) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() actions = self.assertParallel(par, nb=6) a = self.assertContainsAction(actions, "a#ta/Rule") b = self.assertContainsAction(actions, "b#tb/Rule") c = self.assertContainsAction(actions, "c#tc/Rule") d = self.assertContainsAction(actions, "d#td/Rule") e = self.assertContainsAction(actions, "e#te/Rule") f = self.assertContainsAction(actions, "f#tf/Rule") self.assertAction(a, "a#ta/Rule", deps=set(['b#tb/Rule', 'c#tc/Rule'])) self.assertAction(b, "b#tb/Rule", deps=set()) self.assertAction(c, "c#tc/Rule", deps=set(['e#te/Rule'])) self.assertAction(d, "d#td/Rule", deps=set(['e#te/Rule', 'f#tf/Rule'])) self.assertAction(e, "e#te/Rule", deps=set()) self.assertAction(f, "f#tf/Rule", deps=set(['b#tb/Rule']))
def test_complex_case_a_b_c_f_e_d_diamond(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") add_action(depgraph, "e#te") add_action(depgraph, "f#tf") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "c#tc")) depgraph.add_edge(("d#td", "e#te")) depgraph.add_edge(("d#td", "f#tf")) depgraph.add_edge(("f#tf", "b#tb")) depgraph.add_edge(("c#tc", "e#te")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 6) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) par = instructions.pop() instructions = self.assertParallel(par, nb=2) seqs_ebfd = self.assertSequence(instructions[0], nb=2) seqs_ca = self.assertSequence(instructions[1], nb=2) par_ebf = self.assertParallel(seqs_ebfd[0], nb=2) seq_bf = self.assertSequence(par_ebf[1], nb=2) self.assertAction(par_ebf[0], "e#te/Rule", deps=set()) self.assertAction(seq_bf[0], "b#tb/Rule", deps=set()) self.assertAction(seq_bf[1], "f#tf/Rule", deps=set()) self.assertAction(seqs_ebfd[1], "d#td/Rule", deps=set()) self.assertAction(seqs_ca[0], "c#tc/Rule", deps=set(['e#te/Rule'])) self.assertAction(seqs_ca[1], "a#ta/Rule", deps=set(['b#tb/Rule']))
def test_complex_case_a_b_c_f_e_d_diamond(self): depgraph = digraph() add_action(depgraph, "a#ta") add_action(depgraph, "b#tb") add_action(depgraph, "c#tc") add_action(depgraph, "d#td") add_action(depgraph, "e#te") add_action(depgraph, "f#tf") depgraph.add_edge(("a#ta", "b#tb")) depgraph.add_edge(("a#ta", "c#tc")) depgraph.add_edge(("d#td", "e#te")) depgraph.add_edge(("d#td", "f#tf")) depgraph.add_edge(("f#tf", "b#tb")) depgraph.add_edge(("c#tc", "e#te")) (ise_model, xml, error) = self.order(depgraph) self.assertActionsNb(ise_model, 6) instructions = ise_model.instructions self.assertNotEquals(instructions, None) self.assertEquals(len(instructions), 1) seq = instructions.pop() instructions = self.assertSequence(seq, nb=3) par = instructions[0] actions = self.assertParallel(par, nb=2) self.assertContainsAction(actions, "b#tb/Rule") self.assertContainsAction(actions, "e#te/Rule") par = instructions[1] actions = self.assertParallel(par, nb=2) self.assertContainsAction(actions, "f#tf/Rule") self.assertContainsAction(actions, "c#tc/Rule") par = instructions[2] actions = self.assertParallel(par, nb=2) self.assertContainsAction(actions, "a#ta/Rule") self.assertContainsAction(actions, "d#td/Rule")