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 with tempfile.TemporaryDirectory() as tmpdirname:
38 salome.cm.SetOverrideEnvForContainersSimple([("SALOME_BIG_OBJ_ON_DISK_THRES","1"),("SALOME_FILE_BIG_OBJ_DIR",str(tmpdirname))])
40 SALOMERuntime.RuntimeSALOME.setRuntime()
41 r=SALOMERuntime.getSALOMERuntime()
42 p=r.createProc("StressTest")
43 ti=p.createType("int","int")
44 td=p.createType("double","double")
45 tdd=p.createSequenceTc("seqdouble","seqdouble",td)
46 tddd=p.createSequenceTc("seqseqdouble","seqseqdouble",tdd)
47 tdddd=p.createSequenceTc("seqseqseqdouble","seqseqseqdouble",tddd)
48 pyobj=p.createInterfaceTc("python:obj:1.0","pyobj",[])
49 seqpyobj=p.createSequenceTc("list[pyobj]","list[pyobj]",pyobj)
50 seqseqpyobj=p.createSequenceTc("list[list[pyobj]]","list[list[pyobj]]",seqpyobj)
51 seqseqseqpyobj=p.createSequenceTc("list[list[list[pyobj]]]","list[list[list[pyobj]]]",seqseqpyobj)
52 cont=p.createContainer("gg","Salome")
53 cont.setProperty("name","localhost")
54 cont.setProperty("hostname","localhost")
57 startNode = r.createScriptNode("Salome","start")
58 startNode.setExecutionMode("local")
59 startNode.setContainer(None)
60 startNode.setSqueezeStatus(True)
61 startNode.setScript("""o2 = [[[ {k:2*k for k in range(23,55)} ]]]""")
62 po2 = startNode.edAddOutputPort("o2",seqseqseqpyobj)
63 p.edAddChild(startNode)
65 fe = r.createForEachLoopDyn("fe",seqseqpyobj)
67 p.edAddCFLink(startNode,fe)
68 p.edAddLink(po2,fe.edGetSeqOfSamplesPort())
70 gather2Node = r.createScriptNode("Salome","gather2")
71 p.edAddChild(gather2Node)
72 gather2Node.setExecutionMode("local")
73 gather2Node.setContainer(None)
74 gather2Node.setSqueezeStatus(True)
75 pi5 = gather2Node.edAddInputPort("i5",seqpyobj)
76 po5 = gather2Node.edAddOutputPort("o5",seqpyobj)
77 gather2Node.setScript("""
82 effEnv = {elt.key:elt.val for elt in salome.cm.GetOverrideEnvForContainers()}
83 if len( glob( os.path.join( effEnv["SALOME_FILE_BIG_OBJ_DIR"], "*.pckl" ) ) ) != 1:
84 raise RuntimeError("Fail !")
87 p.edAddCFLink(fe,gather2Node)
89 n1b = r.createBloc("n1b")
92 gather1Node = r.createScriptNode("Salome","gather1")
93 gather1Node.setExecutionMode("local")
94 gather1Node.setContainer(None)
95 gather1Node.setSqueezeStatus(True)
96 pi6 = gather1Node.edAddInputPort("i6",seqpyobj)
97 po6 = gather1Node.edAddOutputPort("o6",seqpyobj)
98 gather1Node.setScript("""print("gather1")
101 n1b.edAddChild(gather1Node)
102 fe1 = r.createForEachLoopDyn("fe1",seqpyobj)
104 n1b.edAddCFLink(fe1,gather1Node)
106 n2b = r.createBloc("n2b")
108 fe2 = r.createForEachLoopDyn("fe2",pyobj)
111 gather0Node = r.createScriptNode("Salome","gather0")
112 gather0Node.setExecutionMode("local")
113 gather0Node.setContainer(None)
114 gather0Node.setSqueezeStatus(True)
115 pi7 = gather0Node.edAddInputPort("i7",seqpyobj)
116 po7 = gather0Node.edAddOutputPort("o7",seqpyobj)
117 gather0Node.setScript("""
121 n2b.edAddChild(gather0Node)
122 n2b.edAddCFLink(fe2,gather0Node)
123 heatNode = r.createScriptNode("Salome","HeatMarcelNode")
124 heatNode.setExecutionMode("remote")
125 heatNode.setContainer(cont)
126 heatNode.setSqueezeStatus(True)
127 heatNode.setScript("""o3 = list(range(100,200))""")
128 pi3 = heatNode.edAddInputPort("i3",pyobj)
129 po3 = heatNode.edAddOutputPort("o3",pyobj)
130 fe2.edSetNode(heatNode)
131 fe2.edAddLink(fe2.edGetSamplePort(),pi3)
133 p.edAddLink( fe1.edGetSamplePort(), fe2.edGetSeqOfSamplesPort() )
134 p.edAddLink( fe.edGetSamplePort(), fe1.edGetSeqOfSamplesPort() )
135 p.edAddLink( po6, pi5 )
136 p.edAddLink( po7, pi6 )
137 p.edAddLink( po3, pi7 )
140 fname = "stressTest3.xml"
141 #pp.saveSchema(fname)
143 l=loader.YACSLoader()
146 st = datetime.datetime.now()
147 ex=pilot.ExecutorSwig()
148 ex.setMaxNbOfThreads(1000)
150 salome.cm.ShutdownContainers()
151 print("End of computation {}".format( str(datetime.datetime.now()-st) ) )
152 self.assertTrue( pp.getState() == pilot.DONE )
153 from glob import glob
154 self.assertEqual(len( glob(os.path.join(str(tmpdirname),"*.pckl") ) ), 0 )
156 if __name__ == '__main__':
157 with tempfile.TemporaryDirectory() as dir_test:
158 file_test = os.path.join(dir_test,"UnitTestsResult")
159 with open(file_test, 'a') as f:
160 f.write(" --- TEST src/yacsloader: testYacsProxy.py\n")
161 suite = unittest.makeSuite(TestYacsProxy)
162 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
163 if not result.wasSuccessful():
164 raise RuntimeError("Test failed !")