-# Copyright (C) 2006-2015 CEA/DEN, EDF R&D
+# Copyright (C) 2006-2019 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
ref=datetime.datetime.now()
t=0. ; pas=1./float(nb)
- for i in xrange(nb):
- for j in xrange(nb):
+ for i in range(nb):
+ for j in range(nb):
x=j*pas
t+=1.+cos(1.*(x*3.14159))
pass
pass
- print "coucou from script0-%i -> %s"%(dbg,str(datetime.datetime.now()-ref))
+ print("coucou from script0-%i -> %s"%(dbg,str(datetime.datetime.now()-ref)))
return t
"""
script1="""
import datetime
ref=datetime.datetime.now()
o2=0. ; pas=1./float(i1)
-for i in xrange(i1):
- for j in xrange(i1):
+for i in range(i1):
+ for j in range(i1):
x=j*pas
o2+=1.+cos(1.*(x*3.14159))
pass
-print "coucou from script1-%i -> %s"%(dbg,str(datetime.datetime.now()-ref))
+print("coucou from script1-%i -> %s"%(dbg,str(datetime.datetime.now()-ref)))
"""
- for i in xrange(nbOfNodes):
+ for i in range(nbOfNodes):
node0=self.r.createFuncNode("DistPython","node%i"%(i))
p.edAddChild(node0)
node0.setFname("ff")
st=datetime.datetime.now()
# 1st exec
ex.RunW(p,0)
- print "Time spend of test0 to run 1st %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test0 to run 1st %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
# 2nd exec using the same already launched remote python interpreters
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test0 to run 2nd %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test0 to run 2nd %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
# 3rd exec using the same already launched remote python interpreters
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test0 to run 3rd %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test0 to run 3rd %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
pass
ref=datetime.datetime.now()
t=0. ; pas=1./float(nb)
- for i in xrange(nb):
- for j in xrange(nb):
+ for i in range(nb):
+ for j in range(nb):
x=j*pas
t+=1.+cos(1.*(x*3.14159))
pass
pass
- print "coucou from script0-%i -> %s"%(dbg,str(datetime.datetime.now()-ref))
+ print("coucou from script0-%i -> %s"%(dbg,str(datetime.datetime.now()-ref)))
return t
"""
# here in script1 aa is refered ! aa will exist thanks to HPCont Init Script
import datetime
ref=datetime.datetime.now()
o2=0. ; pas=1./float(i1)
-for i in xrange(i1):
- for j in xrange(i1):
+for i in range(i1):
+ for j in range(i1):
x=j*pas
o2+=1.+cos(1.*(x*3.14159))
pass
-print "coucou %lf from script1-%i -> %s"%(aa,dbg,str(datetime.datetime.now()-ref))
+print("coucou %lf from script1-%i -> %s"%(aa,dbg,str(datetime.datetime.now()-ref)))
aa+=1.
"""
#
- for i in xrange(nbOfNodes):
+ for i in range(nbOfNodes):
nodeMiddle=self.r.createFuncNode("Salome","node%i_1"%(i)) # PyFuncNode remote
p.edAddChild(nodeMiddle)
nodeMiddle.setFname("ff")
self.assertEqual(p.getState(),pilot.READY)
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test1 to 1st run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test1 to 1st run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
# 2nd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test1 to 2nd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test1 to 2nd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
# 3rd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test1 to 3rd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test1 to 3rd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
pass
""" Test on HP Containers in foreach context."""
script0="""def ff():
global aa
- print "%%lf - %%s"%%(aa,str(my_container))
+ print("%%lf - %%s"%%(aa,str(my_container)))
return 16*[%i],0
"""
script1="""from math import cos
import datetime
ref=datetime.datetime.now()
o2=0. ; pas=1./float(i1)
-for i in xrange(i1):
- for j in xrange(i1):
+for i in range(i1):
+ for j in range(i1):
x=j*pas
o2+=1.+cos(1.*(x*3.14159))
pass
-print "coucou %lf from script -> %s"%(aa,str(datetime.datetime.now()-ref))
+print("coucou %lf from script -> %s"%(aa,str(datetime.datetime.now()-ref)))
aa+=1.
o3=0
"""
self.assertEqual(p.getState(),pilot.READY)
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test2 to 1st run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test2 to 1st run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
# 2nd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test2 to 2nd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test2 to 2nd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
# 3rd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test2 to 3rd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test2 to 3rd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
pass
""" Test that focuses on parallel load of containers."""
script0="""def ff():
global aa
- print "%%lf - %%s"%%(aa,str(my_container))
+ print("%%lf - %%s"%%(aa,str(my_container)))
return 100*[%i],0
"""
script1="""from math import cos
import datetime
ref=datetime.datetime.now()
o2=0. ; pas=1./float(i1)
-for i in xrange(i1):
- for j in xrange(i1):
+for i in range(i1):
+ for j in range(i1):
x=j*pas
o2+=1.+cos(1.*(x*3.14159))
pass
-print "coucou %lf from script -> %s"%(aa,str(datetime.datetime.now()-ref))
+print("coucou %lf from script -> %s"%(aa,str(datetime.datetime.now()-ref)))
aa+=1.
o3=0
"""
self.assertEqual(p.getState(),pilot.READY)
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test3 to 1st run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test3 to 1st run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
# 2nd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test3 to 2nd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test3 to 2nd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
# 3rd exec
st=datetime.datetime.now()
ex.RunW(p,0)
- print "Time spend of test3 to 3rd run %s"%(str(datetime.datetime.now()-st))
+ print("Time spend of test3 to 3rd run %s"%(str(datetime.datetime.now()-st)))
self.assertEqual(p.getState(),pilot.DONE)
self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
pass
script1="""nb=7
ii=0
o1=nb*[None]
-for i in xrange(nb):
+for i in range(nb):
tmp=(i+10)*[None]
- for j in xrange(i+10):
+ for j in range(i+10):
tmp[j]=ii
ii+=1
pass
node2000.setScript("o6=2+i5")
p.edAddLink(node200.edGetSamplePort(),i5)
#
- node3=self.r.createForEachLoop("node3",td)
+ node3=self.r.createForEachLoop("node3",td2)
p.edAddChild(node3)
p.edAddCFLink(node2,node3)
p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
script1="""nb=7
ii=0
o1=nb*[None]
-for i in xrange(nb):
+for i in range(nb):
tmp=(i+10)*[None]
- for j in xrange(i+10):
+ for j in range(i+10):
tmp[j]=ii
ii+=1
pass
node2000.setScript("def ff(x):\n return 2+x")
p.edAddLink(node200.edGetSamplePort(),i5)
#
- node3=self.r.createForEachLoop("node3",td)
+ node3=self.r.createForEachLoop("node3",td2)
p.edAddChild(node3)
p.edAddCFLink(node2,node3)
p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
self.assertEqual(n1.getState(),pilot.DONE)
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
- self.assertEqual(a,range(6))
- self.assertEqual([elt.getPyObj() for elt in b],[[6L, 12L, 16L, 18L, -4L, 10L]])
+ self.assertEqual(a,list(range(6)))
+ self.assertEqual([elt.getPyObj() for elt in b],[[6, 12, 16, 18, -4, 10]])
self.assertEqual(c,['n10_o2_interceptor'])
pass
self.assertEqual(n1.getState(),pilot.FAILED)
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
- self.assertEqual(a,range(3))
- self.assertEqual([elt.getPyObj() for elt in b],[[6L,12L,16L]])
+ self.assertEqual(a,list(range(3)))
+ self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16]])
self.assertEqual(c,['n10_o2_interceptor'])
pass
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
self.assertEqual(a,[0,1,2,4,5])
- self.assertEqual([elt.getPyObj() for elt in b],[[6L,12L,16L,-4L,10L]])
+ self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
self.assertEqual(c,['n10_o2_interceptor'])
p.getChildByName("n1").getChildByName("n10").setScript("""
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
self.assertEqual(a,[1,2,3,4,5])
- self.assertEqual([elt.getPyObj() for elt in b],[[12L,16L,18L,-4L,10L]])
+ self.assertEqual([elt.getPyObj() for elt in b],[[12,16,18,-4,10]])
self.assertEqual(c,['n10_o2_interceptor'])
pass
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
self.assertEqual(a,[0,1,2,4,5])
- self.assertEqual([elt.getPyObj() for elt in b],[[6L,12L,16L,-4L,10L]])
+ self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
self.assertEqual(c,['n10_o2_interceptor'])
p.getChildByName("n1").getChildByName("n10").setScript("""
#
self.assertEqual(n1.getState(),pilot.DONE)
self.assertEqual(p.getState(),pilot.DONE)
- self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[6L,12L,16L,63L,-4L,10L])
+ self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[6,12,16,63,-4,10])
pass
def test10(self):
n1.edGetSeqOfSamplesPort().getPyObj()
a,b,c=n1.getPassedResults(ex)
self.assertEqual(a,[1,3,5,7,9,11])
- self.assertEqual([elt.getPyObj() for elt in b],[[12L,36L,60L,84L,108L,132L]])
+ self.assertEqual([elt.getPyObj() for elt in b],[[12,36,60,84,108,132]])
self.assertEqual(c,['n10_o2_interceptor'])
p.getChildByName("n1").getChildByName("n10").setScript("""
#
self.assertEqual(n1.getState(),pilot.DONE)
self.assertEqual(p.getState(),pilot.DONE)
- self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0L,12L,30L,36L,60L,60L,90L,84L,120L,108L,150L,132L])
+ self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,12,30,36,60,60,90,84,120,108,150,132])
pass
pass
a,b,c=n1.getPassedResults(ex)
self.assertEqual(a,[0,2,4,6,8,10])
- self.assertEqual([elt.getPyObj() for elt in b],[[0L,4L,8L,12L,16L,20L]])
+ 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("""
#
self.assertEqual(n1.getState(),pilot.DONE)
self.assertEqual(p.getState(),pilot.DONE)
- self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0L,5L,4L,15L,8L,25L,12L,35L,16L,45L,20L,55L])
+ self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,5,4,15,8,25,12,35,16,45,20,55])
pass
def test12(self):
#
node0=self.r.createForEachLoop("ForEachLoop_int0",ti)
p.edAddChild(node0)
- node0.edGetSeqOfSamplesPort().edInitPy(range(4))
+ 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(range(4))
+ node000_0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
node000_0.edGetNbOfBranchesPort().edInitInt(3)
#
node0000=self.r.createBloc("Bloc1")
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.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)
#
n00.edAddLink(n000.edGetSamplePort(),i0)
#
- n000.edGetSeqOfSamplesPort().edInitPy(range(10))
+ n000.edGetSeqOfSamplesPort().edInitPy(list(range(10)))
n000.edGetNbOfBranchesPort().edInitInt(2)
#
n01=r.createScriptNode("Salome","test23/check") ; n0bis.edAddChild(n01)
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):
+ fname="BugInConcurrentLaunchDftCont.xml"
+ p=self.r.createProc("pr")
+ ti=p.createType("int","int")
+ cont=p.createContainer("DefaultContainer","Salome")
+ 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(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="test19.xml"
+ l=loader.YACSLoader()
+ #
+ p=self.r.createProc("PROC")
+ 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=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=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","HPSalome")
+ cont.setSizeOfPool(2)
+ 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")
+ #
+ cont=p.createContainer("gg","HPSalome") # very important ! HP Container needed for the test !
+ cont.setSizeOfPool(8) # important make this figure >= 6
+ #
+ 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=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)
+ #
+ #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="test21.xml"
+ xmlStateFileName="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(2)
+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(5)
+ 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();
+ #
+ 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,2,10,15,20,25])
+ pass
+ pass
+
+ def test22(self):
+ """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.
+ """
+ fname="test21.xml"
+ xmlStateFileName="saveState21.xml"
+
+ 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="test23.xml"
+ xmlStateFileName="saveState23.xml"
+ from datetime import datetime
+ 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)
+ #
+ 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)
+ #
+ 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="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
+
if __name__ == '__main__':
import os,sys
U = os.getenv('USER')
- f=open("/tmp/" + U + "/UnitTestsResult", 'a')
- f.write(" --- TEST src/yacsloader: testSaveLoadRun.py\n")
- suite = unittest.makeSuite(TestSaveLoadRun)
- result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
- f.close()
+ with open("/tmp/" + U + "/UnitTestsResult", '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())