From 348b0f7bffbe1f17f24140a36899cb96ffa44295 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Wed, 19 Jul 2023 13:45:50 +0200 Subject: [PATCH 1/1] [EDF28020] Fix nested foreach-switch. --- src/engine/Switch.cxx | 5 +- .../samples/foreach_switch_double.xml | 224 ++++++++++++++++++ src/yacsloader_swig/Test/CMakeLists.txt | 1 + .../Test/CTestTestfileInstall.cmake | 7 + src/yacsloader_swig/Test/testFixes.py | 81 +++++++ 5 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 src/yacsloader/samples/foreach_switch_double.xml create mode 100755 src/yacsloader_swig/Test/testFixes.py diff --git a/src/engine/Switch.cxx b/src/engine/Switch.cxx index 392b00909..1c7feff44 100644 --- a/src/engine/Switch.cxx +++ b/src/engine/Switch.cxx @@ -114,7 +114,10 @@ CollectorSwOutPort::CollectorSwOutPort(Switch *master, InPort *port):OutPort("", Port(master), _consumer(port),_currentProducer(0) { - _name="Representant_of_"; _name+=master->getName(); _name+="_for_inport_"; _name+=master->getRootNode()->getInPortName(_consumer); + _name="Representant_of_"; + _name+=master->getName(); + _name+="_for_inport_"; + _name+=port->getName(); } CollectorSwOutPort::CollectorSwOutPort(const CollectorSwOutPort& other, Switch *master):OutPort("",master,other.edGetType()), diff --git a/src/yacsloader/samples/foreach_switch_double.xml b/src/yacsloader/samples/foreach_switch_double.xml new file mode 100644 index 000000000..f0de89c72 --- /dev/null +++ b/src/yacsloader/samples/foreach_switch_double.xml @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition_5 Switch_6 + Switch_6 SwitchResults_9 + + Condition_5 r + Switch_6 select + + + Switch_6.p0_Switch_6_case_0.faux_8 r + SwitchResults_9 p0 + + + Switch_6.p1_Switch_6_case_1.vrai_7 r + SwitchResults_9 p0 + + + + + + + + + + iter2_4 output_iter2_4_10 + + iter2_4 evalSamples + iter2_4.block_iter2_4.Condition_5 c + + + iter2_4.block_iter2_4.SwitchResults_9 p0 + output_iter2_4_10 p0_0 + + + + + + + + + + + + + + + + + + + Condition_1 Switch_2 + Switch_2 SwitchResults_11 + + Condition_1 r + Switch_2 select + + + Switch_2.p0_Switch_2_case_0.output_iter2_4_10 p0_0 + SwitchResults_11 p0 + + + Switch_2.p1_Switch_2_case_1.vrai_3 r + SwitchResults_11 p0 + + + + + + + + + + + + + + + + iteration_0 output_iteration_0_12 + output_iteration_0_12 End + + iteration_0 evalSamples + iteration_0.block_iteration_0.Condition_1 c + + + output_iteration_0_12 p0_0 + End x + + + iteration_0.block_iteration_0.SwitchResults_11 p0 + output_iteration_0_12 p0_0 + + + iteration_0.block_iteration_0.Switch_2.p0_Switch_2_case_0.iter2_4.block_iter2_4.Condition_5c + + + + iteration_0.block_iteration_0.Condition_1c + + + + iteration_0SmplsCollection + +.G0dk.........1G.5F +.G0dk.........1GU5F + + + + iteration_0.block_iteration_0.Switch_2.p0_Switch_2_case_0.iter2_4SmplsCollection + +.G0dk.........1G.5F +.G0dk.........1GU5F + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/yacsloader_swig/Test/CMakeLists.txt b/src/yacsloader_swig/Test/CMakeLists.txt index f13da63f7..782303255 100644 --- a/src/yacsloader_swig/Test/CMakeLists.txt +++ b/src/yacsloader_swig/Test/CMakeLists.txt @@ -47,6 +47,7 @@ IF(NOT WIN32) async_plugin.py testWorkloadManager.py testPynodeWithCache.py + testFixes.py ) INSTALL(PROGRAMS ${LOCAL_TEST_FILES} DESTINATION ${LOCAL_TEST_DIR}) diff --git a/src/yacsloader_swig/Test/CTestTestfileInstall.cmake b/src/yacsloader_swig/Test/CTestTestfileInstall.cmake index 65202d3bc..af5f10f56 100644 --- a/src/yacsloader_swig/Test/CTestTestfileInstall.cmake +++ b/src/yacsloader_swig/Test/CTestTestfileInstall.cmake @@ -80,4 +80,11 @@ IF(NOT WIN32) ENVIRONMENT "SALOME_EMB_SERVANT=1" ) + SET(TEST_NAME ${COMPONENT_NAME}_Fixes_swig) + ADD_TEST(${TEST_NAME} testFixes.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + ENVIRONMENT "SALOME_EMB_SERVANT=1" + ) + ENDIF() diff --git a/src/yacsloader_swig/Test/testFixes.py b/src/yacsloader_swig/Test/testFixes.py new file mode 100755 index 000000000..b3ba77d60 --- /dev/null +++ b/src/yacsloader_swig/Test/testFixes.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# Copyright (C) 2006-2023 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +""" +Various non regression tests. +""" + +import sys +import pilot +import SALOMERuntime +import loader +import unittest +import tempfile +import os +import salome + +NB_NODE=15 +class TestEdit(unittest.TestCase): + + def setUp(self): + SALOMERuntime.RuntimeSALOME_setRuntime() + self.r = pilot.getRuntime() + self.l = loader.YACSLoader() + self.e = pilot.ExecutorSwig() + # We need a catalog which contains only one resource named "localhost" + # with NB_NODE cores. The modifications made here are not saved to the + # catalog file. + salome.salome_init() + resourceManager = salome.lcc.getResourcesManager() + resource_definition = resourceManager.GetResourceDefinition("localhost") + resource_definition.nb_node = NB_NODE + resource_definition.nb_proc_per_node = 1 + resourceManager.AddResource(resource_definition, False, "") + resource_required = salome.ResourceParameters() + resource_required.can_run_containers = True + res_list = resourceManager.GetFittingResources(resource_required) + for r in res_list: + if r != "localhost": + resourceManager.RemoveResource(r, False, "") + resource_definition = resourceManager.GetResourceDefinition("localhost") + self.assertEqual(resource_definition.nb_node, NB_NODE) + self.assertEqual(resource_definition.nb_proc_per_node, 1) + + def tearDown(self): + cm = salome.lcc.getContainerManager() + cm.ShutdownContainers() + + def test_double_foreach_switch(self): + """ Two layers of nested foreach and switch structures. + """ + proc = self.l.load("samples/foreach_switch_double.xml") + self.e.RunW(proc,0) + self.assertEqual(proc.getState(),pilot.DONE) + ok = proc.getChildByName("End").getOutputPort("ok") + self.assertTrue(ok, "Wrong result!") + +if __name__ == '__main__': + dir_test = tempfile.mkdtemp(suffix=".yacstest") + file_test = os.path.join(dir_test,"UnitTestsResult") + with open(file_test, 'a') as f: + f.write(" --- TEST src/yacsloader: testFixes.py\n") + suite = unittest.makeSuite(TestEdit) + result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite) + sys.exit(not result.wasSuccessful()) -- 2.30.2