Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/yacs.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   int status;
53
54   // Initializing omniORB
55   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
56   CORBA::ORB_ptr orb = init( argc , argv ) ;
57
58   SALOME_NamingService *_NS=new SALOME_NamingService(orb);
59
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);
66
67   Engines::MachineParameters p;
68   Engines::CompoList clist;
69   clist.length(2);
70   clist[0] = "MED";
71   clist[1] = "GEOM";
72
73   p.hostname = "";
74   p.OS = "LINUX";
75   p.mem_mb = 1000;
76   p.cpu_clock = 1000;
77   p.nb_proc_per_node = 1;
78   p.nb_node = 1;
79   p.isMPI = false;
80
81   char st[10];
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;
87   }
88
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;
94   }
95
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;
100
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;
107
108   _NS->Change_Directory("/Containers");
109
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));
119     }
120   }
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()]++;
129     }
130   }
131   _ContManager->ShutdownContainers();
132
133   int cmin=10;
134   int cmax=0;
135   int fmin=10;
136   int fmax=0;
137   int nbpmax;
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;
147         nbpmax = nbproc;
148       }
149     }
150   }
151   string msg;
152   if( ((cmax-cmin) <= 2) && (fmax == 10/nbpmax) && !error ){
153     if(bestImplemented)
154       msg = "TEST OK";
155     else
156       msg = "TEST OK but FindBest not implemented!";
157     status=0;
158   }
159   else{
160     msg ="TEST KO";
161     status=1;
162   }
163   cout << msg << endl;
164
165   return status;
166 }