2 # Copyright (C) 2023 CEA, EDF
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.
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
30 class TestYacsProxy(unittest.TestCase):
33 [EDF27816] : test to check
36 tmpdirname = "/tmp/tmp9kaggixn"
38 #with tempfile.TemporaryDirectory() as tmpdirname:
39 salome.cm.SetOverrideEnvForContainersSimple([("SALOME_BIG_OBJ_ON_DISK_THRES","1000000"),("SALOME_FILE_BIG_OBJ_DIR",str(tmpdirname))])
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")
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)
66 fe = r.createForEachLoopDyn("fe",seqseqpyobj)
68 p.edAddCFLink(startNode,fe)
69 p.edAddLink(po2,fe.edGetSeqOfSamplesPort())
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("""
82 if len( glob( os.path.join( os.environ["SALOME_FILE_BIG_OBJ_DIR"], "*.pckl" ) ) ) == 1:
83 raise RuntimeError("Fail !")
86 p.edAddCFLink(fe,gather2Node)
88 n1b = r.createBloc("n1b")
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")
100 n1b.edAddChild(gather1Node)
101 fe1 = r.createForEachLoopDyn("fe1",seqpyobj)
103 n1b.edAddCFLink(fe1,gather1Node)
105 n2b = r.createBloc("n2b")
107 fe2 = r.createForEachLoopDyn("fe2",pyobj)
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("""
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)
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 )
139 fname = "stressTest3.xml"
142 l=loader.YACSLoader()
145 st = datetime.datetime.now()
146 ex=pilot.ExecutorSwig()
147 ex.setMaxNbOfThreads(1000)
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 )
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 !")