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

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 #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     /* ORB/POA setup */
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     /* Broker setup */
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     /* Test the constructor */
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     /* ... change CPU time outside of scheduling */
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     /* ... begin CPU scheduling */
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         /* Make sure the initial values made it all the way down to the rk. */
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         /* ... and do the same for dynamic changes. */
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     /* ... stop and */
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     /* ... restart scheduling */
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 }

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1