Salome HOME
0456556a120373c490d2fc93a50bf2afcc199e42
[modules/yacs.git] / src / yacsloader / Test / testResume.py
1 #!/usr/bin/env python
2 #  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 import time
21 import unittest
22 import threading
23
24 import SALOMERuntime
25 import loader
26 import pilot
27
28 class TestResume(unittest.TestCase):
29
30     def setUp(self):
31         SALOMERuntime.RuntimeSALOME_setRuntime(1)
32         self.l = loader.YACSLoader()
33         self.e = pilot.ExecutorSwig()
34         self.p = self.l.load("samples/bloc2.xml")
35         pass
36
37     def test1_PartialExec(self):
38         # --- stop execution after breakpoint
39         time.sleep(1)
40
41         print "================= Start of PARTIALEXEC ==================="
42         brp=['b1.b2.node1']
43         self.e.setListOfBreakPoints(brp)
44         self.e.setExecMode(2) # YACS::STOPBEFORENODES
45         #self.e.displayDot(self.p)
46         run1 = threading.Thread(None, self.e.RunPy, "breakpoint", (self.p,0))
47         run1.start()
48         time.sleep(0.1)
49         self.e.waitPause()
50         #self.e.displayDot(self.p)
51         self.e.saveState('dumpPartialBloc2.xml')
52         #self.e.displayDot(self.p)
53         self.e.stopExecution()
54         #self.e.displayDot(self.p)
55         self.assertEqual(101, self.p.getChildByName('b1.b2.node1').getEffectiveState())
56         self.assertEqual(106, self.p.getChildByName('b1.node1').getEffectiveState())
57         print "================= reach BREAKPOINT PARTIAL EXEC =========="
58         pass
59
60     def test2_ExecFromLoadState(self):
61         # --- reload state from previous partial execution then exec
62         time.sleep(1)
63
64         print "================= Start of EXECLOADEDSTATE ==============="
65         sp = loader.stateParser()
66         sl = loader.stateLoader(sp,self.p)
67         sl.parse('dumpPartialBloc2.xml')
68         #self.e.displayDot(self.p)
69         self.e.setExecMode(0) # YACS::CONTINUE
70         run2 = threading.Thread(None, self.e.RunPy, "loadState", (self.p,0,1,1))
71         run2.start()
72         time.sleep(0.1)
73         self.e.waitPause()
74         #self.e.displayDot(self.p)
75         run2.join()
76         self.assertEqual(106, self.p.getChildByName('node1').getEffectiveState())
77         self.assertEqual(106, self.p.getChildByName('node2').getEffectiveState())
78         self.assertEqual(106, self.p.getChildByName('b1.node1').getEffectiveState())
79         self.assertEqual(106, self.p.getChildByName('b1.node2').getEffectiveState())
80         self.assertEqual(106, self.p.getChildByName('b1.b2.node1').getEffectiveState())
81         self.assertEqual(106, self.p.getChildByName('b1.b2.node2').getEffectiveState())
82         self.assertEqual(106, self.p.getChildByName('b1.b2.loop1.node1').getEffectiveState())
83         print "================= End of EXECLOADEDSTATE ================="
84                           
85     pass
86
87 import os
88 U = os.getenv('USER')
89 f=open("/tmp/" + U + "/UnitTestsResult", 'a')
90 f.write("  --- TEST src/yacsloader: testResume.py\n")
91 suite = unittest.makeSuite(TestResume)
92 unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
93 f.close()