]> SALOME platform Git repositories - modules/paravis.git/blob - test/VisuPrs/Util/paravistesthelper.py
Salome HOME
some fixes in tests
[modules/paravis.git] / test / VisuPrs / Util / paravistesthelper.py
1 # Copyright (C) 2013-2015  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import subprocess
21 import sys, os
22 import signal
23 import killSalomeWithPort
24
25 ## TEMP >>> ###
26 if not os.getenv("OMNIORB_USER_PATH"):
27     os.environ["OMNIORB_USER_PATH"] = os.path.realpath(os.path.expanduser('~'))
28     pass
29 ## <<< TEMP ###
30
31
32 class SalomeSession(object):
33     def __init__(self, args=[]):
34         sys.argv = ['runSalome'] + args
35
36         if "INGUI" in args:
37             sys.argv += ["--gui"]
38             sys.argv += ["--show-desktop=1"]
39             sys.argv += ["--splash=0"]
40             #sys.argv += ["--standalone=study"]
41             #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
42         else:
43             sys.argv += ["--terminal"]
44         sys.argv += ["--modules=MED,PARAVIS,GUI"]
45
46         import setenv
47         setenv.main(True)
48
49         import runSalome
50         runSalome.runSalome()
51     pass
52 #
53
54 port = 0
55
56 def run_test(command):
57   # Run SALOME
58   import tempfile
59   log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False)
60   log.close()
61   import salome
62   salome_session = SalomeSession(args=["--ns-port-log=%s"%log.name])
63   salome.salome_init()
64   session_server = salome.naming_service.Resolve('/Kernel/Session')
65   if session_server:
66       session_server.emitMessage("connect_to_study")
67       session_server.emitMessage("activate_viewer/ParaView")
68       pass
69
70   global port
71   with open(log.name) as f:
72       port = int(f.readline())
73
74   # Run test
75   #res = subprocess.check_call(command)
76   p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
77   _out, _err = p.communicate()
78   res = p.returncode
79
80   # Exit SALOME
81   killSalomeWithPort.killMyPort(port)
82   os.remove(log.name)
83
84   # :TRICKY: Special case of returncode=127
85   # When using paraview in SALOME environment, the following error
86   # systematically appears when exiting paraview (it's also true when using
87   # PARAVIS and exiting SALOME):
88   # Inconsistency detected by ld.so: dl-close.c: 738: _dl_close: Assertion `map->l_init_called' failed!
89   # For PARAVIS tests purpose, paraview functionalities are accessed in each
90   # test; these tests are run in the above subprocess call.
91   # The assertion error implies a subprocess return code of 127, and the test
92   # status is considered as "failed".
93   # The tricky part here is to discard such return codes, waiting for a fix
94   # maybe in paraview...
95   print "#############################"
96   print res
97   print _err
98   print "#############################"
99   if res == 127 and _err.startswith("Inconsistency detected by ld.so: dl-close.c"):
100       print "    ** THE FOLLOWING MESSAGE IS DISCARDED WHEN ANALYZING TEST SUCCESSFULNESS **"
101       print _err
102       print "    ** end of message **"
103       res = 0;
104   elif _err:
105       print "    ** Detected error **"
106       print "Error code: ", res
107       print _err
108       print "    ** end of message **"
109       pass
110
111   if _out:
112       print _out
113   return res
114 #
115
116 def timeout_handler(signum, frame):
117     print "FAILED : timeout(" + sys.argv[1] + ") is reached"
118     killSalomeWithPort.killMyPort(port)
119     exit(1)
120 #
121 signal.alarm(abs(int(sys.argv[1])-10))
122 signal.signal(signal.SIGALRM, timeout_handler)
123
124 res = 1
125 try:
126     res = run_test([sys.executable]+sys.argv[2:])
127 except:
128     #import traceback
129     #traceback.print_exc()
130     pass
131
132 exit(res)