1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME TestContainer : test of container creation and its life cycle
23 // File : TestContainer.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
28 #include "utilities.h"
33 #include <SALOMEconfig.h>
34 #include "SALOME_NamingService.hxx"
35 #include "SALOME_ContainerManager.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "NamingService_WaitForServerReadiness.hxx"
39 #include "Utils_ORB_INIT.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_SALOME_Exception.hxx"
42 #include "Utils_CommException.hxx"
43 #include "Basics_DirUtils.hxx"
45 int main (int argc, char * argv[])
47 std::map<std::string, int> cycle;
48 std::map<std::string, int> first;
49 Engines::Container_ptr cont;
50 Engines::Component_ptr compo;
55 // Initializing omniORB
56 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
57 CORBA::ORB_ptr orb = init( argc , argv ) ;
59 SALOME_NamingService *_NS=new SALOME_NamingService(orb);
61 CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
62 ASSERT( !CORBA::is_nil(obj));
63 Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
64 obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
65 ASSERT( !CORBA::is_nil(obj));
66 Engines::ResourcesManager_var _ResManager=Engines::ResourcesManager::_narrow(obj);
68 Engines::MachineParameters p;
69 Engines::CompoList clist;
78 p.nb_proc_per_node = 1;
83 for(int i=0;i<10;i++){
84 sprintf(st,"cycl_%d",i);
85 p.container_name = CORBA::string_dup(st);
86 cont = _ContManager->GiveContainer(p,Engines::P_CYCL,clist);
87 if(CORBA::is_nil(cont)) error = true;
90 for(int i=0;i<10;i++){
91 sprintf(st,"first_%d",i);
92 p.container_name = CORBA::string_dup(st);
93 cont = _ContManager->GiveContainer(p,Engines::P_FIRST,clist);
94 if(CORBA::is_nil(cont)) error = true;
97 p.container_name = CORBA::string_dup("best");
98 cont = _ContManager->GiveContainer(p,Engines::P_BEST,clist);
99 if(CORBA::is_nil(cont)) bestImplemented = false;
100 else bestImplemented = true;
102 SALOME_LifeCycleCORBA LCC(_NS);
103 p.container_name = CORBA::string_dup("FactoryServer");
104 compo = LCC.FindOrLoad_Component(p,"SMESH");
105 if(CORBA::is_nil(compo)) error = true;
106 compo = LCC.FindOrLoad_Component(p,"SMESH");
107 if(CORBA::is_nil(compo)) error = true;
109 _NS->Change_Directory("/Containers");
111 std::vector<std::string> vec = _NS->list_directory_recurs();
112 std::list<std::string> lstCont;
113 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++){
114 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
115 Engines::Container_var cont=Engines::Container::_narrow(obj);
116 if(!CORBA::is_nil(cont)){
117 cycle[cont->getHostName()]=0;
118 first[cont->getHostName()]=0;
119 lstCont.push_back((*iter));
122 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
123 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
124 Engines::Container_var cont=Engines::Container::_narrow(obj);
125 if(!CORBA::is_nil(cont)){
126 std::string basename = Kernel_Utils::GetBaseName(cont->name());
127 if(basename.compare(0,4,"cycl")==0)
128 cycle[cont->getHostName()]++;
129 if(basename.compare(0,5,"first")==0)
130 first[cont->getHostName()]++;
133 _ContManager->ShutdownContainers();
140 for(std::map<std::string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
141 if(strcmp((*iter).first.c_str(),"localhost")!=0){
142 Engines::MachineParameters *p = _ResManager->GetMachineParameters((*iter).first.c_str());
143 int nbproc = p->nb_node * p->nb_proc_per_node;
144 if(cycle[(*iter).first]/nbproc<cmin) cmin=cycle[(*iter).first]/nbproc;
145 if(cycle[(*iter).first]/nbproc>cmax) cmax=cycle[(*iter).first]/nbproc;
146 if(first[(*iter).first]/nbproc<fmin) fmin=first[(*iter).first]/nbproc;
147 if(first[(*iter).first]/nbproc>fmax){
148 fmax=first[(*iter).first]/nbproc;
154 if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){
158 msg = "TEST OK but FindBest not implemented!";
165 std::cout << msg << std::endl;