From 75fa75d766b594b97837781018318bb2c79a55dd Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Tue, 2 Jun 2020 18:27:10 +0200 Subject: [PATCH] Test for python node with cache. --- src/engine/Executor.cxx | 17 +++- src/engine/Executor.hxx | 2 +- src/yacsloader_swig/Test/CMakeLists.txt | 1 + .../Test/CTestTestfileInstall.cmake | 6 ++ src/yacsloader_swig/Test/runUnitTest.sh | 8 +- .../Test/testWorkloadManager.py | 86 +++++++++++++++++++ 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100755 src/yacsloader_swig/Test/testWorkloadManager.py diff --git a/src/engine/Executor.cxx b/src/engine/Executor.cxx index 8af044080..c46ebf2e8 100644 --- a/src/engine/Executor.cxx +++ b/src/engine/Executor.cxx @@ -1691,6 +1691,7 @@ public: NewTask(Executor& executor, YACS::ENGINE::Task* yacsTask); const WorkloadManager::ContainerType& type()const override; void run(const WorkloadManager::RunInfo& runInfo)override; + bool isAccepted(const WorkloadManager::Resource& r)override; private: WorkloadManager::ContainerType _type; Executor& _executor; @@ -1736,9 +1737,19 @@ void NewTask::run(const WorkloadManager::RunInfo& runInfo) delete this; // provisoire } -void Executor::newRun(Scheduler *graph,int debug, bool fromScratch) +bool NewTask::isAccepted(const WorkloadManager::Resource& r) { - DEBTRACE("Executor::newRun debug: "<< graph->getName() <<" "<< debug<<" fromScratch: "<getContainer(); + std::string hostname = yacsContainer->getProperty("hostname"); + bool accept = true; + if(!hostname.empty()) + accept = (hostname == r.name); + return accept; +} + +void Executor::runWlm(Scheduler *graph,int debug, bool fromScratch) +{ + DEBTRACE("Executor::runWlm debug: "<< graph->getName() <<" "<< debug<<" fromScratch: "< alck(&_mutexForSchedulerUpdate); _mainSched = graph; @@ -1889,7 +1900,7 @@ void Executor::RunW(Scheduler *graph,int debug, bool fromScratch) || str_value == "WORKLOADMANAGER" || str_value == "workloadmanager" || str_value == "WorkLoadManager") - newRun(graph, debug, fromScratch); + runWlm(graph, debug, fromScratch); else RunB(graph, debug, fromScratch); } diff --git a/src/engine/Executor.hxx b/src/engine/Executor.hxx index c83b4159f..dfa37fa03 100644 --- a/src/engine/Executor.hxx +++ b/src/engine/Executor.hxx @@ -101,7 +101,7 @@ namespace YACS void RunA(Scheduler *graph,int debug=0, bool fromScratch=true); void RunW(Scheduler *graph,int debug=0, bool fromScratch=true); void RunB(Scheduler *graph,int debug=0, bool fromScratch=true); - void newRun(Scheduler *graph,int debug=0, bool fromScratch=true); + void runWlm(Scheduler *graph,int debug=0, bool fromScratch=true); void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; } bool getKeepGoingProperty() const { return _keepGoingOnFail; } void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; } diff --git a/src/yacsloader_swig/Test/CMakeLists.txt b/src/yacsloader_swig/Test/CMakeLists.txt index d8cb4ff36..e33ec979c 100644 --- a/src/yacsloader_swig/Test/CMakeLists.txt +++ b/src/yacsloader_swig/Test/CMakeLists.txt @@ -46,6 +46,7 @@ IF(NOT WIN32) testProgress.py testExecForEachGeoMesh.py async_plugin.py + testWorkloadManager.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 ff5955c46..c8117f763 100644 --- a/src/yacsloader_swig/Test/CTestTestfileInstall.cmake +++ b/src/yacsloader_swig/Test/CTestTestfileInstall.cmake @@ -30,4 +30,10 @@ IF(NOT WIN32) LABELS "${COMPONENT_NAME}" ) + SET(TEST_NAME ${COMPONENT_NAME}_WorkloadManager_swig) + ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} testWorkloadManager.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + ) + ENDIF() diff --git a/src/yacsloader_swig/Test/runUnitTest.sh b/src/yacsloader_swig/Test/runUnitTest.sh index 51a9d35c6..5c3c745c0 100755 --- a/src/yacsloader_swig/Test/runUnitTest.sh +++ b/src/yacsloader_swig/Test/runUnitTest.sh @@ -27,10 +27,14 @@ sleep 3 export TESTCOMPONENT_ROOT_DIR=`pwd`/../runtime -python3 -m unittest discover +#python3 -m unittest discover +MODULES_TO_TEST=testEdit testExec testFEDyn testFEDyn2 testLoader testProgress \ +testRefcount testResume testSave testSaveLoadRun testValidationChecks + +python3 -m unittest $MODULES_TO_TEST ret=$? echo "exec status salome_test_driver " $ret kill -9 $pidecho -exit $ret \ No newline at end of file +exit $ret diff --git a/src/yacsloader_swig/Test/testWorkloadManager.py b/src/yacsloader_swig/Test/testWorkloadManager.py new file mode 100755 index 000000000..ae9197868 --- /dev/null +++ b/src/yacsloader_swig/Test/testWorkloadManager.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# Copyright (C) 2006-2020 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 +# + +import sys +import pilot +import SALOMERuntime +import loader +import unittest +import tempfile +import os + +class TestEdit(unittest.TestCase): + + def setUp(self): + SALOMERuntime.RuntimeSALOME_setRuntime() + self.r = pilot.getRuntime() + self.l = loader.YACSLoader() + self.e = pilot.ExecutorSwig() + pass + + def test1(self): + """ Test the conservation of the python context between two nodes sharing + the same container. + Schema: n1 -> n2 + """ + runtime=self.r + executor=self.e + proc=runtime.createProc("MySchema") + ti=proc.createType("int","int") + cont=proc.createContainer("MyContainer","Salome") + # type "multi" : the workload manager chooses the resource + # type "mono" : the workload manager does not choose the resource + cont.setProperty("type","multi") + # number of cores used by the container + cont.setProperty("nb_parallel_procs", "1") + n1=runtime.createScriptNode("","n1") + n2=runtime.createScriptNode("","n2") + n1.setExecutionMode("remote") + n2.setExecutionMode("remote") + n1.setContainer(cont) + n2.setContainer(cont) + n1.setScript("v=42") + res_port=n2.edAddOutputPort("v", ti) + proc.edAddChild(n1) + proc.edAddChild(n2) + proc.edAddCFLink(n1,n2) + # set the default execution mode using the workload manager + proc.setProperty("executor", "workloadmanager") + # reuse the same python context for every execution + cont.setStoreContext(True) + #proc.saveSchema("mini_wlm.xml") + executor=pilot.ExecutorSwig() + # default run method of the executor which uses the property "executor" + # in order to choose the actual run method + executor.RunW(proc,0) + # you can also impose the executor, ignoring the property "executor" + #executor.RunB(proc,0) # use the "historical" executor + #executor.runWlm(proc,0) # use the workload manager based executor + + self.assertEqual(res_port.getPyObj(), 42) + +if __name__ == '__main__': + dir_test = tempfile.mkdtemp(suffix=".yacstest") + file_test = os.join(dir_test,"UnitTestsResult") + with open(file_test, 'a') as f: + f.write(" --- TEST src/yacsloader: testWorkloadManager.py\n") + suite = unittest.makeSuite(TestEdit) + result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite) + sys.exit(not result.wasSuccessful()) -- 2.39.2