Salome HOME
A patch from Paul RASCLE for: kernel documentation with doxygen, modification on...
[modules/kernel.git] / src / LifeCycleCORBA / TestContainerManager.cxx
1 //  SALOME TestContainer : test of container creation and its life cycle
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : TestContainer.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 #include "utilities.h"
30 #include <iostream>
31 #include <unistd.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"
37 #include "OpUtil.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #include "Utils_CommException.hxx"
42 using namespace std;
43
44 int main (int argc, char * argv[])
45 {
46   map<string, int> cycle;
47   map<string, int> first;
48   Engines::Container_ptr cont;
49   Engines::Component_ptr compo;
50   bool error = false;
51   bool bestImplemented;
52
53   // Initializing omniORB
54   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
55   CORBA::ORB_ptr orb = init( argc , argv ) ;
56
57   SALOME_NamingService *_NS=new SALOME_NamingService(orb);
58
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);
65
66   Engines::MachineParameters p;
67   Engines::CompoList clist;
68   clist.length(2);
69   clist[0] = "MED";
70   clist[1] = "GEOM";
71
72   p.hostname = "";
73   p.OS = "LINUX";
74   p.mem_mb = 1000;
75   p.cpu_clock = 1000;
76   p.nb_proc_per_node = 1;
77   p.nb_node = 1;
78   p.isMPI = false;
79
80   char st[10];
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;
86   }
87
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;
93   }
94
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;
99
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;
106
107   _NS->Change_Directory("/Containers");
108
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));
118     }
119   }
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()]++;
128     }
129   }
130   _ContManager->ShutdownContainers();
131
132   int cmin=10;
133   int cmax=0;
134   int fmin=10;
135   int fmax=0;
136   int nbpmax;
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;
146         nbpmax = nbproc;
147       }
148     }
149   }
150   if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){
151     string msg;
152     if(bestImplemented)
153       msg = "TEST OK";
154     else
155       msg = "TEST OK but FindBest not implemented!";
156     MESSAGE(msg);
157     return 0;
158   }
159   else{
160     MESSAGE("TEST KO");
161     return 1;
162   }
163 }