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 #undef NDEBUG
00024 #endif
00025
00026 #include <assert.h>
00027 #include <assert_pp.h>
00028
00029 #include <time_util.h>
00030 #include <timesFile.h>
00031
00032 #include <rk_stub.h>
00033
00034 #include <iostream>
00035
00036 #include <RKTask.hh>
00037 #include <ManagerImpl.hh>
00038
00039 int main(int argc, char *argv[])
00040 {
00041 int retval = 0;
00042
00043 rk_stub_set_mode(RK_STUB_SIM);
00044
00045 assert(tfMakeTimesFile("test_cpu_times",
00046 (const float[]){ 50.0, TIMES_FILE_TERMINATOR }));
00047
00048
00049 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00050 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00051
00052 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
00053 PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00054 mgr->activate();
00055
00056
00057 Broker::ScheduleParameters sp;
00058 Broker::RealTimeTask_var rtt;
00059 Broker::Manager_var manager;
00060 Broker::TaskParameters tp;
00061 Broker::Task_var task;
00062 pid_t client_pid;
00063
00064 client_pid = rk_stub_mk_pid("foo", NULL, NULL, NULL);
00065
00066 ManagerImpl *mi = new ManagerImpl("manager");
00067
00068 manager = mi->_this();
00069
00070
00071 tp.length(1);
00072 tp[0].name = "name";
00073 tp[0].value <<= "test";
00074
00075 RKTask *rkt = new RKTask(tp);
00076
00077 task = rkt->_this();
00078 rtt = Broker::RealTimeTask::_narrow(task.in());
00079 assert(!CORBA::is_nil(rtt.in()));
00080
00081
00082 assert(rtt->GetComputeTime() != 0);
00083 rtt->SetComputeTime(250);
00084 assert(rtt->GetComputeTime() == 250);
00085
00086 sp.length(2);
00087 sp[0].name = "period";
00088 sp[0].value <<= "1000";
00089 sp[1].name = "pid";
00090 sp[1].value <<= client_pid;
00091
00092 rtt->SetManager(manager.in());
00093
00094
00095 rtt->BeginCPUScheduling(sp);
00096
00097 assert(rtt->Period() == 1000);
00098 assert(rtt->Deadline() == 1000);
00099 assert(rtt->GetComputeTime() == 250);
00100
00101 {
00102 struct cpu_reserve_attr cra;
00103 rk_resource_set_t rs;
00104 rk_reserve_t cr;
00105
00106
00107 assert((rs = rk_proc_get_rset(client_pid)) != NULL);
00108 cr = rk_resource_set_get_cpu_rsv(rs);
00109 rk_cpu_reserve_get_attr(cr, &cra);
00110 assert(timespec_to_microsec(&cra.period) == 1000);
00111 assert(timespec_to_microsec(&cra.deadline) == 1000);
00112 assert(timespec_to_microsec(&cra.compute_time) == 250);
00113
00114
00115 rtt->SetComputeTime(500);
00116 assert(rtt->GetComputeTime() == 500);
00117 rk_cpu_reserve_get_attr(cr, &cra);
00118 assert(timespec_to_microsec(&cra.compute_time) == 500);
00119 rtt->SetComputeTime(250);
00120 }
00121
00122
00123 rtt->EndCPUScheduling();
00124
00125 assert(rtt->GetComputeTime() == 250);
00126
00127 sp.length(3);
00128 sp[0].name = "period";
00129 sp[0].value <<= "1000";
00130 sp[1].name = "deadline";
00131 sp[1].value <<= "500";
00132 sp[2].name = "pid";
00133 sp[2].value <<= client_pid;
00134
00135
00136 rtt->BeginCPUScheduling(sp);
00137
00138 assert(rtt->GetComputeTime() == 250);
00139 assert(rtt->Period() == 1000);
00140 assert(rtt->Deadline() == 500);
00141
00142 rtt->EndCPUScheduling();
00143
00144 return( retval );
00145 }