From: rnv Date: Wed, 30 Dec 2020 01:45:30 +0000 (+0300) Subject: Final fix for #19007 [CEA][Windows] SALOME non regression tests on Windows X-Git-Tag: V9_7_0a1~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=07a2f4b4bc26848b3258984a221f0cb2e4572f3a;p=modules%2Fkernel.git Final fix for #19007 [CEA][Windows] SALOME non regression tests on Windows --- diff --git a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py b/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py index cda759280..039b52162 100755 --- a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py +++ b/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py @@ -35,71 +35,76 @@ def new_instance(running_instances): running_instances.put(instance) # +def createInstances(nb): + running_instances = multiprocessing.Queue() + processes = [ + multiprocessing.Process(target=new_instance, args=(running_instances,)) + for i in range(nb) + ] + return running_instances, processes +# + +def terminateInstances(running_instances): + import time + timeout = time.time() + 60 * 10 # the test duration is about 50 s, we reasonably assume a max duration of 10mn + + while not running_instances.empty() and time.time() < timeout: + instance = running_instances.get() + print("Terminate instance running on port", instance.get_port()) + instance.stop() +# + +def session(args=None): + if args is None: + args = [] + try: + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) + except SystemExit as e: + if str(e) != '0': + logging.error(e) + pass +# + +def appli(args=None): + if args is None: + args = [] + try: + sys.argv = ['runSalome', '-t'] + import setenv + setenv.main(True, exeName="salome start") + import runSalome + runSalome.runSalome() + except SystemExit as e: + if str(e) != '0': + logging.error(e) + pass +# + class TestConcurrentLaunch(unittest.TestCase): - def __createInstances(self, nb): - running_instances = multiprocessing.Queue() - processes = [ - multiprocessing.Process(target=new_instance, args=(running_instances,)) - for i in range(nb) - ] - return running_instances, processes - # - def __terminateInstances(self, running_instances): - import time - timeout = time.time() + 60*10 # the test duration is about 50 s, we reasonably assume a max duration of 10mn - - while not running_instances.empty() and time.time() < timeout: - instance = running_instances.get() - print("Terminate instance running on port", instance.get_port()) - instance.stop() - # - def appli(self, args=None): - if args is None: - args = [] - try: - sys.argv = ['runSalome', '-t'] - import setenv - setenv.main(True, exeName="salome start") - import runSalome - runSalome.runSalome() - except SystemExit as e: - if str(e) != '0': - logging.error(e) - pass - # - def session(self, args=None): - if args is None: - args = [] - try: - import setenv - setenv.main(True) - import runSession - params, args = runSession.configureSession(args, exe="salome shell") - return runSession.runSession(params, args) - except SystemExit as e: - if str(e) != '0': - logging.error(e) - pass - # def test01_SingleSession(self): print("** Testing single session **") - self.session(["hello.py"]) - # + session(["hello.py"]) + def test02_MultiSession(self): print("** Testing multi sessions **") jobs = [] for i in range(9): - p = multiprocessing.Process(target=self.session, args=(["hello.py"],)) + p = multiprocessing.Process(target=session, args=(["hello.py"],)) jobs.append(p) p.start() for j in jobs: j.join() # + def test03_SingleAppli(self): print("** Testing single appli **") - running_instances, processes = self.__createInstances(1) + running_instances, processes = createInstances(1) for p in processes: p.start() pass @@ -107,12 +112,13 @@ class TestConcurrentLaunch(unittest.TestCase): p.join() pass - self.session(["hello.py"]) - self.__terminateInstances(running_instances) + session(["hello.py"]) + terminateInstances(running_instances) # + def test04_MultiAppli(self): print("** Testing multi appli **") - running_instances, processes = self.__createInstances(9) + running_instances, processes = createInstances(9) for p in processes: p.start() pass @@ -120,8 +126,8 @@ class TestConcurrentLaunch(unittest.TestCase): p.join() pass - self.session(["hello.py"]) - self.__terminateInstances(running_instances) + session(["hello.py"]) + terminateInstances(running_instances) # # diff --git a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py index ab9d44ccf..03309ed01 100755 --- a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py +++ b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py @@ -24,7 +24,8 @@ import multiprocessing import unittest import logging -def port_reservation(obtained_ports, preferred=None, test=None, expected=None): + +def port_reservation(obtained_ports, preferred=None, name = None, messages=None, expected=None): from PortManager import getPort if preferred: port = getPort(preferred) @@ -34,16 +35,23 @@ def port_reservation(obtained_ports, preferred=None, test=None, expected=None): obtained_ports.put(port) - if expected: - test.assertTrue(port == expected, "used = %s, expected = %s"%(port, expected)) + if expected and messages: + _name = name + " : " if name else "" + if port != expected: + messages.put(_name + "used port= %s, expected port = %s"%(port, expected)) + else: + messages.put(_name + "OK") # + class TestMinimalExample(unittest.TestCase): + def testSequential(self): from PortManager import releasePort, getBusyPorts print("\nBEGIN testSequential") print("Busy ports", getBusyPorts()) obtained_ports = multiprocessing.Queue() + messages = multiprocessing.Queue() processes = [ multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) @@ -58,17 +66,19 @@ class TestMinimalExample(unittest.TestCase): print("Busy ports", getBusyPorts()) # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, "testSequential 2872", + messages, 2872,)) p.start() p.join() # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812, self,)) + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,)) p.start() p.join() # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, "testSequential 2899:1", + messages, 2899,)) p.start() p.join() @@ -79,10 +89,17 @@ class TestMinimalExample(unittest.TestCase): p.join() # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, "testSequential 2899:2", + messages, 2899,)) p.start() p.join() + # Check results + while not messages.empty(): + message = messages.get() + if "OK" not in message: + self.fail(message) + # Release ports print("Busy ports", getBusyPorts()) while not obtained_ports.empty(): @@ -100,6 +117,7 @@ class TestMinimalExample(unittest.TestCase): print("\nBEGIN testConcurrent") print("Busy ports", getBusyPorts()) obtained_ports = multiprocessing.Queue() + messages = multiprocessing.Queue() processes = [ multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) @@ -107,7 +125,8 @@ class TestMinimalExample(unittest.TestCase): ] # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, "testSequential 2872", + messages, 2872,)) processes.append(p) # Try to get specific port number @@ -124,6 +143,12 @@ class TestMinimalExample(unittest.TestCase): for p in processes: p.join() + # Check results + while not messages.empty(): + message = messages.get() + if "OK" not in message: + self.fail(message) + # Release ports print("Busy ports", getBusyPorts()) while not obtained_ports.empty(): diff --git a/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake index 80bca2c9b..8b468ea23 100644 --- a/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake @@ -19,18 +19,26 @@ SET(tname salome_test) -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash) -ADD_TEST(${TEST_NAME} bash ${tname}.sh) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) +IF (WIN32) + SET(PY_EXEC $ENV{PYTHONBIN}) +ELSE() + SET(PY_EXEC python) +ENDIF() -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell) -ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) +IF(NOT WIN32) + SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash) + ADD_TEST(${TEST_NAME} bash ${tname}.sh) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) + + SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell) + ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) +ENDIF() SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_py) -ADD_TEST(${TEST_NAME} python ${tname}.py) +ADD_TEST(${TEST_NAME} ${PY_EXEC} ${tname}.py) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_driver) -ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py) +ADD_TEST(${TEST_NAME} ${PY_EXEC} ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)