Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

rk_task_good.cc

Go to the documentation of this file.
00001 /*
00002  * rk_task_good.cc
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file rk_task_good.cc
00014  *
00015  * Test the RKTask class.
00016  */
00017 
00018 #include "config.h"
00019 
00020 /* Make sure assert is on */
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     /* ORB/POA setup */
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     /* Broker setup */
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     /* Test the constructor */
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     /* ... change CPU time outside of scheduling */
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     /* ... begin CPU scheduling */
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         /* Make sure the initial values made it all the way down to the rk. */
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         /* ... and do the same for dynamic changes. */
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     /* ... stop and */
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     /* ... restart scheduling */
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 }

Generated on Mon Dec 1 16:29:07 2003 for CPU Broker by doxygen 1.3.4