00001
00002
00003
00004
00005
00006 #include <stdlib.h>
00007
00008 #include "globals.h"
00009 #include "cmdarg.h"
00010 #include "module.h"
00011 #include "output.h"
00012 #include "save.h"
00013 #include "find.h"
00014 #include "test.h"
00015 #include "aggregate.h"
00016
00017 #ifndef _NO_CPPUNIT
00018 #include "test_callbacks.h"
00019
00020 #ifndef WIN32
00021 #include <dlfcn.h>
00022 #endif
00023
00024
00025 TIMESTAMP get_global_clock(void)
00026 {
00027 return global_clock;
00028 }
00029
00030 STATUS t_setup_ranks(void);
00031 STATUS t_sync_all(PASSCONFIG pass);
00032
00033 STATUS test_init(void)
00034 {
00035 OBJECT *obj;
00036 output_verbose("initializing objects...");
00037 for (obj=object_get_first(); obj!=NULL; obj=object_get_next(obj))
00038 {
00039 if (object_init(obj)==FAILED)
00040 {
00041 output_error("object %s initialization failed", object_name(obj));
00042 return FAILED;
00043 }
00044 }
00045 return SUCCESS;
00046 }
00047
00048 STATUS do_sync_all(PASSCONFIG pass)
00049 {
00050 return t_sync_all(pass);
00051 }
00052
00053 static TEST_CALLBACKS callbacks = {
00054
00055 class_get_class_from_classname,
00056 get_global_clock,
00057 object_sync,
00058 do_sync_all,
00059 test_init,
00060 t_setup_ranks,
00061 remove_objects
00062 };
00063
00064 STATUS test_start(int argc, char *argv[])
00065 {
00066 int mod_test_num = 1;
00067 char mod_test[100];
00068 char *mod_name;
00069 int test_result = 0;
00070 sprintf(mod_test,"mod_test%d",mod_test_num++);
00071 mod_name = global_getvar(mod_test, NULL, 0);
00072 module_load("tape",argc,argv);
00073 while(mod_name != NULL)
00074 {
00075 MODULE *mod = module_load(mod_name,argc,argv);
00076
00077 if(mod == NULL)
00078 {
00079 output_fatal("Invalid module name");
00080
00081
00082
00083
00084
00085 return FAILED;
00086 }
00087
00088 if (mod->module_test==NULL)
00089 {
00090 output_fatal("Module %s does not implement cppunit test", mod->name);
00091
00092
00093
00094
00095
00096
00097 return FAILED;
00098 }
00099
00100 test_result = mod->module_test(&callbacks,argc,argv);
00101
00102 if(test_result == 0)
00103 return FAILED;
00104 sprintf(mod_test,"mod_test%d",mod_test_num++);
00105 mod_name = global_getvar(mod_test, NULL, 0);
00106 }
00107
00108 return SUCCESS;
00109
00110 }
00111 STATUS original_test_start(int argc, char *argv[])
00112 {
00113 OBJECT *obj[6];
00114 MODULE *network;
00115 CLASS *node, *link;
00116 MODULE *tape;
00117 CLASS *player, *recorder, *collector;
00118
00119 network = module_load("network",argc,argv);
00120 if (network==NULL)
00121 {
00122 #ifndef WIN32
00123 fprintf(stderr,"%s\n",dlerror());
00124 #else
00125 perror("network module load failed");
00126 #endif
00127 return FAILED;
00128 }
00129 output_verbose("network module loaded ok");
00130
00131 node = class_get_class_from_classname("node");
00132 if (node==NULL)
00133 {
00134 output_fatal("network module does not implement class node");
00135
00136
00137
00138
00139
00140
00141 return FAILED;
00142 }
00143 output_verbose("class node implementation loaded ok");
00144
00145 link = class_get_class_from_classname("link");
00146 if (node==NULL || link==NULL)
00147 {
00148 output_fatal("network module does not implement class link");
00149
00150
00151
00152
00153
00154
00155 return FAILED;
00156 }
00157 output_verbose("class link implementation loaded ok");
00158
00159 tape = module_load("tape",argc,argv);
00160 if (tape==NULL)
00161 {
00162 #ifndef WIN32
00163 fprintf(stderr,"%s\n",dlerror());
00164 #else
00165 perror("tape module load failed");
00166 #endif
00167 return FAILED;
00168 }
00169
00170 player = class_get_class_from_classname("player");
00171 if (player==NULL)
00172 {
00173 output_fatal("tape module does not implement class player");
00174
00175
00176
00177
00178
00179
00180 return FAILED;
00181 }
00182 recorder = class_get_class_from_classname("recorder");
00183 if (recorder==NULL)
00184 {
00185 output_fatal("tape module does not implement class recorder");
00186
00187
00188
00189
00190
00191
00192 return FAILED;
00193 }
00194 collector = class_get_class_from_classname("collector");
00195 if (collector==NULL)
00196 {
00197 output_fatal("tape module does not implement class collector");
00198
00199
00200
00201
00202
00203
00204 return FAILED;
00205 }
00206
00207 if (module_import(network,"../test/pnnl2bus.cdf")<=0)
00208 return FAILED;
00209
00210
00211 if ((*player->create)(&obj[3],object_get_first())==FAILED)
00212 {
00213 output_fatal("player creation failed");
00214
00215
00216
00217
00218
00219
00220 return FAILED;
00221 }
00222 object_set_value_by_name(obj[3],"loop","3600");
00223 object_set_value_by_name(obj[3],"property","S");
00224
00225
00226 if ((*recorder->create)(&obj[4],object_get_first())==FAILED)
00227 {
00228 output_fatal("recorder creation failed");
00229
00230
00231
00232
00233
00234
00235 return FAILED;
00236 }
00237 object_set_value_by_name(obj[4],"property","V,S");
00238 object_set_value_by_name(obj[4],"interval","0");
00239 object_set_value_by_name(obj[4],"limit","1000");
00240
00241
00242 if ((*collector->create)(&obj[5],NULL)==FAILED)
00243 {
00244 output_fatal("collector creation failed");
00245
00246
00247
00248
00249
00250
00251 return FAILED;
00252 }
00253 object_set_value_by_name(obj[5],"property","count(V.mag),min(V.mag),avg(V.mag),std(V.mag),max(V.mag),min(V.ang),avg(V.ang),std(V.ang),max(V.ang)");
00254 object_set_value_by_name(obj[5],"interval","0");
00255 object_set_value_by_name(obj[5],"limit","1000");
00256 object_set_value_by_name(obj[5],"group","class=node;");
00257
00258 module_check(network);
00259
00260 return SUCCESS;
00261 }
00262
00263
00264
00265 STATUS test_end(int argc, char *argv[])
00266 {
00267 return SUCCESS;
00268 }
00269
00270 STATUS original_test_end(int argc, char *argv[])
00271 {
00272 FINDLIST *find = find_objects(FL_GROUP,"class=node;");
00273 OBJECT *obj;
00274 AGGREGATION *aggr;
00275 char *exp = "class=node";
00276 char *agg = "max(V.ang)";
00277
00278 for (obj=find_first(find); obj!=NULL; obj=find_next(find,obj))
00279 output_message("object %s found", object_name(obj));
00280 free(find);
00281
00282 output_message("Aggregation of %s over %s...", agg,exp);
00283 aggr = aggregate_mkgroup(agg,exp);
00284 if (aggr)
00285 output_message("Result is %lf", aggregate_value(aggr));
00286 else
00287 output_message("Aggregation failed!");
00288
00289 if (!saveall("-"))
00290 perror("save failed");
00291
00292 return SUCCESS;
00293 }
00294
00295 #endif