import getpass
from datetime import date
-import salome
-
-
# Auxiliary variables
# Data directory
return cls._type2name[type]
-class SalomeSession(object):
- def __init__(self):
- import runSalome
- import sys
- if "INGUI" in sys.argv:
- sys.argv += ["--gui"]
- sys.argv += ["--show-desktop=1"]
- sys.argv += ["--splash=0"]
- #sys.argv += ["--standalone=study"]
- #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
- else:
- sys.argv += ["--terminal"]
- sys.argv += ["--modules=MED,PARAVIS"]
- clt, d = runSalome.main()
- port = d['port']
- self.port = port
- return
-
- #VTN: workaround for crash on CentOS.6.3.64
- #def __del__(self):
- #os.system('killSalomeWithPort.py {0}'.format(self.port))
- #os.system('killSalomeWithPort.py ' + self.port)
- #import killSalomeWithPort
- #killSalomeWithPort.killMyPort(self.port)
- #return
- pass
-
-
# Auxiliary functions
def test_values(value, et_value, check_error=0):
"""Test values."""
else:
for i in range(et_length):
if abs(et_value[i]) > 1:
- MAX = abs(eps*et_value[i])
+ MAX = abs(eps*et_value[i])
else:
MAX = eps
if abs(et_value[i] - value[i])> MAX:
iterations[field_short_name] = [entity, timestamp_nb]
return mesh_name, iterations
-
-
+
+
def Import_Med_Field(paravis, file, field_names, check_errors=0, prs=[]):
"""Builds presentations on the given fields of the MED file.
Originally defined in VISU_TEST/Grids/visu/ImportMedField/begin file.
-
+
Arguments:
- paravis : PARAVIS instance
+ paravis : PARAVIS instance
file_name : the full path to med file
field_names : the list of field names (for ex: ["pression","temperature","vitesse"])
prs : [[0,1,...], [], []]; empty list (sublist(s)) is ignored
9-VISU.TSCALARMAPONDEFORMEDSHAPE
"""
import presentations
-
+
nb_errors = 0
-
+
print "File: ", file
-
+
# check the file accessibility
if not os.access(file, os.F_OK):
msg = "File " + file + " does not exist!!!"
paravis.ImportFile(file)
proxy = presentations.pvs.GetActiveSource()
if proxy is None:
- raise RuntimeError, "ERROR!!! Can't import file!!!"
-
+ raise RuntimeError, "ERROR!!! Can't import file!!!"
+
for i in range(len(field_names)):
print "Name of the field: ", field_names[i]
-
- if len(prs) != 0:
- if len(prs[i]) != 0:
- mesh_name, iterations = TimeStampId(proxy)
-
- if iterations.has_key(field_names[i]):
- entity = iterations[field_names[i]][0]
- iteration = iterations[field_names[i]][1]
- else:
- msg="There is no information about TimeStampId of the " + field_names[i] + " field!!!"
- raise RuntimeError, msg
-
- err = nb_errors
-
- for type in prs[i]:
- if type==0:
- if presentations.GaussPointsOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created GaussPoints presentation is None!!!"; nb_errors+=1
- if type==1:
- if presentations.ScalarMapOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created ScalarMap presentation is None!!!"; nb_errors+=1
- if type==2:
- if presentations.IsoSurfacesOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created IsoSurfaces presentation is None!!!"; nb_errors+=1
- if type==3:
- if presentations.CutPlanesOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created CutPlanes presentation is None!!!"; nb_errors+=1
- if type==4:
- if presentations.CutLinesOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created CutLines presentation is None!!!"; nb_errors+=1
- if type==5:
- if presentations.DeformedShapeOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created DeformedShape presentation is None!!!"; nb_errors+=1
- if type==6:
- if presentations.VectorsOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created Vectors presentation is None!!!"; nb_errors+=1
- if type==7:
- if presentations.StreamLinesOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created StreamLines presentation is None!!!"; nb_errors+=1
- if type==8:
- if presentations.Plot3DOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created Plot3D presentation is None!!!"; nb_errors+=1
- if type==9:
- if presentations.DeformedShapeAndScalarMapOnField(proxy, entity, field_names[i], iteration) is None:
- print "ERROR!!! Created ScalarMapOnDeformedShape presentation is None!!!"; nb_errors+=1
-
+
+ if len(prs) != 0:
+ if len(prs[i]) != 0:
+ mesh_name, iterations = TimeStampId(proxy)
+
+ if iterations.has_key(field_names[i]):
+ entity = iterations[field_names[i]][0]
+ iteration = iterations[field_names[i]][1]
+ else:
+ msg="There is no information about TimeStampId of the " + field_names[i] + " field!!!"
+ raise RuntimeError, msg
+
+ err = nb_errors
+
+ for type in prs[i]:
+ if type==0:
+ if presentations.GaussPointsOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created GaussPoints presentation is None!!!"; nb_errors+=1
+ if type==1:
+ if presentations.ScalarMapOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created ScalarMap presentation is None!!!"; nb_errors+=1
+ if type==2:
+ if presentations.IsoSurfacesOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created IsoSurfaces presentation is None!!!"; nb_errors+=1
+ if type==3:
+ if presentations.CutPlanesOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created CutPlanes presentation is None!!!"; nb_errors+=1
+ if type==4:
+ if presentations.CutLinesOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created CutLines presentation is None!!!"; nb_errors+=1
+ if type==5:
+ if presentations.DeformedShapeOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created DeformedShape presentation is None!!!"; nb_errors+=1
+ if type==6:
+ if presentations.VectorsOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created Vectors presentation is None!!!"; nb_errors+=1
+ if type==7:
+ if presentations.StreamLinesOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created StreamLines presentation is None!!!"; nb_errors+=1
+ if type==8:
+ if presentations.Plot3DOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created Plot3D presentation is None!!!"; nb_errors+=1
+ if type==9:
+ if presentations.DeformedShapeAndScalarMapOnField(proxy, entity, field_names[i], iteration) is None:
+ print "ERROR!!! Created ScalarMapOnDeformedShape presentation is None!!!"; nb_errors+=1
+
# check if number of errors has increased
if err == nb_errors:
print "Presentation(s) creation...OK"
def delete_with_inputs(obj):
"""Deletes the given object with all its inputs"""
import pvsimple
-
+
obj_to_delete = obj
while obj_to_delete is not None:
tmp_obj = obj_to_delete
obj_to_delete = None
if hasattr(tmp_obj, 'Input'):
obj_to_delete = tmp_obj.Input
-
- pvsimple.Delete(tmp_obj)
-
-# Run Salome
-salome_session = SalomeSession()
-salome.salome_init()
-session_server = salome.naming_service.Resolve('/Kernel/Session')
-if session_server:
- session_server.emitMessage("connect_to_study")
- session_server.emitMessage("activate_viewer/ParaView")
- pass
+ pvsimple.Delete(tmp_obj)
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-import searchFreePort
import subprocess
import sys, os
import signal
## <<< TEMP ###
-args = {}
-searchFreePort.searchFreePort(args)
-port = args['port']
-try:
- import PortManager
- PortManager.releasePort(os.environ['NSPORT'])
-except ImportError:
+class SalomeSession(object):
+ def __init__(self, args=[]):
+ sys.argv = ['runSalome'] + args
+
+ if "INGUI" in args:
+ sys.argv += ["--gui"]
+ sys.argv += ["--show-desktop=1"]
+ sys.argv += ["--splash=0"]
+ #sys.argv += ["--standalone=study"]
+ #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
+ else:
+ sys.argv += ["--terminal"]
+ sys.argv += ["--modules=MED,PARAVIS,GUI"]
+
+ import setenv
+ setenv.main(True)
+
+ import runSalome
+ runSalome.runSalome()
pass
+#
+
+port = 0
+
+def run_test(command):
+ # Run SALOME
+ import tempfile
+ log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False)
+ log.close()
+ import salome
+ salome_session = SalomeSession(args=["--ns-port-log=%s"%log.name])
+ salome.salome_init()
+ session_server = salome.naming_service.Resolve('/Kernel/Session')
+ if session_server:
+ session_server.emitMessage("connect_to_study")
+ session_server.emitMessage("activate_viewer/ParaView")
+ pass
+
+ global port
+ with open(log.name) as f:
+ port = int(f.readline())
+
+ # Run test
+ #res = subprocess.check_call(command)
+ p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ _out, _err = p.communicate()
+ res = p.returncode
+
+ # Exit SALOME
+ killSalomeWithPort.killMyPort(port)
+ os.remove(log.name)
+
+ # :TRICKY: Special case of returncode=127
+ # When using paraview in SALOME environment, the following error
+ # systematicallty appears when exiting paraview (it's also true when using
+ # PARAVIS and exiting SALOME):
+ # Inconsistency detected by ld.so: dl-close.c: 738: _dl_close: Assertion `map->l_init_called' failed!
+ # For PARAVIS tests purpose, paraview functionalities are accessed in each
+ # test; these tests are run in the above subprocess call.
+ # The assertion error implies a subprocess return code of 127, and the test
+ # status is considered as "failed".
+ # The tricky part here is to discard such return codes, waiting for a fix
+ # maybe in paraview...
+ if res == 127 and _err.startswith("Inconsistency detected by ld.so: dl-close.c"):
+ print " ** THE FOLLOWING MESSAGE IS NOT CONSIDERED WHEN ANALYZING TEST SUCCESSFULNESS **"
+ print _err
+ print " ** end of message **"
+ res = 0;
+ elif _err:
+ print " ** Detected error **"
+ print "Error code: ", res
+ print _err
+ print " ** end of message **"
+ pass
+
+ return res
+#
def timeout_handler(signum, frame):
print "FAILED : timeout(" + sys.argv[1] + ") is reached"
killSalomeWithPort.killMyPort(port)
exit(1)
-
+#
signal.alarm(abs(int(sys.argv[1])-10))
signal.signal(signal.SIGALRM, timeout_handler)
res = 1
try:
- res = subprocess.check_call([sys.executable]+sys.argv[2:])
+ res = run_test([sys.executable]+sys.argv[2:])
except:
+ #import traceback
+ #traceback.print_exc()
pass
-killSalomeWithPort.killMyPort(port)
-
exit(res)