00001
00009
00010 #include <iostream>
00011 #include <vector>
00012 #include <string>
00013 #include <fstream>
00014
00015
00016 extern "C" {
00017 #include <unistd.h>
00018 #include <sys/wait.h>
00019 #include <sys/types.h>
00020 #include <signal.h>
00021 #include <sys/time.h>
00022 };
00023
00024
00025 #include "ipc/core.h"
00026 #include <ipc/partition.h>
00027 #include "cdi/cdiHandle.h"
00028
00029
00030
00031
00032
00033 #include "AuxObjs.h"
00034
00035
00036
00037
00038 #define MAX_UPD 1000
00039 #define log std::cout << OWLTime()
00040
00041
00042
00043
00044
00045 int main(int argc, char**argv){
00046
00047 IPCCore::init(argc, argv);
00048
00049 setenv("TEST_NAME", __FILE__ ,1);
00050 if (argc != 2 ){
00051 log << "::cdi_test -> Time interval not defined" << std::endl;
00052 return 1;
00053 }
00054
00055 timeval t_start, t_end;
00056
00057 std::ofstream fout("logs/cdi_test2.log");
00058 double interval;
00059 unsigned int tIntv = atoi(argv[1]);
00060 log << "::cdi_test2 -> Storing data with interval of " << tIntv << " microseconds" << std::endl;
00061
00062 std::cout << OWLTime() << " :: cdi_test2 -> Initializing partition [be_test]!" << std::endl;
00063
00064 fout << "------------------ Test1 START------------------------------" << std::endl;
00065 fout << "Initialize Online Environment : [" ;
00066
00067 gettimeofday(&t_start,NULL);
00068
00069
00070 IPCPartition p("be_test");
00071
00072 if (p.isValid()) {
00073 std::cout << OWLTime() << " :: partition is valid!" << std::endl;
00074 }
00075 else
00076 std::cout << OWLTime() << " :: partition is NOT valid!" << std::endl;
00077
00078
00079
00080 std::cout << OWLTime() << " :: cdi_test2 -> Initializing the dictionary!" << std::endl;
00081
00082 ISInfoDictionary dict(p);
00083
00084 std::cout << OWLTime() << " :: cdi_test2 -> Initializing Conditions object!" << std::endl;
00085
00086
00087
00088 gettimeofday(&t_end,NULL);
00089 interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00090 fout << interval << "]" << std::endl;
00091
00092
00093
00094
00095
00096 TestInfo1 obj1;
00097 TestInfo2 obj2;
00098 TestInfo3 obj3;
00099 TestInfo4 obj4;
00100 TestInfo5 obj5;
00101 TestInfo6 obj6;
00102 TestInfo7 obj7;
00103 TestInfo8 obj8;
00104 TestInfo9 obj9;
00105 TestInfo10 obj10;
00106 TestInfo11 obj11;
00107 TestInfo12 obj12;
00108
00109
00110
00111
00112
00113 obj1.c = 'a';
00114 obj1.uc = 'b';
00115 obj1.i = 1;
00116 obj1.ui = 2;
00117 obj1.s = 3;
00118 obj1.us = 4;
00119 obj1.l = 5;
00120 obj1.ul = 6;
00121 obj1.f = 7.7;
00122 obj1.d = 8.8;
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 obj2.c = 'a';
00133 obj2.uc = 'b';
00134 obj2.i = 1;
00135 obj2.ui = 2;
00136 obj2.s = 3;
00137 obj2.us = 4;
00138 obj2.l = 5;
00139 obj2.ul = 6;
00140 obj2.f = 7.7;
00141 obj2.d = 8.8;
00142
00143
00144
00145
00146
00147
00148 obj3.c = 'a';
00149 obj3.uc = 'b';
00150 obj3.i = 1;
00151 obj3.ui = 3;
00152 obj3.s = 3;
00153 obj3.us = 4;
00154 obj3.l = 5;
00155 obj3.ul = 6;
00156 obj3.f = 7.7;
00157 obj3.d = 8.8;
00158
00159
00160
00161
00162
00163
00164
00165
00166 obj4.c = 'a';
00167 obj4.uc = 'b';
00168 obj4.i = 1;
00169 obj4.ui = 4;
00170 obj4.s = 3;
00171 obj4.us = 4;
00172 obj4.l = 5;
00173 obj4.ul = 6;
00174 obj4.f = 7.7;
00175 obj4.d = 8.8;
00176
00177
00178
00179
00180
00181
00182 obj5.c = 'a';
00183 obj5.uc = 'b';
00184 obj5.i = 1;
00185 obj5.ui = 5;
00186 obj5.s = 3;
00187 obj5.us = 4;
00188 obj5.l = 5;
00189 obj5.ul = 6;
00190 obj5.f = 7.7;
00191 obj5.d = 8.8;
00192
00193
00194
00195
00196
00197
00198
00199 obj6.c = 'a';
00200 obj6.uc = 'b';
00201 obj6.i = 1;
00202 obj6.ui = 6;
00203 obj6.s = 3;
00204 obj6.us = 4;
00205 obj6.l = 5;
00206 obj6.ul = 6;
00207 obj6.f = 7.7;
00208 obj6.d = 8.8;
00209
00210
00211
00212
00213
00214
00215 obj7.c = 'a';
00216 obj7.uc = 'b';
00217 obj7.i = 1;
00218 obj7.ui = 7;
00219 obj7.s = 3;
00220 obj7.us = 4;
00221 obj7.l = 5;
00222 obj7.ul = 6;
00223 obj7.f = 7.7;
00224 obj7.d = 8.8;
00225
00226
00227
00228
00229
00230
00231 obj8.c = 'a';
00232 obj8.uc = 'b';
00233 obj8.i = 1;
00234 obj8.ui = 8;
00235 obj8.s = 3;
00236 obj8.us = 4;
00237 obj8.l = 5;
00238 obj8.ul = 6;
00239 obj8.f = 7.7;
00240 obj8.d = 8.8;
00241
00242
00243
00244
00245
00246
00247 obj9.c = 'a';
00248 obj9.uc = 'b';
00249 obj9.i = 1;
00250 obj9.ui = 9;
00251 obj9.s = 3;
00252 obj9.us = 4;
00253 obj9.l = 5;
00254 obj9.ul = 6;
00255 obj9.f = 7.7;
00256 obj9.d = 8.8;
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 obj10.c = 'a';
00267 obj10.uc = 'b';
00268 obj10.i = 1;
00269 obj10.ui = 10;
00270 obj10.s = 3;
00271 obj10.us = 4;
00272 obj10.l = 5;
00273 obj10.ul = 6;
00274 obj10.f = 7.7;
00275 obj10.d = 8.8;
00276
00277
00278
00279
00280
00281
00282
00283 obj11.c = 'a';
00284 obj11.uc = 'b';
00285 obj11.i = 1;
00286 obj11.ui = 11;
00287 obj11.s = 3;
00288 obj11.us = 4;
00289 obj11.l = 5;
00290 obj11.ul = 6;
00291 obj11.f = 7.7;
00292 obj11.d = 8.8;
00293
00294
00295
00296
00297
00298
00299
00300 obj12.c = 'a';
00301 obj12.uc = 'b';
00302 obj12.i = 1;
00303 obj12.ui = 2;
00304 obj12.s = 3;
00305 obj12.us = 4;
00306 obj12.l = 5;
00307 obj12.ul = 6;
00308 obj12.f = 7.7;
00309 obj12.d = 8.8;
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 std::vector<std::string> names;
00321 std::vector<ISInfo*> objs;
00322 objs.push_back(&obj1);
00323 objs.push_back(&obj2);
00324 objs.push_back(&obj3);
00325 objs.push_back(&obj4);
00326 objs.push_back(&obj5);
00327 objs.push_back(&obj6);
00328 objs.push_back(&obj7);
00329 objs.push_back(&obj8);
00330 objs.push_back(&obj9);
00331 objs.push_back(&obj10);
00332 objs.push_back(&obj11);
00333 objs.push_back(&obj12);
00334
00335 for (unsigned int i=1; i<= 12; i++){
00336 std::ostringstream n;
00337 n << "RunParams.obj" << i;
00338 names.push_back(n.str().c_str());
00339 }
00340
00341 std::cout << OWLTime() << " :: cdi_test2 -> Adding Information objects to the list!" << std::endl;
00342 fout << "Subscribing the object :[";
00343 gettimeofday(&t_start,NULL);
00344 for (unsigned int i=1; i<=12; i++){
00345 dict.insert(names[i].c_str(),*(objs[i]));
00346 }
00347 gettimeofday(&t_end,NULL);
00348 interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00349 fout << interval << "]" << std::endl;
00350 sleep(30);
00351
00352
00353
00354 std::cout << OWLTime() << " ::cdi_test2 -> Starting to update the objects" << std::endl;
00355
00356
00357
00358
00359 timeval tt_s, tt_e;
00360 gettimeofday(&t_start,NULL);
00361
00362 for (unsigned int i = 1; i <= MAX_UPD; i++) {
00363 for (unsigned int j = 1; j <=12; j++){
00364 (dynamic_cast<TestInfo1*>(objs[0]))->i += i;
00365 dynamic_cast<TestInfo2*>(objs[1])->i += i;
00366 dynamic_cast<TestInfo3*>(objs[2])->i += i;
00367 dynamic_cast<TestInfo4*>(objs[3])->i += i;
00368 dynamic_cast<TestInfo5*>(objs[4])->i += i;
00369 dynamic_cast<TestInfo6*>(objs[5])->i += i;
00370 dynamic_cast<TestInfo7*>(objs[6])->i += i;
00371 dynamic_cast<TestInfo8*>(objs[7])->i += i;
00372 dynamic_cast<TestInfo9*>(objs[8])->i += i;
00373 dynamic_cast<TestInfo10*>(objs[9])->i += i;
00374 fout << "Updating object [" << i << "| 0 ] : -> [";
00375 gettimeofday(&tt_s,NULL);
00376 dict.update(names[j].c_str(),*(objs[j]));
00377 gettimeofday(&tt_e,NULL);
00378 interval = (double)(((double)tt_e.tv_sec*1000+(double)tt_e.tv_usec/1000)-((double)tt_s.tv_sec*1000+(double)tt_s.tv_usec/1000));
00379 fout << interval << "]" << std::endl;
00380
00381 usleep(tIntv);
00382 }
00383 }
00384 gettimeofday(&t_end,NULL);
00385 interval = (double)(((double)t_end.tv_sec*1000+(double)t_end.tv_usec/1000)-((double)t_start.tv_sec*1000+(double)t_start.tv_usec/1000));
00386 fout << "Total update time: [" << interval << "]" << std::endl;
00387 fout << "-------------------------------------END OF TEST ----------------------------------";
00388
00389 fout.close();
00390 log << "::cdi_test2 -> Test finished....exiting" << std::endl;
00391 return 0;
00392 }