- Fix compilation of test-python_loader (which doesn't f*ckin' work).

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@781 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-19 14:48:53 +00:00
parent 984d390f3f
commit 95ef5eba53
3 changed files with 52 additions and 33 deletions

View File

@ -25,8 +25,10 @@
#include "../python_policy_manager.hh" #include "../python_policy_manager.hh"
#include "../python_policy.hh" #include "../python_policy.hh"
#include "simulation.hh"
#include "global_preferences.hh" #include "global_preferences.hh"
#include "ready_queue.hh" #include "policies_gatekeeper.hh"
#include "simulation.hh"
#include "scheduler.hh" #include "scheduler.hh"
#include "user_interrupt_exception.hh" #include "user_interrupt_exception.hh"
@ -37,51 +39,59 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
// FIXME: Eeeeh? Why does this work without explicit namespace resolving? using namespace sgpem;
// Is there some using declaration in included HEADERS?? Aaaaagh! using namespace std;
class TestPythonPolicyManager : public PythonPolicyManager static Policy*
find_pol_by_name(const vector<Policy*>& pols, const Glib::ustring& name)
{ {
public: vector<Policy*>::const_iterator it = pols.begin();
void test_init(const char* policy_name) for( ; it != pols.end(); it++)
{ if((*it)->get_name() == name)
init(); return *it;
_python_policy = new PythonPolicy(policy_name); return NULL;
} }
Policy& get_policy()
{
return *_python_policy;
}
};
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
using namespace sgpem;
using namespace std;
int successes = 0; int successes = 0;
if(argc != 2) if(argc != 2)
{ {
std::cout << "[EE] Usage:\n\t" << argv[0] << std::cout << "[EE] Usage:\n\t" << argv[0] <<
" path/to/uninstalled/policies" << std::endl; " path/to/uninstalled/test/policies" << std::endl;
exit(-1); exit(-1);
} }
else else
// Add argv[1] as the directory to search for uninstalled policies // Add argv[1] as the directory to search for uninstalled policies
sgpem::GlobalPreferences::get_instance().add_policies_dir(argv[1]); sgpem::GlobalPreferences::get_instance().add_policies_dir(argv[1]);
// Self-register itself to Scheduler, however we don't care about it // Self-register itself to PoliciesGatekeeper, however we don't care about it
TestPythonPolicyManager polman; PythonPolicyManager polman;
Simulation& sim = Simulation::get_instance();
History& his = sim.get_history();
PoliciesGatekeeper& pgk = PoliciesGatekeeper::get_instance();
const std::vector<Policy*>& policies = polman.get_avail_policies();
// Print out avail policies
cout << "These are the policies I found:" << endl;
vector<Policy*>::const_iterator it = policies.begin();
for(; it != policies.end(); it++)
cout << "\t * " << (*it)->get_name() << endl;
try try
{ {
polman.test_init("python_loader_configure"); Policy* pol = find_pol_by_name(policies, "python_loader_configure");
polman.get_policy().configure(); assert(pol != NULL);
// FIXME : Maybe activating a policy only to configure it is an overkill?
// Who gives a fuck about it?
pgk.activate_policy(&his, pol);
pol->configure();
} }
catch(UserInterruptException e) catch(UserInterruptException e)
{ {
@ -92,8 +102,10 @@ main(int argc, char** argv)
try try
{ {
polman.test_init("python_loader_is_preemptive"); Policy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
polman.get_policy().is_pre_emptive(); assert(pol != NULL);
pgk.activate_policy(&his, pol);
pol->is_pre_emptive();
} }
catch(UserInterruptException e) catch(UserInterruptException e)
{ {
@ -101,10 +113,13 @@ main(int argc, char** argv)
successes++; successes++;
} }
try try
{ {
polman.test_init("python_loader_get_time_slice"); Policy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
polman.get_policy().get_time_slice(); assert(pol != NULL);
pgk.activate_policy(&his, pol);
pol->get_time_slice();
} }
catch(UserInterruptException e) catch(UserInterruptException e)
{ {
@ -113,11 +128,13 @@ main(int argc, char** argv)
} }
try try
{ {
ReadyQueue sl; Policy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
polman.test_init("python_loader_sort_queue"); assert(pol != NULL);
polman.get_policy().sort_queue(); pgk.activate_policy(&his, pol);
pol->sort_queue();
} }
catch(UserInterruptException e) catch(UserInterruptException e)
{ {

View File

@ -46,7 +46,7 @@ using memory::smart_ptr;
// --------------- // ---------------
// For all your evil-doers on Earth, this is your punishment! // For all you evil-doers on Earth, this is your mighty punishment!
template<typename T> template<typename T>
static bool deep_remove(std::vector<T*>& v, const T& obj) static bool deep_remove(std::vector<T*>& v, const T& obj)

View File

@ -23,6 +23,8 @@
#include "policies_gatekeeper.hh" #include "policies_gatekeeper.hh"
#include <glibmm/timer.h> #include <glibmm/timer.h>
#include <cassert>
#include "smartp.tcc" #include "smartp.tcc"
using namespace std; using namespace std;