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

basic_test.cc

Go to the documentation of this file.
00001 /*
00002  * basic_test.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 basic_test.cc
00014  *
00015  * Test the 'basic' qosket.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #if !defined(DEBUG)
00021 #define DEBUG 1
00022 #endif
00023 
00024 #include <assert_pp.h>
00025 
00026 #include <timesFile.h>
00027 
00028 #include <iostream>
00029 
00030 #include <rk_stub.h>
00031 
00032 #include <RealTimeTaskImpl.hh>
00033 #include <ManagerImpl.hh>
00034 #include <BasicDelegate.hh>
00035 #include <StrictPolicyImpl.hh>
00036 
00037 #include <BasicTaskKernelImpl.h>
00038 
00039 #include <StubBasicTaskQosket.hh>
00040 #include <StrictPolicyCallbackImpl.hh>
00041 
00042 /**
00043  * Evaluate the given contract and check that it is in the expected region.
00044  *
00045  * @param contract The contract to evaluate/check.
00046  * @param expected_name The expected region name.
00047  * @return True if the contract is in the expected region, false otherwise.
00048  */
00049 static int contract_region(quo::Contract_ptr contract,
00050                            const char *expected_name)
00051 {
00052     quo::strings_var result;
00053     unsigned int lpc;
00054     int retval = 0;
00055 
00056     require(contract != NULL);
00057     require(expected_name != NULL);
00058 
00059     contract->eval();
00060     
00061     result = contract->getCurrentRegionName();
00062     for( lpc = 0; lpc < result->length(); lpc++ )
00063     {
00064         if( strcmp(result[lpc], expected_name) == 0 )
00065         {
00066             retval = 1;
00067         }
00068     }
00069     
00070     return( retval );
00071 }
00072 
00073 int main(int argc, char *argv[])
00074 {
00075     int retval = 0;
00076 
00077     rk_stub_set_mode(RK_STUB_LOG);
00078 
00079 #if defined(HAVE_ACE)
00080     /* Put a sock in ACE */
00081     ACE_Log_Msg::instance()->priority_mask(0, ACE_Log_Msg::PROCESS);
00082 #endif
00083 
00084     /* ORB/POA setup */
00085     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00086     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00087     
00088     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
00089     PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00090     mgr->activate();
00091 
00092     /* QuoKernel setup */
00093     Qosket::Basic::BasicTaskKernelImpl *btki;
00094     quo::QuoKernel_var qk;
00095 
00096     btki = new Qosket::Basic::BasicTaskKernelImpl(orb);
00097     qk = btki->_this();
00098 
00099     /* Build the qosket */
00100     StubBasicTaskQosket *btqi;
00101     quo::Contract_var contract;
00102     quo::ValueSC_var last_status;
00103 
00104     btqi = new StubBasicTaskQosket();
00105     btqi->initSysconds(qk);
00106     btqi->initCallbacks(orb);
00107     contract = btqi->initContract(qk);
00108 
00109     last_status = btqi->LastStatus();
00110 
00111     /* Evaluate the contract under initial conditions. */
00112     assert(contract_region(contract.in(), "OnTime"));
00113     /* Check that the callback was called. */
00114     assert(btqi->btq_Callback->btc_Missed == 0);
00115     assert(btqi->btq_Callback->btc_Made == 1);
00116 
00117     /* Report a late status and */
00118     last_status->longValue(11);
00119 
00120 #if 0
00121     /* ... check that the contract switches to the 'Late' region */
00122     assert(contract_region(contract.in(), "Late"));
00123     assert(btqi->btq_Callback->btc_Missed == 1);
00124     assert(btqi->btq_Callback->btc_Made == 1);
00125 
00126     /* Report an on time status and */
00127     last_status->longValue(10);
00128 
00129     /* ... check that the contract switches back to the 'OnTime' region. */
00130     assert(contract_region(contract.in(), "OnTime"));
00131     assert(btqi->btq_Callback->btc_Missed == 1);
00132     assert(btqi->btq_Callback->btc_Made == 2);
00133 #endif
00134     
00135     /* Create some input files for each process to be simulated. */
00136     assert(tfMakeTimesFile("c1_cpu_times",
00137                            (const float[]){
00138         55.0, /*
00139                * repeatedly require 55% of the CPU for task one to meet the
00140                * deadline
00141                */
00142         /* Add more values here to change the sequence of CPU requirements */
00143         TIMES_FILE_TERMINATOR
00144     }));
00145     
00146     /* Broker setup */
00147     Broker::Manager_var manager;
00148     ManagerImpl *mi;
00149 
00150     mi = new ManagerImpl("dummy");
00151     manager = mi->_this();
00152 
00153     BrokerPolicies::StrictPolicy_var policy;
00154     StrictPolicyImpl *spi;
00155 
00156     spi = new StrictPolicyImpl("StrictPolicy");
00157     policy = spi->_this();
00158 
00159     Qosket::StrictPolicy::StrictPolicyCallback_var spc;
00160     StrictPolicyCallbackImpl *spci;
00161 
00162     spci = new StrictPolicyCallbackImpl(policy.in());
00163     spc = spci->_this();
00164     
00165     mi->CurrentPolicy(policy.in());
00166 
00167     BasicDelegate c1("c1", 10000, 10000);
00168 
00169     /* Make the tasks/advocates */
00170     RealTimeTaskImpl *rtti;
00171 
00172     /* ... for process one */
00173     rtti = new RealTimeTaskImpl(c1.bd_TaskDescription); 
00174     c1.bd_Advocate = Broker::RealTimeTask::_narrow(rtti->_this());
00175     assert(!CORBA::is_nil(c1.bd_Advocate.in()));
00176     manager->AddTask(c1.bd_Advocate.in(), c1.bd_CPUSchedule);
00177 
00178     assert(spc->GetPriorityOf("c1") == 0);
00179     
00180     spc->SetPriorityOf("c1", 5);
00181     
00182     assert(spc->GetPriorityOf("c1") == 5);
00183 
00184     try
00185     {
00186         spc->GetPriorityOf("c2");
00187 
00188         ensure(0);
00189     }
00190     catch(const CORBA::BAD_PARAM &e)
00191     {
00192     }
00193     
00194     return( retval );
00195 }

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