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

all_test1.cc

Go to the documentation of this file.
00001 /*
00002  * all_test1.cc
00003  *
00004  * Copyright (c) 2003, 2004 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 all_test1.cc
00014  *
00015  * An all-up test of the CPU broker components.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #if !defined(DEBUG)
00021 #define DEBUG 1
00022 #endif
00023 
00024 #include <stdlib.h>
00025 
00026 #include <assert.h>
00027 #include <assert_pp.h>
00028 
00029 #include <timesFile.h>
00030 
00031 #include <rk.h>
00032 #include <rk_stub.h>
00033 
00034 #include <iostream>
00035 
00036 #include <BrokerC.h>
00037 #include <StrictPolicyC.h>
00038 
00039 #include <ManagerImpl.hh>
00040 #include <BasicDelegate.hh>
00041 #include <RealTimeTaskImpl.hh>
00042 
00043 #include <StrictPolicyImpl.hh>
00044 
00045 #include <LoggingAdvocate.hh>
00046 #include <MaxDecayTaskAdvocate.hh>
00047 #include <GlacialTaskAdvocate.hh>
00048 
00049 int main(int argc, char *argv[])
00050 {
00051     int retval = EXIT_SUCCESS;
00052 
00053     /* Initialize the simulator */
00054     rk_stub_set_mode(RK_STUB_SIM);
00055 
00056 #if defined(HAVE_ACE)
00057     /* Put a sock in ACE */
00058     ACE_Log_Msg::instance()->priority_mask(0, ACE_Log_Msg::PROCESS);
00059 #endif
00060 
00061     /* ORB/POA setup */
00062     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00063     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00064     
00065     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
00066     PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00067     mgr->activate();
00068 
00069     /* Create some input files for each process to be simulated. */
00070     assert(tfMakeTimesFile("c1_cpu_times",
00071                            (const float[]){
00072         55.0, /*
00073                * repeatedly require 55% of the CPU for task one to meet the
00074                * deadline
00075                */
00076         /* Add more values here to change the sequence of CPU requirements */
00077         TIMES_FILE_TERMINATOR
00078     }));
00079     assert(tfMakeTimesFile("c2_cpu_times",
00080                            (const float[]){
00081         20.0, /* ... 20% for task two */
00082         TIMES_FILE_TERMINATOR
00083     }));
00084     assert(tfMakeTimesFile("c3_cpu_times",
00085                            (const float[]){
00086         20.0, /* ... 20% for task three */
00087         TIMES_FILE_TERMINATOR
00088     }));
00089 
00090     /* Broker setup */
00091     Broker::Manager_var manager;
00092     ManagerImpl *mi;
00093 
00094     mi = new ManagerImpl("dummy");
00095     manager = mi->_this();
00096 
00097     BrokerPolicies::StrictPolicy_var policy;
00098     StrictPolicyImpl *spi;
00099 
00100     spi = new StrictPolicyImpl("StrictPolicy");
00101     policy = spi->_this();
00102 
00103     mi->CurrentPolicy(policy.in());
00104 
00105     BasicDelegate c1("c1", 10000, 10000);
00106 
00107     /* Make the delegates and, in turn, the fake processes. */
00108     BasicDelegate c2("c2", 20000, 20000);
00109     BasicDelegate c3("c3", 10000, 10000);
00110 
00111     /* Make the tasks/advocates */
00112     RealTimeTaskDelegateImpl *rttdi;
00113     RealTimeTaskImpl *rtti;
00114 
00115     /* ... for process one */
00116     rtti = new RealTimeTaskImpl(c1.bd_TaskDescription); 
00117     c1.bd_Advocate = Broker::RealTimeTask::_narrow(rtti->_this());
00118     assert(!CORBA::is_nil(c1.bd_Advocate.in()));
00119     manager->AddTask(c1.bd_Advocate.in(), c1.bd_CPUSchedule);
00120 
00121     /* ... for process two */
00122     rtti = new RealTimeTaskImpl(c2.bd_TaskDescription);
00123     c2.bd_Advocate = Broker::RealTimeTask::_narrow(rtti->_this());
00124     assert(!CORBA::is_nil(c2.bd_Advocate.in()));
00125     manager->AddTask(c2.bd_Advocate.in(), c2.bd_CPUSchedule);
00126 
00127     /* ... for process three */
00128     rtti = new RealTimeTaskImpl(c3.bd_TaskDescription);
00129     rttdi = new GlacialTaskAdvocate();
00130     rttdi->SetDelegateAttributeObject("remote-object", rtti->_this());
00131     c3.bd_Advocate = Broker::RealTimeTask::_narrow(rttdi->_this());
00132     assert(!CORBA::is_nil(c3.bd_Advocate.in()));
00133     manager->AddTask(c3.bd_Advocate.in(), c3.bd_CPUSchedule);
00134 
00135     /* Start the simulation. */
00136     struct timespec curr, end = { 1, 0 };
00137 
00138     /* ... stage one, all the same priority */
00139     do {
00140         rk_stub_next_tick();
00141         rk_clock_gettime(CLOCK_REALTIME, &curr);
00142     } while( curr.tv_sec < end.tv_sec );
00143 
00144     /* ... stage two, bump process two's priority */
00145     policy->SetTaskPriority(c2.bd_Advocate.in(), 1);
00146 
00147     end.tv_sec = 2;
00148     
00149     do {
00150         rk_stub_next_tick();
00151         rk_clock_gettime(CLOCK_REALTIME, &curr);
00152     } while( curr.tv_sec < end.tv_sec );
00153 
00154     /* ... stage three, bump process three's priority */
00155     policy->SetTaskPriority(c3.bd_Advocate.in(), 1);
00156 
00157     end.tv_sec = 3;
00158     
00159     do {
00160         rk_stub_next_tick();
00161         rk_clock_gettime(CLOCK_REALTIME, &curr);
00162     } while( curr.tv_sec < end.tv_sec );
00163 
00164     /* ... stage four, bump process one's priority past the others */
00165     policy->SetTaskPriority(c1.bd_Advocate.in(), 2);
00166 
00167     end.tv_sec = 4;
00168     
00169     do {
00170         rk_stub_next_tick();
00171         rk_clock_gettime(CLOCK_REALTIME, &curr);
00172     } while( curr.tv_sec < end.tv_sec );
00173     
00174     return( retval );
00175 }

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