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