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 return FAILED;
00081 }
00082
00083 test_result = mod->module_test(&callbacks,argc,argv);
00084
00085 if(test_result == 0)
00086 return FAILED;
00087 sprintf(mod_test,"mod_test%d",mod_test_num++);
00088 mod_name = global_getvar(mod_test, NULL, 0);
00089 }
00090
00091 return SUCCESS;
00092
00093 }
00094 STATUS original_test_start(int argc, char *argv[])
00095 {
00096 OBJECT *obj[6];
00097 MODULE *network;
00098 CLASS *node, *link;
00099 MODULE *tape;
00100 CLASS *player, *recorder, *collector;
00101
00102 network = module_load("network",argc,argv);
00103 if (network==NULL)
00104 {
00105 #ifndef WIN32
00106 fprintf(stderr,"%s\n",dlerror());
00107 #else
00108 perror("network module load failed");
00109 #endif
00110 return FAILED;
00111 }
00112 output_verbose("network module loaded ok");
00113
00114 node = class_get_class_from_classname("node");
00115 if (node==NULL)
00116 {
00117 output_fatal("network module does not implement class node");
00118 return FAILED;
00119 }
00120 output_verbose("class node implementation loaded ok");
00121
00122 link = class_get_class_from_classname("link");
00123 if (node==NULL || link==NULL)
00124 {
00125 output_fatal("network module does not implement class link");
00126 return FAILED;
00127 }
00128 output_verbose("class link implementation loaded ok");
00129
00130 tape = module_load("tape",argc,argv);
00131 if (tape==NULL)
00132 {
00133 #ifndef WIN32
00134 fprintf(stderr,"%s\n",dlerror());
00135 #else
00136 perror("tape module load failed");
00137 #endif
00138 return FAILED;
00139 }
00140
00141 player = class_get_class_from_classname("player");
00142 if (player==NULL)
00143 {
00144 output_fatal("tape module does not implement class player");
00145 return FAILED;
00146 }
00147 recorder = class_get_class_from_classname("recorder");
00148 if (recorder==NULL)
00149 {
00150 output_fatal("tape module does not implement class recorder");
00151 return FAILED;
00152 }
00153 collector = class_get_class_from_classname("collector");
00154 if (collector==NULL)
00155 {
00156 output_fatal("tape module does not implement class collector");
00157 return FAILED;
00158 }
00159
00160 if (module_import(network,"../test/pnnl2bus.cdf")<=0)
00161 return FAILED;
00162
00163
00164 if ((*player->create)(&obj[3],object_get_first())==FAILED)
00165 {
00166 output_fatal("player creation failed");
00167 return FAILED;
00168 }
00169 object_set_value_by_name(obj[3],"loop","3600");
00170 object_set_value_by_name(obj[3],"property","S");
00171
00172
00173 if ((*recorder->create)(&obj[4],object_get_first())==FAILED)
00174 {
00175 output_fatal("recorder creation failed");
00176 return FAILED;
00177 }
00178 object_set_value_by_name(obj[4],"property","V,S");
00179 object_set_value_by_name(obj[4],"interval","0");
00180 object_set_value_by_name(obj[4],"limit","1000");
00181
00182
00183 if ((*collector->create)(&obj[5],NULL)==FAILED)
00184 {
00185 output_fatal("collector creation failed");
00186 return FAILED;
00187 }
00188 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)");
00189 object_set_value_by_name(obj[5],"interval","0");
00190 object_set_value_by_name(obj[5],"limit","1000");
00191 object_set_value_by_name(obj[5],"group","class=node;");
00192
00193 module_check(network);
00194
00195 return SUCCESS;
00196 }
00197
00198
00199
00200 STATUS test_end(int argc, char *argv[])
00201 {
00202 return SUCCESS;
00203 }
00204
00205 STATUS original_test_end(int argc, char *argv[])
00206 {
00207 FINDLIST *find = find_objects(FL_GROUP,"class=node;");
00208 OBJECT *obj;
00209 AGGREGATION *aggr;
00210 char *exp = "class=node";
00211 char *agg = "max(V.ang)";
00212
00213 for (obj=find_first(find); obj!=NULL; obj=find_next(find,obj))
00214 output_message("object %s found", object_name(obj));
00215 free(find);
00216
00217 output_message("Aggregation of %s over %s...", agg,exp);
00218 aggr = aggregate_mkgroup(agg,exp);
00219 if (aggr)
00220 output_message("Result is %lf", aggregate_value(aggr));
00221 else
00222 output_message("Aggregation failed!");
00223
00224 if (!saveall("-"))
00225 perror("save failed");
00226
00227 return SUCCESS;
00228 }
00229
00230 #endif