2 # Copyright (C) 2006-2008 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 class TestExec(unittest.TestCase):
31 SALOMERuntime.RuntimeSALOME_setRuntime(1)
32 self.l = loader.YACSLoader()
33 self.e = pilot.ExecutorSwig()
34 self.p = self.l.load("samples/aschema.xml")
37 def test1_StepByStep(self):
38 # --- execution step by step
40 print "================= Start of STEPBYSTEP ==================="
41 self.e.setExecMode(1) # YACS::STEPBYSTEP
43 run1 = threading.Thread(None, self.e.RunPy, "stepbystep", (self.p,0))
45 time.sleep(0.1) # let the thread be initialised
52 bp = self.e.getTasksToLoad()
53 print "nexts possible steps = ", bp
55 tte= bp[-1:] # only one node at each step, the last one in the list
56 r = self.e.setStepsToExecute(tte)
57 self.e.resumeCurrentBreakPoint()
58 tocont = self.e.isNotFinished()
62 print "toContinue = ", tocont
65 self.e.resumeCurrentBreakPoint()
67 self.assertEqual(106, self.p.getChildByName('node48').getEffectiveState())
68 self.assertEqual(999, self.p.getChildByName('node13').getEffectiveState())
69 self.assertEqual(888, self.p.getChildByName('node14').getEffectiveState())
70 self.assertEqual(777, self.p.getChildByName('c1').getEffectiveState())
71 self.assertEqual(777, self.p.getChildByName('c1.c1.n2').getEffectiveState())
72 self.assertEqual(106, self.p.getChildByName('c0.c1.n1').getEffectiveState())
73 self.assertEqual(999, self.p.getChildByName('c0.n2').getEffectiveState())
74 self.assertEqual(888, self.p.getChildByName('node62').getEffectiveState())
75 print "================= End of STEPBYSTEP ====================="
78 def test2_StopToBreakpoint(self):
79 # --- start execution, set a breakpoint before node48, then continue
81 print "================= Start of BREAKPOINT ==================="
83 self.e.setListOfBreakPoints(brp)
84 self.e.setExecMode(2) # YACS::STOPBEFORENODES
85 self.run2 = threading.Thread(None, self.e.RunPy, "breakpoint", (self.p,0))
90 print "================= reach BREAKPOINT ======================"
91 # --- resume from breakpoint
92 print "=========== BREAKPOINT, start RESUME ===================="
94 self.e.setExecMode(0) # YACS::CONTINUE
95 self.e.resumeCurrentBreakPoint()
100 self.assertEqual(106, self.p.getChildByName('node48').getEffectiveState())
101 self.assertEqual(999, self.p.getChildByName('node13').getEffectiveState())
102 self.assertEqual(888, self.p.getChildByName('node14').getEffectiveState())
103 self.assertEqual(777, self.p.getChildByName('c1').getEffectiveState())
104 self.assertEqual(777, self.p.getChildByName('c1.c1.n2').getEffectiveState())
105 self.assertEqual(106, self.p.getChildByName('c0.c1.n1').getEffectiveState())
106 self.assertEqual(999, self.p.getChildByName('c0.n2').getEffectiveState())
107 self.assertEqual(888, self.p.getChildByName('node62').getEffectiveState())
108 print "================= End of RESUME ========================="
111 def test3_RunWithoutBreakpoints(self):
112 # --- start execution, run without breakpoints
115 print "================= Start of CONTINUE ====================="
116 self.e.setExecMode(0) # YACS::CONTINUE
117 run3 = threading.Thread(None, self.e.RunPy, "continue", (self.p,0))
121 #self.e.displayDot(p)
123 self.assertEqual(106, self.p.getChildByName('node48').getEffectiveState())
124 self.assertEqual(999, self.p.getChildByName('node13').getEffectiveState())
125 self.assertEqual(888, self.p.getChildByName('node14').getEffectiveState())
126 self.assertEqual(777, self.p.getChildByName('c1').getEffectiveState())
127 self.assertEqual(777, self.p.getChildByName('c1.c1.n2').getEffectiveState())
128 self.assertEqual(106, self.p.getChildByName('c0.c1.n1').getEffectiveState())
129 self.assertEqual(999, self.p.getChildByName('c0.n2').getEffectiveState())
130 self.assertEqual(888, self.p.getChildByName('node62').getEffectiveState())
131 print "================= End of CONTINUE ======================="
134 def test4_StopOnError(self):
135 # --- stop execution on first error and save state
138 print "================= Start of STOPONERROR =================="
139 self.e.setStopOnError()
140 run4 = threading.Thread(None, self.e.RunPy, "continue", (self.p,0))
144 self.e.saveState("dumpErrorASchema.xml")
145 self.e.stopExecution()
147 #self.e.displayDot(self.p)
148 s13 = self.p.getChildByName('node13').getEffectiveState()
149 s43 = self.p.getChildByName('node43').getEffectiveState()
150 self.assert_((s13==999) or (s43==999))
151 print "================= End of STOPONERROR ====================="
154 def test5_PartialExec(self):
155 # --- stop execution after breakpoint
158 print "================= Start of PARTIALEXEC ==================="
160 self.e.setListOfBreakPoints(brp)
161 self.e.setExecMode(2) # YACS::STOPBEFORENODES
162 #self.e.displayDot(self.p)
163 run5 = threading.Thread(None, self.e.RunPy, "breakpoint", (self.p,0))
167 #self.e.displayDot(self.p)
168 self.e.saveState('dumpPartialASchema.xml')
169 #self.e.displayDot(self.p)
170 self.e.stopExecution()
172 #self.e.displayDot(self.p)
173 self.assertEqual(106, self.p.getChildByName('node34').getEffectiveState())
174 self.assertEqual(101, self.p.getChildByName('node35').getEffectiveState())
175 print "================= reach BREAKPOINT PARTIAL EXEC =========="
181 U = os.getenv('USER')
182 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
183 f.write(" --- TEST src/yacsloader: testExec.py\n")
184 suite = unittest.makeSuite(TestExec)
185 unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)