1 # Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 from cStringIO import StringIO
27 import multiprocessing
30 class TestConcurrentLaunch(unittest.TestCase):
32 # Initialize path to SALOME application
33 path_to_launcher = os.getenv("SALOME_LAUNCHER")
34 appli_dir = os.path.dirname(path_to_launcher)
35 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
37 # Configure session startup
38 self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome"))
39 self.SALOME_appli_args = ["start", "-t"]
40 self.SALOME_shell_args = ["shell"]
45 def appli(self, args=None):
49 self.SALOME.main(self.SALOME_appli_args + args)
55 def session(self, args=None):
59 self.SALOME.main(self.SALOME_shell_args + args)
65 def test01_SingleSession(self):
66 print "** Testing single session **"
67 self.session(["hello.py"])
69 def test02_MultiSession(self):
70 print "** Testing multi sessions **"
73 p = multiprocessing.Process(target=self.session, args=(["hello.py"],))
80 def test03_SingleAppli(self):
81 print "** Testing single appli **"
82 current_directory = os.path.dirname(os.path.abspath(__file__))
83 session_log = tempfile.NamedTemporaryFile(prefix='session_', suffix='.log')
84 self.appli(["--ns-port-log=%s"%session_log.name])
86 with open(session_log.name, "r") as f:
87 port_number = f.readline()
88 self.session(["hello.py"])
89 self.session(["-p", port_number, "killSalomeWithPort.py", "args:%s"%port_number])
92 def test04_MultiAppli(self):
93 print "** Testing multi appli **"
96 p = multiprocessing.Process(target=self.test03_SingleAppli)
105 if __name__ == "__main__":
106 path_to_launcher = os.getenv("SALOME_LAUNCHER")
107 if not path_to_launcher:
109 msg += "Error: please set SALOME_LAUNCHER variable to the salome command in your application folder.\n"
113 if not os.path.isfile("hello.py"):
114 with open("hello.py", "w") as f:
115 f.write("print 'Hello!'")