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