]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader_swig/Test/testYacsProxy.py
Salome HOME
[EDF27816] : Fix bug presence of proxy into a list
[modules/yacs.git] / src / yacsloader_swig / Test / testYacsProxy.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2023  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 tempfile
23 import os
24
25 import pilot
26 import SALOMERuntime
27 import loader
28 import salome
29
30 class TestYacsProxy(unittest.TestCase):
31   def test0(self):
32     """
33     [EDF27816] : test to check
34     """
35     salome.salome_init()
36     tmpdirname = "/tmp/tmp9kaggixn"
37     if True:
38     #with tempfile.TemporaryDirectory() as tmpdirname:
39       salome.cm.SetOverrideEnvForContainersSimple([("SALOME_BIG_OBJ_ON_DISK_THRES","1000000"),("SALOME_FILE_BIG_OBJ_DIR",str(tmpdirname))])
40       ####
41       SALOMERuntime.RuntimeSALOME.setRuntime()
42       r=SALOMERuntime.getSALOMERuntime()
43       p=r.createProc("StressTest")
44       ti=p.createType("int","int")
45       td=p.createType("double","double")
46       tdd=p.createSequenceTc("seqdouble","seqdouble",td)
47       tddd=p.createSequenceTc("seqseqdouble","seqseqdouble",tdd)
48       tdddd=p.createSequenceTc("seqseqseqdouble","seqseqseqdouble",tddd)
49       pyobj=p.createInterfaceTc("python:obj:1.0","pyobj",[])
50       seqpyobj=p.createSequenceTc("list[pyobj]","list[pyobj]",pyobj)
51       seqseqpyobj=p.createSequenceTc("list[list[pyobj]]","list[list[pyobj]]",seqpyobj)
52       seqseqseqpyobj=p.createSequenceTc("list[list[list[pyobj]]]","list[list[list[pyobj]]]",seqseqpyobj)
53       cont=p.createContainer("gg","Salome")
54       cont.setProperty("name","localhost")
55       cont.setProperty("hostname","localhost")
56
57       ######## Level 0
58       startNode = r.createScriptNode("Salome","start")
59       startNode.setExecutionMode("local")
60       startNode.setContainer(None)
61       startNode.setSqueezeStatus(True)
62       startNode.setScript("""o2 = [[[ {k:2*k for k in range(23,55)}  ]]]""")
63       po2 = startNode.edAddOutputPort("o2",seqseqseqpyobj)
64       p.edAddChild(startNode)
65       #
66       fe = r.createForEachLoopDyn("fe",seqseqpyobj)
67       p.edAddChild(fe)
68       p.edAddCFLink(startNode,fe)
69       p.edAddLink(po2,fe.edGetSeqOfSamplesPort())
70       #
71       gather2Node = r.createScriptNode("Salome","gather2")
72       p.edAddChild(gather2Node)
73       gather2Node.setExecutionMode("local")
74       gather2Node.setContainer(None)
75       gather2Node.setSqueezeStatus(True)
76       p.edAddChild(gather2Node)
77       pi5 = gather2Node.edAddInputPort("i5",seqpyobj)
78       po5 = gather2Node.edAddOutputPort("o5",seqpyobj)
79       gather2Node.setScript("""
80 from glob import glob
81 import os
82 if len( glob( os.path.join( os.environ["SALOME_FILE_BIG_OBJ_DIR"], "*.pckl" ) ) ) == 1:
83   raise RuntimeError("Fail !")
84 print("gather2")
85 o5 = i5""")
86       p.edAddCFLink(fe,gather2Node)
87       ####### Level 1
88       n1b = r.createBloc("n1b")
89       fe.edSetNode(n1b)
90       #
91       gather1Node = r.createScriptNode("Salome","gather1")
92       gather1Node.setExecutionMode("local")
93       gather1Node.setContainer(None)
94       gather1Node.setSqueezeStatus(True)
95       pi6 = gather1Node.edAddInputPort("i6",seqpyobj)
96       po6 = gather1Node.edAddOutputPort("o6",seqpyobj)
97       gather1Node.setScript("""print("gather1")
98 print(i6)
99 o6 = i6""")
100       n1b.edAddChild(gather1Node)
101       fe1 = r.createForEachLoopDyn("fe1",seqpyobj)
102       n1b.edAddChild(fe1)
103       n1b.edAddCFLink(fe1,gather1Node)
104       ####### Level2
105       n2b = r.createBloc("n2b")
106       fe1.edSetNode(n2b)
107       fe2 = r.createForEachLoopDyn("fe2",pyobj)
108       n2b.edAddChild(fe2)
109       #
110       gather0Node = r.createScriptNode("Salome","gather0")
111       gather0Node.setExecutionMode("local")
112       gather0Node.setContainer(None)
113       gather0Node.setSqueezeStatus(True)
114       pi7 = gather0Node.edAddInputPort("i7",seqpyobj)
115       po7 = gather0Node.edAddOutputPort("o7",seqpyobj)
116       gather0Node.setScript("""
117 print("gather0")
118 print(i7)
119 o7 = i7""")
120       n2b.edAddChild(gather0Node)
121       n2b.edAddCFLink(fe2,gather0Node)
122       heatNode = r.createScriptNode("Salome","HeatMarcelNode")
123       heatNode.setExecutionMode("remote")
124       heatNode.setContainer(cont)
125       heatNode.setSqueezeStatus(True)
126       heatNode.setScript("""o3 = list(range(100,200))""")
127       pi3 = heatNode.edAddInputPort("i3",pyobj)
128       po3 = heatNode.edAddOutputPort("o3",pyobj)
129       fe2.edSetNode(heatNode)
130       fe2.edAddLink(fe2.edGetSamplePort(),pi3)
131       # connection part
132       p.edAddLink( fe1.edGetSamplePort(), fe2.edGetSeqOfSamplesPort() )
133       p.edAddLink( fe.edGetSamplePort(), fe1.edGetSeqOfSamplesPort() )
134       p.edAddLink( po6, pi5 )
135       p.edAddLink( po7, pi6 )
136       p.edAddLink( po3, pi7 )
137
138       pp = p
139       fname = "stressTest3.xml"
140       pp.saveSchema(fname)
141       ####
142       l=loader.YACSLoader()
143       #p=l.load(fname)
144       import datetime
145       st = datetime.datetime.now()
146       ex=pilot.ExecutorSwig()
147       ex.setMaxNbOfThreads(1000)
148       ex.RunW(pp,0)
149       salome.cm.ShutdownContainers()
150       print("End of computation {}".format( str(datetime.datetime.now()-st) ) )
151       self.assertTrue( pp.getState() == pilot.DONE )
152       from glob import glob
153       self.assertEqual(len( glob(os.path.join(str(tmpdirname),"*.pckl") ) ), 0 )
154   
155 if __name__ == '__main__':
156   with tempfile.TemporaryDirectory() as dir_test:
157     file_test = os.path.join(dir_test,"UnitTestsResult")
158     with open(file_test, 'a') as f:
159         f.write("  --- TEST src/yacsloader: testYacsProxy.py\n")
160         suite = unittest.makeSuite(TestYacsProxy)
161         result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
162         if not result.wasSuccessful():
163            raise RuntimeError("Test failed !")
164