Vogon Fleet: implementation: Added environment, concrete_environment, a
placeholder for the ready queue, needed by environment, and factorized stubs for tests in a separate directory. Updated makefile including environment, concrete_environment, ready_queue, but NOT the stubs and/or the tests. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@685 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
36f62cbb8d
commit
53da6e4bb8
13 changed files with 1198 additions and 1 deletions
113
src/testsuite/stubs/history.cc
Normal file
113
src/testsuite/stubs/history.cc
Normal file
|
@ -0,0 +1,113 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
#include "history.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||
History::get_scheduled_at(int time) const
|
||||
{
|
||||
using namespace memory;
|
||||
smart_ptr<DynamicSchedulable> scheduled_at = smart_ptr<DynamicSchedulable>();
|
||||
if (0 <= time && time <= _total_time_elapsed)
|
||||
{
|
||||
smart_ptr<SchedulableQueue> sl = get_simulation_status_at(time);
|
||||
bool found = false;
|
||||
bool invalid = sl == smart_ptr<SchedulableQueue>();
|
||||
for (uint i = 0; !found && !invalid && i < sl->size(); i++)
|
||||
{
|
||||
const DynamicSchedulable* ss = sl->get_item_at(i);
|
||||
if ((bool)ss && ss->get_state() == DynamicSchedulable::state_running)
|
||||
{
|
||||
scheduled_at = smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(ss)));
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scheduled_at;
|
||||
}
|
||||
|
||||
|
||||
memory::smart_ptr<sgpem::SchedulableQueue>
|
||||
History::get_simulation_status_at(int time) const
|
||||
{
|
||||
using namespace memory;
|
||||
smart_ptr<SchedulableQueue> simulation_status_at = smart_ptr<SchedulableQueue>();
|
||||
if (0 <= time && time <= _total_time_elapsed)
|
||||
{
|
||||
if (_slice == memory::smart_ptr<Slice>())
|
||||
std::cout<<"History::get_simulation_status_at.NULL.error";
|
||||
else
|
||||
simulation_status_at = memory::smart_ptr<SchedulableQueue>
|
||||
(
|
||||
new SchedulableQueue
|
||||
(
|
||||
*(_slice->get_simulation_status())
|
||||
)
|
||||
);
|
||||
}
|
||||
return simulation_status_at;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
History::get_current_time() const
|
||||
{
|
||||
return _total_time_elapsed;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
History::enqueue_slice(const sgpem::SchedulableQueue& status)
|
||||
{
|
||||
_slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status));
|
||||
_total_time_elapsed++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
History::truncate_at(int instant)
|
||||
{
|
||||
//std::cout << "\nRecreating a Singleton History";
|
||||
_slice = memory::smart_ptr<Slice>();
|
||||
_total_time_elapsed = -1;
|
||||
}
|
||||
|
||||
|
||||
History&
|
||||
History::get_instance()
|
||||
{
|
||||
if (History::_instance == NULL)
|
||||
History::_instance = new History();
|
||||
return *History::_instance;
|
||||
}
|
||||
|
||||
|
||||
History::History()
|
||||
{
|
||||
_slice = memory::smart_ptr<Slice>();
|
||||
_total_time_elapsed = -1;
|
||||
}
|
||||
|
||||
|
||||
History * History::_instance = NULL;
|
111
src/testsuite/stubs/history.hh
Normal file
111
src/testsuite/stubs/history.hh
Normal file
|
@ -0,0 +1,111 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
#ifndef HISTORY_HH
|
||||
#define HISTORY_HH 1
|
||||
|
||||
#include "backend/observed_subject.hh"
|
||||
#include "backend/slice.hh"
|
||||
#include "backend/schedulable_queue.hh"
|
||||
#include "templates/smartp.tcc"
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
#include <glibmm/module.h> // ??
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
#include "glibmm/ustring.h"
|
||||
#include <vector>
|
||||
|
||||
#include "backend/static_process.hh"
|
||||
|
||||
|
||||
#include "backend/dynamic_schedulable.hh"
|
||||
|
||||
#include "backend/user_interrupt_exception.hh"
|
||||
#include "backend/policy.hh"
|
||||
|
||||
#include "prrpolicy.cc"
|
||||
#include <iostream>
|
||||
*/
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
/** an History stub, should only save the last state included.
|
||||
*/
|
||||
class History : public ObservedSubject
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/** Returns the DynamicSchedulable of the schedulable
|
||||
* which was running at the time, if any.
|
||||
*/
|
||||
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||
get_scheduled_at(int time) const;
|
||||
|
||||
|
||||
/** Returns the last recorded instant, but may raise an error.
|
||||
*/
|
||||
memory::smart_ptr<sgpem::SchedulableQueue>
|
||||
get_simulation_status_at(int time) const;
|
||||
|
||||
|
||||
/** Returns the total time recorded.
|
||||
*/
|
||||
int
|
||||
get_current_time() const;
|
||||
|
||||
|
||||
/** Extends the recorded history by one unit, overwriting the old value
|
||||
*/
|
||||
void
|
||||
enqueue_slice(const sgpem::SchedulableQueue& status);
|
||||
|
||||
|
||||
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
||||
*/
|
||||
void
|
||||
truncate_at(int instant);
|
||||
|
||||
|
||||
/** Returns the singleton instance.
|
||||
*/
|
||||
static History&
|
||||
get_instance();
|
||||
|
||||
|
||||
private:
|
||||
History();
|
||||
|
||||
static History * _instance;
|
||||
int _total_time_elapsed;
|
||||
memory::smart_ptr<Slice> _slice;
|
||||
};
|
||||
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
||||
#endif
|
53
src/testsuite/stubs/policy_manager.cc
Normal file
53
src/testsuite/stubs/policy_manager.cc
Normal file
|
@ -0,0 +1,53 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "policy_manager.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
PolicyManager::PolicyManager()
|
||||
{}
|
||||
|
||||
PolicyManager&
|
||||
PolicyManager::get_registered_manager()
|
||||
{
|
||||
if (_registered == NULL)
|
||||
_registered = new PolicyManager();
|
||||
return *_registered;
|
||||
}
|
||||
|
||||
Policy&
|
||||
PolicyManager::get_policy()
|
||||
{
|
||||
return PRRPolicy::get_instance();
|
||||
}
|
||||
|
||||
void
|
||||
PolicyManager::init()
|
||||
{}
|
||||
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
if(_registered == this) _registered = NULL;
|
||||
}
|
||||
|
||||
|
||||
PolicyManager*
|
||||
PolicyManager::_registered = NULL;
|
73
src/testsuite/stubs/policy_manager.hh
Normal file
73
src/testsuite/stubs/policy_manager.hh
Normal file
|
@ -0,0 +1,73 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef POLICY_MANAGER_HH
|
||||
#define POLICY_MANAGER_HH 1
|
||||
|
||||
#include "prrpolicy.hh"
|
||||
/*
|
||||
#include <glibmm/module.h> // ??
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
#include "glibmm/ustring.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "backend/static_process.hh"
|
||||
#include "backend/observed_subject.hh"
|
||||
#include "backend/schedulable_queue.hh"
|
||||
#include "backend/dynamic_schedulable.hh"
|
||||
#include "templates/smartp.tcc"
|
||||
#include "backend/user_interrupt_exception.hh"
|
||||
#include "backend/policy.hh"
|
||||
#include "backend/slice.hh"
|
||||
#include "prrpolicy.cc"
|
||||
#include <iostream>
|
||||
*/
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
/** A policyManager stub, provides access to the PRRPolicy.
|
||||
*/
|
||||
class PolicyManager
|
||||
{
|
||||
public:
|
||||
|
||||
PolicyManager();
|
||||
|
||||
static PolicyManager&
|
||||
get_registered_manager();
|
||||
|
||||
virtual Policy&
|
||||
get_policy();
|
||||
|
||||
virtual void
|
||||
init();
|
||||
|
||||
virtual
|
||||
~PolicyManager();
|
||||
|
||||
private:
|
||||
static PolicyManager* _registered;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
121
src/testsuite/stubs/prrpolicy.cc
Normal file
121
src/testsuite/stubs/prrpolicy.cc
Normal file
|
@ -0,0 +1,121 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "prrpolicy.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
PRRPolicy::PRRPolicy()
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
PRRPolicy::PRRPolicy(int quantum)
|
||||
: _quantum(quantum)
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
Policy&
|
||||
PRRPolicy::get_instance()
|
||||
{
|
||||
if(_instance == NULL) _instance = new PRRPolicy(3); // quantum size
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
||||
PRRPolicy::~PRRPolicy()
|
||||
{}
|
||||
|
||||
void
|
||||
PRRPolicy::configure()
|
||||
throw(UserInterruptException)
|
||||
{}
|
||||
|
||||
void
|
||||
PRRPolicy::sort_queue() const
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
SchedulableQueue* local_sl = Scheduler::get_instance().get_ready_queue();
|
||||
for (uint useless = 0; useless < local_sl->size(); useless++)
|
||||
for (uint i = 0; i < local_sl->size() - 1; i++)
|
||||
if
|
||||
(
|
||||
local_sl->get_item_at(i)->get_schedulable()->get_priority() >
|
||||
local_sl->get_item_at(i + 1)->get_schedulable()->get_priority()
|
||||
)
|
||||
local_sl->swap(i, i + 1);
|
||||
}
|
||||
|
||||
void
|
||||
PRRPolicy::activate()
|
||||
{}
|
||||
|
||||
void
|
||||
PRRPolicy::deactivate()
|
||||
{}
|
||||
|
||||
int
|
||||
PRRPolicy::get_id() const
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
sgpem::policy_sorts_type
|
||||
PRRPolicy::wants() const
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return policy_sorts_processes;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
PRRPolicy::get_name() const
|
||||
{
|
||||
return "42";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
PRRPolicy::get_description() const
|
||||
{
|
||||
return "42";
|
||||
}
|
||||
|
||||
bool
|
||||
PRRPolicy::is_pre_emptive() const
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
PRRPolicy::get_time_slice() const
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return _quantum;
|
||||
}
|
||||
|
||||
PolicyParameters&
|
||||
PRRPolicy::get_parameters()
|
||||
{
|
||||
return _parameters;
|
||||
}
|
||||
|
||||
Policy*
|
||||
PRRPolicy::_instance = NULL;
|
129
src/testsuite/stubs/prrpolicy.hh
Normal file
129
src/testsuite/stubs/prrpolicy.hh
Normal file
|
@ -0,0 +1,129 @@
|
|||
// src/testsuite/test-stepforward.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef PRRPOLICY_HH
|
||||
#define PRRPOLICY_HH 1
|
||||
|
||||
#include "backend/policy.hh"
|
||||
#include "backend/user_interrupt_exception.hh"
|
||||
#include "backend/schedulable_queue.hh"
|
||||
#include "backend/scheduler.hh"
|
||||
#include "glibmm/ustring.h"
|
||||
|
||||
/*
|
||||
#include <string>
|
||||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "backend/static_process.hh"
|
||||
#include "backend/observed_subject.hh"
|
||||
|
||||
#include "backend/dynamic_schedulable.hh"
|
||||
#include "templates/smartp.tcc"
|
||||
#include "backend/user_interrupt_exception.hh"
|
||||
|
||||
#include "backend/slice.hh"
|
||||
|
||||
#include <iostream>
|
||||
*/
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
/** An hard-coded Priority Round Robin policy
|
||||
* It's actually called PRRPolicy, altough my personal taste would have suggested
|
||||
* naming it
|
||||
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
|
||||
* i.e. PRRRRRRR-Policy.
|
||||
* it adds a new constructor taking the quantum size (time slice)
|
||||
*/
|
||||
class PRRPolicy : public Policy
|
||||
{
|
||||
public:
|
||||
|
||||
PRRPolicy();
|
||||
|
||||
PRRPolicy(int quantum);
|
||||
|
||||
static Policy&
|
||||
get_instance();
|
||||
|
||||
virtual
|
||||
~PRRPolicy();
|
||||
|
||||
virtual void
|
||||
configure()
|
||||
throw(UserInterruptException);
|
||||
|
||||
virtual void
|
||||
sort_queue() const
|
||||
throw(UserInterruptException);
|
||||
|
||||
|
||||
virtual void
|
||||
activate();
|
||||
|
||||
virtual void
|
||||
deactivate();
|
||||
|
||||
|
||||
virtual int
|
||||
get_id() const;
|
||||
|
||||
virtual sgpem::policy_sorts_type
|
||||
wants() const
|
||||
throw(UserInterruptException);
|
||||
|
||||
|
||||
virtual Glib::ustring
|
||||
get_name() const;
|
||||
|
||||
virtual Glib::ustring
|
||||
get_description() const;
|
||||
|
||||
virtual bool
|
||||
is_pre_emptive() const
|
||||
throw(UserInterruptException);
|
||||
|
||||
virtual int
|
||||
get_time_slice() const
|
||||
throw(UserInterruptException);
|
||||
|
||||
|
||||
virtual PolicyParameters&
|
||||
get_parameters();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PolicyParameters _parameters;
|
||||
int _id;
|
||||
int _quantum;
|
||||
|
||||
private:
|
||||
|
||||
static Policy* _instance;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue