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;
54 // Initializing omniORB
55 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
56 CORBA::ORB_ptr orb = init( argc , argv ) ;
58 SALOME_NamingService *_NS=new SALOME_NamingService(orb);
60 CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
61 ASSERT( !CORBA::is_nil(obj));
62 Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
63 obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
64 ASSERT( !CORBA::is_nil(obj));
65 Engines::ResourcesManager_var _ResManager=Engines::ResourcesManager::_narrow(obj);
67 Engines::MachineParameters p;
68 Engines::CompoList clist;
77 p.nb_proc_per_node = 1;
82 for(int i=0;i<10;i++){
83 sprintf(st,"cycl_%d",i);
84 p.container_name = CORBA::string_dup(st);
85 cont = _ContManager->GiveContainer(p,Engines::P_CYCL,clist);
86 if(CORBA::is_nil(cont)) error = true;
89 for(int i=0;i<10;i++){
90 sprintf(st,"first_%d",i);
91 p.container_name = CORBA::string_dup(st);
92 cont = _ContManager->GiveContainer(p,Engines::P_FIRST,clist);
93 if(CORBA::is_nil(cont)) error = true;
96 p.container_name = CORBA::string_dup("best");
97 cont = _ContManager->GiveContainer(p,Engines::P_BEST,clist);
98 if(CORBA::is_nil(cont)) bestImplemented = false;
99 else bestImplemented = true;
101 SALOME_LifeCycleCORBA LCC(_NS);
102 p.container_name = CORBA::string_dup("FactoryServer");
103 compo = LCC.FindOrLoad_Component(p,"SMESH");
104 if(CORBA::is_nil(compo)) error = true;
105 compo = LCC.FindOrLoad_Component(p,"SMESH");
106 if(CORBA::is_nil(compo)) error = true;
108 _NS->Change_Directory("/Containers");
110 vector<string> vec = _NS->list_directory_recurs();
111 list<string> lstCont;
112 for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
113 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
114 Engines::Container_var cont=Engines::Container::_narrow(obj);
115 if(!CORBA::is_nil(cont)){
116 cycle[cont->getHostName()]=0;
117 first[cont->getHostName()]=0;
118 lstCont.push_back((*iter));
121 for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
122 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
123 Engines::Container_var cont=Engines::Container::_narrow(obj);
124 if(!CORBA::is_nil(cont)){
125 if(strncmp(basename(cont->name()),"cycl",4)==0)
126 cycle[cont->getHostName()]++;
127 if(strncmp(basename(cont->name()),"first",5)==0)
128 first[cont->getHostName()]++;
131 _ContManager->ShutdownContainers();
138 for(map<string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
139 if(strcmp((*iter).first.c_str(),"localhost")!=0){
140 Engines::MachineParameters *p = _ResManager->GetMachineParameters((*iter).first.c_str());
141 int nbproc = p->nb_node * p->nb_proc_per_node;
142 if(cycle[(*iter).first]/nbproc<cmin) cmin=cycle[(*iter).first]/nbproc;
143 if(cycle[(*iter).first]/nbproc>cmax) cmax=cycle[(*iter).first]/nbproc;
144 if(first[(*iter).first]/nbproc<fmin) fmin=first[(*iter).first]/nbproc;
145 if(first[(*iter).first]/nbproc>fmax){
146 fmax=first[(*iter).first]/nbproc;
152 if( ((cmax-cmin) <= 2) && (fmax == 10/nbpmax) && !error ){
156 msg = "TEST OK but FindBest not implemented!";