00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020
00021 #if !defined(DEBUG)
00022 #define DEBUG 1
00023 #endif
00024
00025 #include <stdlib.h>
00026 #include <assert.h>
00027 #include <assert_pp.h>
00028
00029 #include <rk_stub.h>
00030
00031 #include <iostream>
00032
00033 #include <tao/Typecode.h>
00034 #include <RKTask.hh>
00035 #include <ManagerImpl.hh>
00036
00037 #include "StubPolicy.hh"
00038
00039 using namespace std;
00040
00041 struct {
00042 int verbose;
00043 } args = {
00044 1,
00045 };
00046
00047
00048
00049
00050
00051
00052
00053 #define expect_catch(BLOCK, EXCEPTION) \
00054 { \
00055 try \
00056 { \
00057 BLOCK; \
00058 ensure(0); \
00059 } \
00060 catch(const EXCEPTION &_e) \
00061 { \
00062 if( args.verbose ) \
00063 { \
00064 cerr << "Tried \"" \
00065 << __STRING(BLOCK) \
00066 << "\" at line " \
00067 << __LINE__ \
00068 << " and got expected exception \"" \
00069 << _e \
00070 << "\"" \
00071 << endl; \
00072 try \
00073 { \
00074 throw _e; \
00075 } \
00076 catch(const Broker::InvalidTaskParameter &_itp) \
00077 { \
00078 cerr << "message=" \
00079 << _itp.message \
00080 << "; pair={ name=" \
00081 << _itp.pair.name \
00082 << "; value_kind=" \
00083 << _itp.pair.value.type()->kind() \
00084 << " }" \
00085 << endl; \
00086 } \
00087 catch(const Broker::DuplicateTaskParameter &_dtp) \
00088 { \
00089 cerr << "name=" \
00090 << _dtp.name \
00091 << endl; \
00092 } \
00093 catch(const Broker::DuplicateScheduleParameter &_dsp) \
00094 { \
00095 cerr << "name=" \
00096 << _dsp.name \
00097 << endl; \
00098 } \
00099 catch(const Broker::MissingTaskParameter &_mtp) \
00100 { \
00101 cerr << "name=" \
00102 << _mtp.name \
00103 << endl; \
00104 } \
00105 catch(const Broker::InvalidScheduleParameter &_itp) \
00106 { \
00107 cerr << "message=" \
00108 << _itp.message \
00109 << "; pair={ name=" \
00110 << _itp.pair.name \
00111 << "; value_kind=" \
00112 << _itp.pair.value.type()->kind() \
00113 << " }" \
00114 << endl; \
00115 } \
00116 catch(const Broker::MissingScheduleParameter &_msp) \
00117 { \
00118 cerr << "name=" \
00119 << _msp.name \
00120 << endl; \
00121 } \
00122 catch(const CORBA::SystemException &_se) \
00123 { \
00124 cerr << "system-exception '" \
00125 << _se \
00126 << "' at line " \
00127 << __LINE__ \
00128 << endl; \
00129 } \
00130 } \
00131 } \
00132 catch(...) \
00133 { \
00134 cerr << "unknown exception at line " \
00135 << __LINE__ \
00136 << endl; \
00137 exit(1); \
00138 } \
00139 }
00140
00141 int main(int argc, char *argv[])
00142 {
00143 int retval = EXIT_SUCCESS;
00144
00145 rk_stub_set_mode(RK_STUB_LOG);
00146
00147 try
00148 {
00149
00150 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00151 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00152
00153 PortableServer::POA_var root_poa =
00154 PortableServer::POA::_narrow(obj.in());
00155 PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00156 mgr->activate();
00157
00158
00159 Broker::ScheduleParameters sp;
00160 Broker::RealTimeTask_var rtt;
00161 Broker::Manager_var manager;
00162 Broker::TaskParameters tp;
00163 Broker::Task_var task;
00164 pid_t client_pid;
00165
00166 ManagerImpl *mi = new ManagerImpl("manager");
00167 StubPolicy *spi = new StubPolicy("dummy");
00168
00169 manager = mi->_this();
00170 Broker::Policy_var policy = spi->_this();
00171
00172 manager->CurrentPolicy(policy.in());
00173
00174
00175
00176 tp.length(0);
00177
00178 expect_catch(new RKTask(tp), Broker::MissingTaskParameter);
00179
00180 tp.length(1);
00181 tp[0].name = "name";
00182 tp[0].value <<= (CORBA::UShort)1;
00183
00184 expect_catch(new RKTask(tp), Broker::InvalidTaskParameter);
00185
00186 tp.length(1);
00187 tp[0].name = "name";
00188 tp[0].value <<= "really_long_name_that_should_cause_an_exception";
00189
00190 expect_catch(new RKTask(tp), Broker::InvalidTaskParameter);
00191
00192 tp.length(2);
00193 tp[0].name = "name";
00194 tp[0].value <<= "test";
00195 tp[1].name = "name";
00196 tp[1].value <<= "test";
00197
00198 expect_catch(new RKTask(tp), Broker::DuplicateTaskParameter);
00199
00200 tp.length(1);
00201
00202 RKTask *rkt = new RKTask(tp);
00203
00204 task = rkt->_this();
00205 rtt = Broker::RealTimeTask::_narrow(task.in());
00206 assert(!CORBA::is_nil(rtt.in()));
00207
00208
00209 expect_catch(task->EndCPUScheduling(), CORBA::BAD_INV_ORDER);
00210
00211 sp.length(0);
00212
00213 task->SetManager(manager.in());
00214
00215 expect_catch(task->BeginCPUScheduling(sp),
00216 Broker::MissingScheduleParameter);
00217
00218 sp.length(1);
00219 sp[0].name = "pid";
00220 sp[0].value <<= "hello";
00221
00222 expect_catch(task->BeginCPUScheduling(sp),
00223 Broker::InvalidScheduleParameter);
00224
00225 client_pid = -2;
00226 sp.length(1);
00227 sp[0].name = "pid";
00228 sp[0].value <<= client_pid;
00229
00230 expect_catch(task->BeginCPUScheduling(sp),
00231 Broker::InvalidScheduleParameter);
00232
00233 client_pid = rk_stub_mk_pid("test", NULL, NULL, NULL);
00234
00235 sp.length(2);
00236 sp[0].name = "pid";
00237 sp[0].value <<= client_pid;
00238 sp[1].name = "pid";
00239 sp[1].value <<= client_pid;
00240
00241 expect_catch(task->BeginCPUScheduling(sp),
00242 Broker::DuplicateScheduleParameter);
00243
00244 sp.length(2);
00245 sp[0].name = "period";
00246 sp[0].value <<= "hello";
00247 sp[1].name = "pid";
00248 sp[1].value <<= client_pid;
00249
00250 expect_catch(task->BeginCPUScheduling(sp),
00251 Broker::InvalidScheduleParameter);
00252
00253 sp.length(2);
00254 sp[0].name = "deadline";
00255 sp[0].value <<= "hello";
00256 sp[1].name = "pid";
00257 sp[1].value <<= client_pid;
00258
00259 expect_catch(task->BeginCPUScheduling(sp),
00260 Broker::InvalidScheduleParameter);
00261
00262 sp.length(2);
00263 sp[0].name = "deadline";
00264 sp[0].value <<= "1000";
00265 sp[1].name = "pid";
00266 sp[1].value <<= client_pid;
00267
00268 expect_catch(task->BeginCPUScheduling(sp),
00269 Broker::MissingScheduleParameter);
00270
00271 sp.length(2);
00272 sp[0].name = "period";
00273 sp[0].value <<= "1000";
00274
00275 task->BeginCPUScheduling(sp);
00276
00277
00278 expect_catch(task->BeginCPUScheduling(sp),
00279 CORBA::BAD_INV_ORDER);
00280
00281
00282 rtt->SetComputeTime(250);
00283
00284 expect_catch(rtt->SetComputeTime(100000), CORBA::BAD_PARAM);
00285
00286 assert(rtt->GetComputeTime() == 250);
00287
00288 task->EndCPUScheduling();
00289
00290
00291 expect_catch(task->EndCPUScheduling(), CORBA::BAD_INV_ORDER);
00292
00293 }
00294 catch(const CORBA::UserException &e)
00295 {
00296 cerr << e << endl;
00297 retval = EXIT_FAILURE;
00298 }
00299 catch(const CORBA::SystemException &e)
00300 {
00301 cerr << e << endl;
00302 retval = EXIT_FAILURE;
00303 }
00304 catch(...)
00305 {
00306 cerr << "Caught an unknown exception" << endl;
00307 retval = EXIT_FAILURE;
00308 }
00309 return( retval );
00310 }