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

basic_test.cc

Go to the documentation of this file.
00001 /*
00002  * basic_test.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 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 <iostream>
00027 
00028 #include <rk_stub.h>
00029 
00030 #include <BasicTaskKernelImpl.h>
00031 
00032 #include <StubBasicTaskQosket.hh>
00033 
00034 /**
00035  * Evaluate the given contract and check that it is in the expected region.
00036  *
00037  * @param contract The contract to evaluate/check.
00038  * @param expected_name The expected region name.
00039  * @return True if the contract is in the expected region, false otherwise.
00040  */
00041 static int contract_region(quo::Contract_ptr contract,
00042                            const char *expected_name)
00043 {
00044     quo::strings_var result;
00045     unsigned int lpc;
00046     int retval = 0;
00047 
00048     require(contract != NULL);
00049     require(expected_name != NULL);
00050 
00051     contract->eval();
00052     
00053     result = contract->getCurrentRegionName();
00054     for( lpc = 0; lpc < result->length(); lpc++ )
00055     {
00056         if( strcmp(result[lpc], expected_name) == 0 )
00057         {
00058             retval = 1;
00059         }
00060     }
00061     
00062     return( retval );
00063 }
00064 
00065 int main(int argc, char *argv[])
00066 {
00067     int retval = 0;
00068 
00069     rk_stub_set_mode(RK_STUB_LOG);
00070 
00071 #if defined(HAVE_ACE)
00072     /* Put a sock in ACE */
00073     ACE_Log_Msg::instance()->priority_mask(0, ACE_Log_Msg::PROCESS);
00074 #endif
00075 
00076     /* ORB/POA setup */
00077     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00078     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00079     
00080     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
00081     PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00082     mgr->activate();
00083 
00084     /* QuoKernel setup */
00085     Qosket::Basic::BasicTaskKernelImpl *btki;
00086     quo::QuoKernel_var qk;
00087 
00088     btki = new Qosket::Basic::BasicTaskKernelImpl(orb);
00089     qk = btki->_this();
00090 
00091     /* Build the qosket */
00092     StubBasicTaskQosket *btqi;
00093     quo::Contract_var contract;
00094     quo::ValueSC_var last_status;
00095 
00096     btqi = new StubBasicTaskQosket();
00097     btqi->initSysconds(qk);
00098     btqi->initCallbacks(orb);
00099     contract = btqi->initContract(qk);
00100 
00101     last_status = btqi->LastStatus();
00102 
00103     /* Evaluate the contract under initial conditions. */
00104     assert(contract_region(contract.in(), "OnTime"));
00105     /* Check that the callback was called. */
00106     assert(btqi->btq_Callback->btc_Missed == 0);
00107     assert(btqi->btq_Callback->btc_Made == 1);
00108 
00109     /* Report a late status and */
00110     last_status->longValue(11);
00111 
00112 #if 0
00113     /* ... check that the contract switches to the 'Late' region */
00114     assert(contract_region(contract.in(), "Late"));
00115     assert(btqi->btq_Callback->btc_Missed == 1);
00116     assert(btqi->btq_Callback->btc_Made == 1);
00117 
00118     /* Report an on time status and */
00119     last_status->longValue(10);
00120 
00121     /* ... check that the contract switches back to the 'OnTime' region. */
00122     assert(contract_region(contract.in(), "OnTime"));
00123     assert(btqi->btq_Callback->btc_Missed == 1);
00124     assert(btqi->btq_Callback->btc_Made == 2);
00125 #endif
00126     
00127     return( retval );
00128 }

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