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