+
+ def test11(self):
+ "test if we do not restart from the begining of the schema after an error in a foreach"
+ fname=os.path.join(self.workdir, "test11.xml")
+ from datetime import datetime
+ p=self.r.createProc("prTest2")
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ cont.setProperty("type","multi")
+ td=p.createType("double","double")
+ ti=p.createType("int","int")
+ tsi=p.createSequenceTc("seqint","seqint",ti)
+ tsd=p.createSequenceTc("seqdbl","seqdbl",td)
+ n0=self.r.createScriptNode("","n0")
+ o0=n0.edAddOutputPort("o0",tsi)
+ n0.setScript("o0=[ elt for elt in range(12) ]")
+ p.edAddChild(n0)
+ n1=self.r.createForEachLoop("n1",ti)
+ n10=self.r.createScriptNode("","n10")
+ n10.setExecutionMode("remote")
+ n10.setContainer(cont)
+ n1.edAddChild(n10)
+ n10.setScript("""
+import time
+if i1%2==1:
+ raise Exception("Simulated error !")
+else:
+ time.sleep(0.1)
+ o2=2*i1
+""")
+ i1=n10.edAddInputPort("i1",ti)
+ o2=n10.edAddOutputPort("o2",ti)
+ p.edAddChild(n1)
+ p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
+ p.edAddLink(n1.edGetSamplePort(),i1)
+ p.edAddCFLink(n0,n1)
+ n1.edGetNbOfBranchesPort().edInitPy(2)
+ n2=self.r.createScriptNode("","n2")
+ n2.setScript("o4=i3")
+ i3=n2.edAddInputPort("i3",tsi)
+ o4=n2.edAddOutputPort("o4",tsi)
+ n2.setScript("o4=i3")
+ p.edAddChild(n2)
+ p.edAddCFLink(n1,n2)
+ p.edAddLink(o2,i3)
+ p.saveSchema(fname)
+ #
+ l=loader.YACSLoader()
+ p=l.load(fname)
+ n1=p.getChildByName("n1")
+ ex=pilot.ExecutorSwig()
+ ex.setKeepGoingProperty(True)
+ #
+ startt=datetime.now()
+ ex.RunW(p,0)
+ t0=datetime.now()-startt
+ #
+ self.assertEqual(p.getState(),pilot.FAILED)
+ self.assertEqual(n1.getState(),pilot.FAILED)
+ n1.edGetSeqOfSamplesPort().getPyObj()
+ a,b,c=n1.getPassedResults(ex)
+
+ self.assertEqual(a,[0,2,4,6,8,10])
+ self.assertEqual([elt.getPyObj() for elt in b],[[0,4,8,12,16,20]])
+
+ p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(12) ]")
+ p.getChildByName("n1").getChildByName("n10").setScript("""
+import time
+if i1%2==0:
+ raise Exception("Simulated error !")
+else:
+ time.sleep(1)
+ o2=5*i1
+""")
+ p.resetState(1)
+
+
+ p.getChildByName("n1").assignPassedResults(a,b,c)
+ p.exUpdateState();
+ #
+ startt=datetime.now()
+ ex.RunW(p,0,False)
+ t1=datetime.now()-startt
+ #
+ self.assertEqual(n1.getState(),pilot.DONE)
+ self.assertEqual(p.getState(),pilot.DONE)
+ self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,5,4,15,8,25,12,35,16,45,20,55])
+ pass
+
+ def test12(self):
+ """ Test of nested ForEachLoop with a port connected inside and outside the loop."""
+ schema = self.r.createProc("schema")
+ ti = schema.getTypeCode("int")
+ tiset = schema.createSequenceTc("", "seqint", ti)
+ tisetseq = schema.createSequenceTc("", "seqintvec", tiset)
+
+ n1 = self.r.createScriptNode("", "PyScript2")
+ n1.edAddInputPort("i3", ti)
+ n1.edAddInputPort("i4", ti)
+ n1.edAddOutputPort("o5", ti)
+ n1.setScript("o5=i3+i4")
+
+ n2 = self.r.createScriptNode("", "PyScript1")
+ n2.edAddInputPort("i2", ti)
+ n2.edAddOutputPort("o3", ti)
+ n2.setScript("o3=i2")
+
+ b1 = self.r.createBloc("Bloc1")
+ b1.edAddChild(n1)
+ b1.edAddChild(n2)
+
+ fe1 = self.r.createForEachLoop("ForEach1", ti)
+ fe1.getInputPort("nbBranches").edInitPy(2)
+ fe1.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
+ fe1.edSetNode(b1)
+
+ n3 = self.r.createScriptNode("", "PostProcessing")
+ n3.edAddInputPort("i7", tiset)
+ n3.edAddInputPort("i5", tiset)
+ n3.edAddOutputPort("o4", ti)
+ n3.setScript("""
+o4 = 0
+for i in i7:
+ o4 = i + o4
+
+for i in i5:
+ o4 = i + o4
+""")
+
+ b0 = self.r.createBloc("Bloc0")
+ b0.edAddChild(fe1)
+ b0.edAddChild(n3)
+
+ fe0 = self.r.createForEachLoop("ForEach1", ti)
+ fe0.getInputPort("nbBranches").edInitPy(2)
+ fe0.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
+ fe0.edSetNode(b0)
+
+ schema.edAddChild(fe0)
+
+ nx = self.r.createScriptNode("", "Result")
+ nx.edAddInputPort("i8", tiset)
+ nx.edAddOutputPort("o6", ti)
+ nx.setScript("""
+o6 = 0
+for i in i8:
+ o6 = i + o6
+""")
+ schema.edAddChild(nx)
+
+ schema.edAddLink(fe1.getOutputPort("evalSamples"), n1.getInputPort("i3"))
+ schema.edAddLink(fe0.getOutputPort("evalSamples"), n1.getInputPort("i4"))
+
+ schema.edAddDFLink(n1.getOutputPort("o5"), n3.getInputPort("i7"))
+ schema.edAddDFLink(n2.getOutputPort("o3"), n3.getInputPort("i5"))
+
+ po5 = fe1.getOutputPort("Bloc1.PyScript2.o5")
+ schema.edAddDFLink(po5, n2.getInputPort("i2"))
+
+ schema.edAddDFLink(n3.getOutputPort("o4"), nx.getInputPort("i8"))
+# schema.saveSchema("foreach12.xml")
+
+ e = pilot.ExecutorSwig()
+ e.RunW(schema)
+ self.assertEqual(schema.getState(),pilot.DONE)
+ resVal = schema.getChildByName("Result").getOutputPort("o6").getPyObj()
+ self.assertEqual(resVal, 160)
+ pass
+
+ def test13(self):
+ """ Non regression test EDF11239. ForEach into ForEach. Problem on cloning linked to DeloymentTree.appendTask method that was too strong."""
+ p=self.r.createProc("Bug11239")
+ ti=p.createType("int","int")
+ ti2=p.createSequenceTc("seqint","seqint",ti)
+ #
+ cont=p.createContainer("DefaultContainer","Salome")
+ #
+ node0=self.r.createForEachLoop("ForEachLoop_int0",ti)
+ p.edAddChild(node0)
+ node0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
+ node0.edGetNbOfBranchesPort().edInitInt(2)
+ #
+ node00=self.r.createBloc("Bloc0")
+ node0.edAddChild(node00)
+ node000_0=self.r.createForEachLoop("ForEachLoop_int1",ti)
+ node00.edAddChild(node000_0)
+ node000_0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
+ node000_0.edGetNbOfBranchesPort().edInitInt(3)
+ #
+ node0000=self.r.createBloc("Bloc1")
+ node000_0.edAddChild(node0000)
+ #
+ node0000_0=self.r.createScriptNode("","PyScript2")
+ node0000.edAddChild(node0000_0)
+ i3=node0000_0.edAddInputPort("i3",ti)
+ i4=node0000_0.edAddInputPort("i4",ti)
+ o5=node0000_0.edAddOutputPort("o5",ti)
+ node0000_0.setScript("o5 = i3 + i4")
+ node0000_0.setContainer(cont)
+ node0000_0.setExecutionMode("remote")
+ p.edAddLink(node0.edGetSamplePort(),i3)
+ p.edAddLink(node000_0.edGetSamplePort(),i4)
+ #
+ node0000_1=self.r.createScriptNode("","PyScript1")
+ node0000.edAddChild(node0000_1)
+ o3=node0000_1.edAddOutputPort("o3",ti)
+ node0000_1.setScript("o3 = 7")
+ node0000_1.setExecutionMode("local")
+ p.edAddCFLink(node0000_0,node0000_1)
+ #
+ node000_1=self.r.createScriptNode("","PostTraitement")
+ node00.edAddChild(node000_1)
+ i7=node000_1.edAddInputPort("i7",ti2)
+ i5=node000_1.edAddInputPort("i5",ti2)
+ node000_1.setScript("for i in i7:\n print(i)\nprint(\"separation\")\nfor i in i5:\n print(i)")
+ node000_1.setContainer(cont)
+ node000_1.setExecutionMode("remote")
+ p.edAddLink(o5,i7)
+ p.edAddLink(o3,i5)
+ p.edAddCFLink(node000_0,node000_1)
+ #
+ #p.saveSchema("tmpp.xml")
+ ex = pilot.ExecutorSwig()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ def test14(self):
+ """ Non regression EDF11027. Problem after Save/Load of a foreach node with type pyobj with input "SmplsCollection" manually set before. Correction in convertToYacsObjref from XML->Neutral. Objref can hide a string !"""
+ xmlFileName=os.path.join(self.workdir, "test14.xml")
+ SALOMERuntime.RuntimeSALOME_setRuntime()
+ r=pilot.getRuntime()
+ n0=r.createProc("test23/zeRun")
+ tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
+ tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
+ n0bis=r.createBloc("test23/main") ; n0.edAddChild(n0bis)
+ n00=r.createBloc("test23/run") ; n0bis.edAddChild(n00)
+ #
+ n000=r.createForEachLoop("test23/FE",tp) ; n00.edAddChild(n000)
+ n0000=r.createScriptNode("Salome","test23/run_internal") ; n000.edSetNode(n0000)
+ i0=n0000.edAddInputPort("i0",tp)
+ i1=n0000.edAddInputPort("i1",tp) ; i1.edInitPy(3)
+ o0=n0000.edAddOutputPort("o0",tp)
+ n0000.setScript("o0=i0+i1")
+ #
+ n00.edAddLink(n000.edGetSamplePort(),i0)
+ #
+ n000.edGetSeqOfSamplesPort().edInitPy(list(range(10)))
+ n000.edGetNbOfBranchesPort().edInitInt(2)
+ #
+ n01=r.createScriptNode("Salome","test23/check") ; n0bis.edAddChild(n01)
+ n0bis.edAddCFLink(n00,n01)
+ i2=n01.edAddInputPort("i2",tp2)
+ o1=n01.edAddOutputPort("o1",tp2)
+ n01.setScript("o1=i2")
+ n0bis.edAddLink(o0,i2)
+ #
+ n0.saveSchema(xmlFileName)
+ #
+ l=loader.YACSLoader()
+ p=l.load(xmlFileName) # very import do not use n0 but use p instead !
+ ex=pilot.ExecutorSwig()
+ #
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ self.assertEqual(p.getChildByName("test23/main.test23/check").getOutputPort("o1").getPyObj(),[3,4,5,6,7,8,9,10,11,12])
+ pass
+
+ def test15(self):
+ from SALOME_PyNode import UnProxyObjectSimple
+ #fname=os.path.join(self.workdir, "BugInConcurrentLaunchDftCont.xml")
+ p=self.r.createProc("pr")
+ ti=p.createType("int","int")
+ cont=p.createContainer("DefaultContainer","Salome")
+ # enable WorkloadManager mode because containers are not registered right
+ # in classical mode (4 containers with the same name are launched at the
+ # same time).
+ p.setProperty("executor", "WorkloadManager")
+ cont.setProperty("type", "multi")
+ cont.setProperty("container_name","FactoryServer")
+ b=self.r.createBloc("Bloc") ; p.edAddChild(b)
+ #
+ nb=4
+ outs=[]
+ for i in range(nb):
+ node=self.r.createScriptNode("Salome","node%d"%i)
+ node.setExecutionMode("remote")
+ node.setContainer(cont)
+ outs.append(node.edAddOutputPort("i",ti))
+ node.setScript("i=%d"%i)
+ b.edAddChild(node)
+ #
+ node=self.r.createScriptNode("Salome","nodeEnd")
+ node.setExecutionMode("remote")
+ node.setContainer(cont)
+ res=node.edAddOutputPort("res",ti)
+ p.edAddChild(node)
+ l=[]
+ for i in range(nb):
+ elt="i%d"%i
+ inp=node.edAddInputPort(elt,ti) ; l.append(elt)
+ p.edAddChild(node)
+ p.edAddLink(outs[i],inp)
+ node.setScript("res="+"+".join(l))
+ p.edAddCFLink(b,node)
+ #
+ for i in range(10):
+ p.init()
+ ex = pilot.ExecutorSwig()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(UnProxyObjectSimple( res.getPyObj() ),6)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ def test16(self):
+ """ Test to check that a list[pyobj] outputport linked to pyobj inputport is OK."""
+ SALOMERuntime.RuntimeSALOME_setRuntime()
+ self.r=pilot.getRuntime()
+ n0=self.r.createProc("test16/zeRun")
+ tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
+ tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
+
+ n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
+ o0=n00.edAddOutputPort("o0",tp2)
+ n00.setScript("o0=[[i+1] for i in range(8)]")
+ n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
+ i1=n01.edAddInputPort("i1",tp)
+ n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
+ n0.edAddCFLink(n00,n01)
+ n0.edAddLink(o0,i1)
+ #
+ ex=pilot.ExecutorSwig()
+ self.assertEqual(n0.getState(),pilot.READY)
+ ex.RunW(n0,0)
+ self.assertEqual(n0.getState(),pilot.DONE)
+ pass
+
+ def test17(self):
+ """ Same as test16 except that tp2 is not list of tp but a list of copy of tp"""
+ SALOMERuntime.RuntimeSALOME_setRuntime()
+ self.r=pilot.getRuntime()
+ n0=self.r.createProc("test17/zeRun")
+ tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
+ tpp=n0.createInterfaceTc("python:obj:1.0","pyobj",[]) # diff is here
+ tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tpp)
+
+ n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
+ o0=n00.edAddOutputPort("o0",tp2)
+ n00.setScript("o0=[[i+1] for i in range(8)]")
+ n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
+ i1=n01.edAddInputPort("i1",tp)
+ n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
+ n0.edAddCFLink(n00,n01)
+ n0.edAddLink(o0,i1)
+ #
+ ex=pilot.ExecutorSwig()
+ self.assertEqual(n0.getState(),pilot.READY)
+ ex.RunW(n0,0)
+ self.assertEqual(n0.getState(),pilot.DONE)
+ pass
+
+ def test18(self):
+ p=self.r.createProc("prTest18")
+ n00=self.r.createScriptNode("Salome","n00")
+ self.assertEqual(n00.getMaxLevelOfParallelism(),1)
+ n00.setExecutionMode("remote")
+ self.assertEqual(n00.getMaxLevelOfParallelism(),1)
+ cont=p.createContainer("gg","Salome")
+ n00.setContainer(cont)
+ self.assertEqual(n00.getMaxLevelOfParallelism(),1)
+ cont.setProperty("nb_proc_per_nod","6")
+ self.assertEqual(n00.getMaxLevelOfParallelism(),1)
+ cont.setProperty("nb_proc_per_node","7") # <- here
+ self.assertEqual(n00.getMaxLevelOfParallelism(),7) # <- here
+ pass
+
+ def test19(self):
+ """This test checks the mechanism of YACS that allow PythonNodes to know their DynParaLoop context."""
+ fname=os.path.join(self.workdir, "test19.xml")
+ l=loader.YACSLoader()
+ #
+ p=self.r.createProc("PROC")
+ p.setProperty("executor","workloadmanager")
+ ti=p.createType("int","int")
+ tdi=p.createSequenceTc("seqint","seqint",ti)
+ # Level0
+ fe0=self.r.createForEachLoop("FE0",ti) ; p.edAddChild(fe0)
+ fe0.edGetNbOfBranchesPort().edInitInt(4)
+ fe0_end=self.r.createScriptNode("Salome","fe0_end")
+ fe0.edSetFinalizeNode(fe0_end)
+ fe0_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
+assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)""")
+ n0=self.r.createScriptNode("Salome","n0") ; p.edAddChild(n0)
+ n0.setScript("o1=list(range(10))")
+ a=n0.edAddOutputPort("o1",tdi)
+ p.edAddLink(a,fe0.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n0,fe0)
+ # Level1
+ b0=self.r.createBloc("b0") ; fe0.edAddChild(b0)
+ n1=self.r.createScriptNode("Salome","n1") ; b0.edAddChild(n1)
+ n1.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
+assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)
+o1=list(range(10))""")
+ b=n1.edAddOutputPort("o1",tdi)
+ fe1=self.r.createForEachLoop("FE1",ti) ; b0.edAddChild(fe1)
+ fe1.edGetNbOfBranchesPort().edInitInt(3)
+ fe1_end=self.r.createScriptNode("Salome","fe1_end")
+ fe1_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
+assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
+assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
+""")
+ fe1.edSetFinalizeNode(fe1_end)
+ p.edAddLink(b,fe1.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n1,fe1)
+ # Level2
+ n2=self.r.createScriptNode("Salome","n2") ; fe1.edAddChild(n2)
+ n2.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
+assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
+assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
+""")
+
+ p.saveSchema(fname)
+ ex=pilot.ExecutorSwig()
+
+ # local run of PythonNodes n1 and n2
+ p=l.load(fname)
+ p.init()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.setDPLScopeSensitive(True) # <- this line is the aim of the test
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+
+ # run remote
+ p=l.load(fname)
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ # no limit for the number of containers launched
+ cont.setProperty("nb_proc_per_node","0")
+ cont.setProperty("type","multi")
+ #cont.usePythonCache(True)
+ cont.attachOnCloning()
+ n1=p.getChildByName("FE0.b0.n1") ; n1.setExecutionMode("remote") ; n1.setContainer(cont)
+ n2=p.getChildByName("FE0.b0.FE1.n2") ; n2.setExecutionMode("remote") ; n2.setContainer(cont)
+ p.init()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ def test20(self):
+ """This test revealed a huge bug in ElementaryNode contained in a loop or foreach. The RECONNECT state generated invalid dependancies that only HPContainer can reveal the problem"""
+ def assignCont(n,cont):
+ n.setExecutionMode("remote") ; n.setContainer(cont)
+ pass
+ xmlFileName="test20.xml"
+ p=self.r.createProc("test26")
+ p.setProperty("executor","workloadmanager")
+ #
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ # no limit for the number of containers launched
+ cont.setProperty("nb_proc_per_node","0")
+ cont.setProperty("type","multi")
+ cont.usePythonCache(True)
+ cont.attachOnCloning()
+ #
+ po=p.createInterfaceTc("python:obj:1.0","pyobj",[])
+ sop=p.createSequenceTc("list[pyobj]","list[pyobj]",po)
+ #
+ b0=self.r.createBloc("test26/main") ; p.edAddChild(b0)
+ n0=self.r.createScriptNode("Salome","test26/n0") ; assignCont(n0,cont) # 1
+ n0.setScript("""import os
+dd=list( range(10) )""")
+ dd=n0.edAddOutputPort("dd",sop) ; b0.edAddChild(n0)
+ fe0=self.r.createForEachLoop("test26/FE0",po) ; b0.edAddChild(fe0)
+ fe0.edGetNbOfBranchesPort().edInitInt(1) # very important for the test : 1 !
+ fe0i=self.r.createBloc("test26/FE0_internal") ; fe0.edSetNode(fe0i)
+ zeArgInitNode2=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode2,cont) # 2
+ fe0i.edAddChild(zeArgInitNode2)
+ c1=zeArgInitNode2.edAddInputPort("c",po)
+ c2=zeArgInitNode2.edAddOutputPort("c",po)
+ zeRun=self.r.createBloc("test26/zeRun") ; fe0i.edAddChild(zeRun)
+ zeArgInitNode=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode,cont) # 3
+ zeRun.edAddChild(zeArgInitNode)
+ ff1=zeArgInitNode.edAddInputPort("ff",po)
+ ff2=zeArgInitNode.edAddOutputPort("ff",po)
+ line01=self.r.createScriptNode("Salome","line01") ; zeRun.edAddChild(line01) ; assignCont(line01,cont) # 4
+ line01.setScript("ee=3")
+ ee0=line01.edAddOutputPort("ee",po)
+ initt=self.r.createScriptNode("Salome","test26/initt") ; assignCont(initt,cont) # 5
+ initt.setScript("pass") ; zeRun.edAddChild(initt)
+ end=self.r.createScriptNode("Salome","test26/end") ; assignCont(end,cont) # 6
+ end.setScript("import os") ; zeRun.edAddChild(end)
+ retu=self.r.createScriptNode("Salome","return") ; assignCont(retu,cont) # 7
+ retu.setScript("ee=i0") ; zeRun.edAddChild(retu)
+ i0=retu.edAddInputPort("i0",po)
+ ee=retu.edAddOutputPort("ee",po)
+ zeRun.edAddCFLink(zeArgInitNode,line01)
+ zeRun.edAddCFLink(line01,initt)
+ zeRun.edAddCFLink(initt,end)
+ zeRun.edAddCFLink(end,retu)
+ p.edAddLink(ee0,i0)
+ #
+ returnn=self.r.createScriptNode("Salome","return") ; assignCont(returnn,cont) # 8
+ returnn.setScript("elt=i0")
+ i00=returnn.edAddInputPort("i0",po)
+ elt=returnn.edAddOutputPort("elt",po)
+ fe0i.edAddChild(returnn)
+ fe0i.edAddCFLink(zeArgInitNode2,zeRun)
+ fe0i.edAddCFLink(zeRun,returnn)
+ p.edAddLink(c2,ff1)
+ p.edAddLink(ee,i00)
+ #
+ finalize=self.r.createScriptNode("Salome","test26/finalize") ; b0.edAddChild(finalize) ; assignCont(finalize,cont) # 9
+ finalize.setScript("pass")
+ b0.edAddCFLink(n0,fe0)
+ b0.edAddCFLink(fe0,finalize)
+ #
+ p.edAddLink(dd,fe0.edGetSeqOfSamplesPort())
+ p.edAddLink(fe0.edGetSamplePort(),c1)
+ #
+ #xmlFileName="test20.xml"
+ #p.saveSchema(xmlFileName)
+ p.getChildByName("test26/main.test26/FE0").edGetNbOfBranchesPort().edInitInt(1) # very important 1 !
+ #
+ ex=pilot.ExecutorSwig()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ pass
+
+ def test21(self):
+ "test if we restart from a saved state in a foreach loop"
+ fname=os.path.join(self.workdir, "test21.xml")
+ xmlStateFileName=os.path.join(self.workdir, "saveState21.xml")
+ from datetime import datetime
+ p=self.r.createProc("prTest21")
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ cont.setProperty("type","multi")
+ td=p.createType("double","double")
+ ti=p.createType("int","int")
+ tsi=p.createSequenceTc("seqint","seqint",ti)
+ tsd=p.createSequenceTc("seqdbl","seqdbl",td)
+ n0=self.r.createScriptNode("","n0")
+ o0=n0.edAddOutputPort("o0",tsi)
+ n0.setScript("o0=[ elt for elt in range(6) ]")
+ p.edAddChild(n0)
+ n1=self.r.createForEachLoop("n1",ti)
+ n10=self.r.createScriptNode("","n10")
+ n10.setExecutionMode("remote")
+ n10.setContainer(cont)
+ n1.edAddChild(n10)
+ n10.setScript("""
+import time
+time.sleep(9)
+o2=2*i1
+""")
+ i1=n10.edAddInputPort("i1",ti)
+ o2=n10.edAddOutputPort("o2",ti)
+ p.edAddChild(n1)
+ p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
+ p.edAddLink(n1.edGetSamplePort(),i1)
+ p.edAddCFLink(n0,n1)
+ n1.edGetNbOfBranchesPort().edInitPy(2)
+ n2=self.r.createScriptNode("","n2")
+ n2.setScript("o4=i3")
+ i3=n2.edAddInputPort("i3",tsi)
+ o4=n2.edAddOutputPort("o4",tsi)
+ n2.setScript("o4=i3")
+ p.edAddChild(n2)
+ p.edAddCFLink(n1,n2)
+ p.edAddLink(o2,i3)
+ p.saveSchema(fname)
+ #
+ l=loader.YACSLoader()
+ p=l.load(fname)
+ n1=p.getChildByName("n1")
+ ex=pilot.ExecutorSwig()
+ ex.setKeepGoingProperty(True)
+ #
+ startt=datetime.now()
+ import threading
+ myRun=threading.Thread(None, ex.RunW, None, (p,0))
+ myRun.start()
+ import time
+ time.sleep(15)
+ SALOMERuntime.schemaSaveState(p, ex, xmlStateFileName)
+ a,b,c=n1.getPassedResults(ex)
+ myRun.join()
+ t0=datetime.now()-startt
+ #
+ self.assertEqual(p.getState(),pilot.DONE)
+ self.assertEqual(n1.getState(),pilot.DONE)
+ self.assertEqual(a,[0,1])
+ self.assertEqual([elt.getPyObj() for elt in b],[[0,2]])
+ #
+ p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
+ p.getChildByName("n1").getChildByName("n10").setScript("""
+import time
+time.sleep(0.1)
+o2=5*i1
+""")
+ loader.loadState(p, xmlStateFileName)
+ p.resetState(1)
+ p.getChildByName("n1").assignPassedResults(a,b,c)
+ p.exUpdateState();
+ #
+ ex.RunW(p,0,False)
+ #
+ self.assertEqual(n1.getState(),pilot.DONE)
+ self.assertEqual(p.getState(),pilot.DONE)
+ self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
+
+ # Restart from a saved state in a foreach loop without using assignPassedResults.
+ # This test uses the files test21.xml and saveState21.xml produced by test21.
+
+ ex=pilot.ExecutorSwig()
+ l=loader.YACSLoader()
+ q=l.load(fname)
+ q.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
+ q.getChildByName("n1").getChildByName("n10").setScript("""
+import time
+time.sleep(0.1)
+print("execution n10:", i1)
+o2=5*i1
+""")
+ q.getChildByName("n2").setScript("""
+print("execution n2:", i3)
+o4=i3
+""")
+ loader.loadState(q, xmlStateFileName)
+ q.resetState(1)
+ q.exUpdateState()
+ #
+ ex.RunW(q,0,False)
+ #
+ self.assertEqual(q.getChildByName("n1").getState(),pilot.DONE)
+ self.assertEqual(q.getState(),pilot.DONE)
+ self.assertEqual(q.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
+ pass
+
+ def test23(self):
+ """ test focused on weight attribut after a dump and reload from a xml file
+ """
+ fname=os.path.join(self.workdir, "test23.xml")
+ p=self.r.createProc("prTest23")
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ cont.setProperty("type","multi")
+ td=p.createType("double","double")
+ ti=p.createType("int","int")
+ tsi=p.createSequenceTc("seqint","seqint",ti)
+ tsd=p.createSequenceTc("seqdbl","seqdbl",td)
+ n0=self.r.createScriptNode("","n0")
+ o0=n0.edAddOutputPort("o0",tsi)
+ n0.setScript("o0=[ elt for elt in range(6) ]")
+ p.edAddChild(n0)
+ n1=self.r.createForEachLoop("n1",ti)
+ n1.setWeight(3)
+ n10=self.r.createScriptNode("","n10")
+ n10.setExecutionMode("remote")
+ n10.setContainer(cont)
+ n1.edAddChild(n10)
+ n10.setScript("""
+import time
+time.sleep(2)
+o2=2*i1
+""")
+ n10.setWeight(4.)
+ i1=n10.edAddInputPort("i1",ti)
+ o2=n10.edAddOutputPort("o2",ti)
+ p.edAddChild(n1)
+ p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
+ p.edAddLink(n1.edGetSamplePort(),i1)
+ p.edAddCFLink(n0,n1)
+ n1.edGetNbOfBranchesPort().edInitPy(2)
+ n2=self.r.createScriptNode("","n2")
+ n2.setScript("o4=i3")
+ i3=n2.edAddInputPort("i3",tsi)
+ o4=n2.edAddOutputPort("o4",tsi)
+ n2.setScript("o4=i3")
+ p.edAddChild(n2)
+ p.edAddCFLink(n1,n2)
+ p.edAddLink(o2,i3)
+ p.saveSchema(fname)
+ #
+ l=loader.YACSLoader()
+ p=l.load(fname)
+ self.assertEqual(p.getChildByName("n1").getWeight().getSimpleLoopWeight(),3.0)
+ self.assertEqual(p.getChildByName("n1").getChildByName("n10").getWeight().getElementaryWeight(),4.0)
+ pass
+
+ def test24(self):
+ """ Non regression test EDF17470"""
+ SALOMERuntime.RuntimeSALOME.setRuntime()
+ r=SALOMERuntime.getSALOMERuntime()
+ p=r.createProc("prTest2")
+ #
+ cont1=p.createContainer("cont1","Salome")
+ cont1.setProperty("name","localhost")
+ cont1.setProperty("hostname","localhost")
+ cont1.setProperty("type","multi")
+ cont1.setProperty("container_name","container1")
+ #
+ cont2=p.createContainer("cont2","Salome")
+ cont2.setProperty("name","localhost")
+ cont2.setProperty("hostname","localhost")
+ cont2.setProperty("type","multi")
+ cont2.setProperty("container_name","container2")
+ #
+ td=p.createType("double","double")
+ ti=p.createType("int","int")
+ ts=p.createType("string","string")
+ n0=r.createScriptNode("","n0")
+ n0.setScript("""import SalomeSDSClt
+import SALOME
+import salome
+import unittest
+import pickle
+import gc
+import time
+
+def obj2Str(obj):
+ return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
+def str2Obj(strr):
+ return pickle.loads(strr)
+
+
+salome.salome_init()
+scopeName="Scope1"
+varName="a"
+dsm=salome.naming_service.Resolve("/DataServerManager")
+dsm.cleanScopesInNS()
+if scopeName in dsm.listScopes():
+ dsm.removeDataScope(scopeName)
+dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+#
+t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+dss.atomicApply([t0])
+""")
+ n0_sn=n0.edAddOutputPort("scopeName",ts)
+ n0_vn=n0.edAddOutputPort("varName",ts)
+ #
+ n1=r.createScriptNode("","n1")
+ n1_sn=n1.edAddInputPort("scopeName",ts)
+ n1_vn=n1.edAddInputPort("varName",ts)
+ n1.setScript("""import SalomeSDSClt
+import SALOME
+import salome
+import unittest
+import pickle
+import gc
+import time
+
+
+def obj2Str(obj):
+ return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
+def str2Obj(strr):
+ return pickle.loads(strr)
+
+salome.salome_init()
+dsm=salome.naming_service.Resolve("/DataServerManager")
+dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+assert(not isCreated)
+
+t1=dss.addMultiKeyValueSession(varName)
+# lecture 'ef'
+wk2=dss.waitForKeyInVar(varName,obj2Str("ef"))
+wk2.waitFor()
+assert(str2Obj(dss.waitForMonoThrRev(wk2))==[11,12])""")
+ n1.setContainer(cont1)
+ n1.setExecutionMode("remote")
+ #
+ n2=r.createScriptNode("","n2")
+ n2_sn=n2.edAddInputPort("scopeName",ts)
+ n2_vn=n2.edAddInputPort("varName",ts)
+ n2.setScript("""import SalomeSDSClt
+import SALOME
+import salome
+import unittest
+import pickle
+import gc
+import time
+
+
+def obj2Str(obj):
+ return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
+def str2Obj(strr):
+ return pickle.loads(strr)
+
+salome.salome_init()
+dsm=salome.naming_service.Resolve("/DataServerManager")
+dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+assert(not isCreated)
+time.sleep(3.)
+t1=dss.addMultiKeyValueSession(varName)
+t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10]))
+t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("ef"),obj2Str([11,12]))
+""")
+ n2.setContainer(cont2)
+ n2.setExecutionMode("remote")
+ #
+ p.edAddChild(n0)
+ p.edAddChild(n1)
+ p.edAddChild(n2)
+ p.edAddCFLink(n0,n1)
+ p.edAddCFLink(n0,n2)
+ p.edAddLink(n0_sn,n1_sn)
+ p.edAddLink(n0_vn,n1_vn)
+ p.edAddLink(n0_sn,n2_sn)
+ p.edAddLink(n0_vn,n2_vn)
+ #
+ ex=pilot.ExecutorSwig()
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ def test25(self):
+ fname=os.path.join(self.workdir, "test25.xml")
+ p=self.r.createProc("p0")
+ tp=p.createInterfaceTc("python:obj:1.0","pyobj",[])
+ n1_0_sc=self.r.createScriptNode("Salome","n1_0_sc")
+ p.edAddChild(n1_0_sc)
+ n1_0_sc.setExecutionMode("remote")
+ n1_0_sc.setScript("""""")
+ i1_0_sc=n1_0_sc.edAddInputPort("i1",tp)
+ i1_0_sc.edInitPy(list(range(4)))
+
+ cont=p.createContainer("gg","Salome")
+ cont.setProperty("name","localhost")
+ cont.setProperty("hostname","localhost")
+ n1_0_sc.setContainer(cont)
+
+ p.saveSchema(fname)
+ l=loader.YACSLoader()
+ p=l.load(fname)
+ ex=pilot.ExecutorSwig()
+ self.assertEqual(p.getState(),pilot.READY)
+ ex.RunW(p,0)
+ self.assertEqual(p.getState(),pilot.DONE)
+ pass
+
+ def test27(self):
+ """
+ This test is here to check that old (<=930) graphs are always loadable.
+ So an xml file coming from test14 in 930 has been generated and converted into home made "base64" like format.
+ This test puts unbased64 byte array into test_930.xml and load it to check that everything is OK.
+ """
+ import os
+ content_of_file = b'DDkShXM2PeNCndPqRfnYX5EAt.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blED4u4BeuaT1nC9YuKRiNwAdkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wx0O49cNwDDG4HYu4bbkwx4u4BeuaT3.2=.Ewx.u4HcOqdWuaHblE=.E2D.u4HcOqdWuaHblE=.E2=.E2D0vqRjMadbkidgsiHAnohcOKRbEidgsiHAnoHetqR0uanWtAnDFWcbEidgsiHAnoHetqydNq9eNCRcMqDDEixbPq7eNwD0vq1jNC9bmKX1no9jMCxYsiT3.2=.E2=.EwPcMqfeNwDDN4JYuaNbkwVBf06c6eUhcmn17ER9euT1noxYNKHeNaT1noPcMqfeNwI.E2=1no1cNCVfOa9eNCT3.wx.tCxgNwI3'
+
+ fname=os.path.join(self.workdir, "test_930.xml")
+ with open(fname,"wb") as f:
+ f.write( pilot.FromBase64Swig(content_of_file) )
+
+ SALOMERuntime.RuntimeSALOME_setRuntime()
+ l=loader.YACSLoader()
+ p=l.load(fname)
+ self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").getChildByName("test23/run_internal").getInputPort("i1").getPyObj() == 3)
+ self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").edGetSeqOfSamplesPort().getPyObj()==list(range(10)))
+ os.remove(fname)
+ pass
+
+if __name__ == '__main__':
+ dir_test = tempfile.mkdtemp(suffix=".yacstest")
+ file_test = os.path.join(dir_test,"UnitTestsResult")
+ with open(file_test, 'a') as f:
+ f.write(" --- TEST src/yacsloader: testSaveLoadRun.py\n")
+ suite = unittest.makeSuite(TestSaveLoadRun)
+ result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+ sys.exit(not result.wasSuccessful())