]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine_swig/basic_first_SSL.py
Salome HOME
6503bd8f418009213d0c116f99c7d59812acad29
[modules/yacs.git] / src / engine_swig / basic_first_SSL.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2021-2022  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, or (at your option) any later version.
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
21 import unittest
22 import pilot
23 import SALOMERuntime
24 import loader
25 import os
26 import datetime
27 import salome
28 import sys
29 import time
30 import NamingService
31
32 class TestBasicFirstSSL(unittest.TestCase):
33     def test0(self):
34         """
35         First SSL test with YACS. This test launches SALOME_Container_No_NS_Serv servers to perform it's job.
36         These extra SALOME_Container_No_NS_Serv servers are shut down at the end
37         """
38         salome.standalone()
39         NamingService.NamingService.SetLogContainersFile()
40         SALOMERuntime.RuntimeSALOME.setRuntime()
41         rrr=SALOMERuntime.getSALOMERuntime()
42         """First test of HP Container no loop here only the 3 sorts of python nodes (the Distributed is it still used and useful ?) """
43         fname= "TestSaveLoadRun0.xml"
44         nbOfNodes=2
45         sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
46         l=loader.YACSLoader()
47         p=rrr.createProc("prTest0")
48         td=p.createType("double","double")
49         ti=p.createType("int","int")
50         pg=pilot.PlayGround()
51         pg.setData([("localhost",4)])
52
53         script0="""
54 def ff(nb,dbg):
55     from math import cos
56     import datetime
57
58     ref=datetime.datetime.now()
59     t=0. ; pas=1./float(nb)
60     for i in range(nb):
61         for j in range(nb):
62             x=j*pas
63             t+=1.+cos(1.*(x*3.14159))
64             pass
65         pass
66     print("coucou from script0-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
67     return t
68         """
69         for i in range(nbOfNodes):
70             cont=p.createContainer("gg{}".format(i),"Salome")
71             cont.setProperty("name","localhost")
72             cont.setProperty("hostname","localhost")
73             cont.setProperty("nb_proc_per_node","1")
74             node0=rrr.createFuncNode("DistPython","node%i"%(i))
75             p.edAddChild(node0)
76             node0.setFname("ff")
77             node0.setContainer(cont)
78             node0.setScript(script0)
79             nb=node0.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
80             dbg=node0.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
81             out0=node0.edAddOutputPort("s",td)
82             pass
83         p.saveSchema(fname)
84         p=l.load(fname)
85         ex=pilot.ExecutorSwig()
86         self.assertEqual(p.getState(),pilot.READY)
87         st=datetime.datetime.now()
88         p.propagePlayGround(pg)
89         # 1st exec
90         #input(os.getpid())
91         ex.RunW(p,0)
92         print("Time spend of test0 to run 1st %s"%(str(datetime.datetime.now()-st)))
93         self.assertEqual(p.getState(),pilot.DONE)
94         # 2nd exec using the same already launched remote python interpreters
95         st=datetime.datetime.now()
96         ex.RunW(p,0)
97         print("Time spend of test0 to run 2nd %s"%(str(datetime.datetime.now()-st)))
98         self.assertEqual(p.getState(),pilot.DONE)
99         # 3rd exec using the same already launched remote python interpreters
100         st=datetime.datetime.now()
101         ex.RunW(p,0)
102         print("Time spend of test0 to run 3rd %s"%(str(datetime.datetime.now()-st)))
103         self.assertEqual(p.getState(),pilot.DONE)
104         print( "file containing list of IORS of containers : \"{}\"".format( NamingService.NamingService.GetLogContainersFile() ) )
105         print(NamingService.NamingService.IOROfNS())
106         print(NamingService.NamingService.RefOfNS())
107         print("Killing all containers")
108         NamingService.NamingService.KillContainersInFile( NamingService.NamingService.GetLogContainersFile() )
109
110
111 if __name__ == '__main__':
112     unittest.main()