2 # Copyright (C) 2006-2020 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
31 class TestEdit(unittest.TestCase):
34 SALOMERuntime.RuntimeSALOME_setRuntime()
35 self.r = pilot.getRuntime()
36 self.l = loader.YACSLoader()
37 self.e = pilot.ExecutorSwig()
38 # We need a catalog which contains only one resource named "localhost"
39 # with 16 cores. The modifications made here are not saved to the
42 resourceManager = salome.lcc.getResourcesManager()
43 resource_definition = resourceManager.GetResourceDefinition("localhost")
44 resource_definition.nb_node = NB_NODE
45 resourceManager.AddResource(resource_definition, False, "")
46 resource_required = salome.ResourceParameters()
47 resource_required.can_run_containers = True
48 res_list = resourceManager.GetFittingResources(resource_required)
51 resourceManager.RemoveResource(r, False, "")
52 resource_definition = resourceManager.GetResourceDefinition("localhost")
53 self.assertEqual(resource_definition.nb_node, NB_NODE)
56 cm = salome.lcc.getContainerManager()
57 cm.ShutdownContainers()
60 """ Two parallel foreach-s with different containers
62 proc = self.l.load("samples/wlm_2foreach.xml")
64 self.assertEqual(proc.getState(),pilot.DONE)
65 res_port = proc.getChildByName("End").getOutputPort("r")
66 # theoretical time should be 15s
67 execution_time = res_port.getPyObj()
68 # lower time means some resources are overloaded
69 msg = "Execution time is too short : {}s".format(execution_time)
70 self.assertTrue(execution_time > 13, msg)
71 # The containers may need some time to be launched.
72 # We need some delay to add to the 15s.
73 msg = "Execution time is too long : {}s".format(execution_time)
74 self.assertTrue(execution_time < 25, msg)
77 """ Two parallel foreach-s with different containers and python nodes
80 proc = self.l.load("samples/wlm_2foreach_with_cache.xml")
82 self.assertEqual(proc.getState(),pilot.DONE)
83 ok = proc.getChildByName("End").getOutputPort("ok")
85 total_time = proc.getChildByName("End").getOutputPort("total_time")
86 # theoretical time should be 16s
87 execution_time = total_time.getPyObj()
88 # lower time means some resources are overloaded
89 msg = "Execution time is too short : {}s".format(execution_time)
90 self.assertTrue(execution_time > 14, msg)
91 # The containers may need some time to be launched.
92 # We need some delay to add to the 16s.
93 msg = "Execution time is too long : {}s".format(execution_time)
94 self.assertTrue(execution_time < 26, msg)
95 coeff_cont = proc.getChildByName("End").getOutputPort("coeff_cont").getPyObj()
96 msg = "coeff_cont too low:"+str(coeff_cont)
97 self.assertTrue(coeff_cont >= NB_NODE, msg)
98 msg = "coeff_cont too high:"+str(coeff_cont)
99 self.assertTrue(coeff_cont <= 2*NB_NODE, msg)
102 """ Launch 8 independent nodes in parallel.
104 proc = self.l.load("samples/wlm_8nodes.xml")
106 self.assertEqual(proc.getState(),pilot.DONE)
107 ok = proc.getChildByName("End").getOutputPort("ok")
109 err_message = proc.getChildByName("End").getOutputPort("err_message").getPyObj()
110 self.fail(err_message)
113 """ Verify the execution is stoped if no resource can run a task.
115 proc = self.l.load("samples/wlm_error.xml")
117 self.assertEqual(proc.getState(),pilot.FAILED)
118 self.assertEqual(proc.getChildByName("ErrorNode").getState(),pilot.ERROR)
120 if __name__ == '__main__':
121 dir_test = tempfile.mkdtemp(suffix=".yacstest")
122 file_test = os.path.join(dir_test,"UnitTestsResult")
123 with open(file_test, 'a') as f:
124 f.write(" --- TEST src/yacsloader: testWorkloadManager.py\n")
125 suite = unittest.makeSuite(TestEdit)
126 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
127 sys.exit(not result.wasSuccessful())