1 // SALOME TestContainer : test of container creation and its life cycle
3 // Copyright (C) 2003 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
24 // File : TestContainer.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #include "utilities.h"
32 #include <SALOMEconfig.h>
33 #include "SALOME_NamingService.hxx"
34 #include "SALOME_ContainerManager.hxx"
35 #include "SALOME_LifeCycleCORBA.hxx"
36 #include "NamingService_WaitForServerReadiness.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #include "Utils_CommException.hxx"
44 int main (int argc, char * argv[])
46 map<string, int> cycle;
47 map<string, int> first;
48 Engines::Container_ptr cont;
49 Engines::Component_ptr compo;
53 // Initializing omniORB
54 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
55 CORBA::ORB_ptr orb = init( argc , argv ) ;
57 SALOME_NamingService *_NS=new SALOME_NamingService(orb);
59 CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
60 ASSERT( !CORBA::is_nil(obj));
61 Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
62 obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
63 ASSERT( !CORBA::is_nil(obj));
64 Engines::ResourcesManager_var _ResManager=Engines::ResourcesManager::_narrow(obj);
66 Engines::MachineParameters p;
67 Engines::CompoList clist;
76 p.nb_proc_per_node = 1;
81 for(int i=0;i<10;i++){
82 sprintf(st,"cycl_%d",i);
83 p.container_name = CORBA::string_dup(st);
84 cont = _ContManager->GiveContainer(p,Engines::P_CYCL,clist);
85 if(CORBA::is_nil(cont)) error = true;
88 for(int i=0;i<10;i++){
89 sprintf(st,"first_%d",i);
90 p.container_name = CORBA::string_dup(st);
91 cont = _ContManager->GiveContainer(p,Engines::P_FIRST,clist);
92 if(CORBA::is_nil(cont)) error = true;
95 p.container_name = CORBA::string_dup("best");
96 cont = _ContManager->GiveContainer(p,Engines::P_BEST,clist);
97 if(CORBA::is_nil(cont)) bestImplemented = false;
98 else bestImplemented = true;
100 SALOME_LifeCycleCORBA LCC(_NS);
101 p.container_name = CORBA::string_dup("FactoryServer");
102 compo = LCC.FindOrLoad_Component(p,"SMESH");
103 if(CORBA::is_nil(compo)) error = true;
104 compo = LCC.FindOrLoad_Component(p,"SMESH");
105 if(CORBA::is_nil(compo)) error = true;
107 _NS->Change_Directory("/Containers");
109 vector<string> vec = _NS->list_directory_recurs();
110 list<string> lstCont;
111 for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
112 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
113 Engines::Container_var cont=Engines::Container::_narrow(obj);
114 if(!CORBA::is_nil(cont)){
115 cycle[cont->getHostName()]=0;
116 first[cont->getHostName()]=0;
117 lstCont.push_back((*iter));
120 for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
121 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
122 Engines::Container_var cont=Engines::Container::_narrow(obj);
123 if(!CORBA::is_nil(cont)){
124 if(strncmp(basename(cont->name()),"cycl",4)==0)
125 cycle[cont->getHostName()]++;
126 if(strncmp(basename(cont->name()),"first",5)==0)
127 first[cont->getHostName()]++;
130 _ContManager->ShutdownContainers();
137 for(map<string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
138 if(strcmp((*iter).first.c_str(),"localhost")!=0){
139 Engines::MachineParameters *p = _ResManager->GetMachineParameters((*iter).first.c_str());
140 int nbproc = p->nb_node * p->nb_proc_per_node;
141 if(cycle[(*iter).first]/nbproc<cmin) cmin=cycle[(*iter).first]/nbproc;
142 if(cycle[(*iter).first]/nbproc>cmax) cmax=cycle[(*iter).first]/nbproc;
143 if(first[(*iter).first]/nbproc<fmin) fmin=first[(*iter).first]/nbproc;
144 if(first[(*iter).first]/nbproc>fmax){
145 fmax=first[(*iter).first]/nbproc;
150 if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){
155 msg = "TEST OK but FindBest not implemented!";