- Give code a round of indentation. Thank astyle, not me.
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@837 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
aaf8e068d3
commit
d3c7b46853
108 changed files with 3196 additions and 3180 deletions
|
@ -24,90 +24,90 @@
|
|||
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<ReadyQueue> sl = get_simulation_status_at(time);
|
||||
bool found = false;
|
||||
bool invalid = sl == smart_ptr<ReadyQueue>();
|
||||
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::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<ReadyQueue> sl = get_simulation_status_at(time);
|
||||
bool found = false;
|
||||
bool invalid = sl == smart_ptr<ReadyQueue>();
|
||||
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::ReadyQueue>
|
||||
History::get_simulation_status_at(int time) const
|
||||
{
|
||||
using namespace memory;
|
||||
smart_ptr<ReadyQueue> simulation_status_at = smart_ptr<ReadyQueue>();
|
||||
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<ReadyQueue>
|
||||
(
|
||||
new ReadyQueue
|
||||
(
|
||||
*(_slice->get_simulation_status())
|
||||
)
|
||||
);
|
||||
}
|
||||
return simulation_status_at;
|
||||
}
|
||||
memory::smart_ptr<sgpem::ReadyQueue>
|
||||
History::get_simulation_status_at(int time) const
|
||||
{
|
||||
using namespace memory;
|
||||
smart_ptr<ReadyQueue> simulation_status_at = smart_ptr<ReadyQueue>();
|
||||
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<ReadyQueue>
|
||||
(
|
||||
new ReadyQueue
|
||||
(
|
||||
*(_slice->get_simulation_status())
|
||||
)
|
||||
);
|
||||
}
|
||||
return simulation_status_at;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
History::get_current_time() const
|
||||
{
|
||||
return _total_time_elapsed;
|
||||
}
|
||||
int
|
||||
History::get_current_time() const
|
||||
{
|
||||
return _total_time_elapsed;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
History::enqueue_slice(const sgpem::ReadyQueue& status)
|
||||
{
|
||||
_slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status));
|
||||
_total_time_elapsed++;
|
||||
}
|
||||
void
|
||||
History::enqueue_slice(const sgpem::ReadyQueue& 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;
|
||||
}
|
||||
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::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()
|
||||
{
|
||||
_slice = memory::smart_ptr<Slice>();
|
||||
_total_time_elapsed = -1;
|
||||
}
|
||||
|
||||
|
||||
History * History::_instance = NULL;
|
||||
History * History::_instance = NULL;
|
||||
|
|
|
@ -52,58 +52,58 @@
|
|||
namespace sgpem
|
||||
{
|
||||
|
||||
/** an History stub, should only save the last state included.
|
||||
/** 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.
|
||||
*/
|
||||
class History : public ObservedSubject
|
||||
{
|
||||
|
||||
public:
|
||||
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||
get_scheduled_at(int time) const;
|
||||
|
||||
|
||||
/** 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::ReadyQueue>
|
||||
get_simulation_status_at(int time) const;
|
||||
|
||||
|
||||
/** Returns the last recorded instant, but may raise an error.
|
||||
*/
|
||||
memory::smart_ptr<sgpem::ReadyQueue>
|
||||
get_simulation_status_at(int time) const;
|
||||
/** Returns the total time recorded.
|
||||
*/
|
||||
int
|
||||
get_current_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::ReadyQueue& status);
|
||||
|
||||
|
||||
/** Extends the recorded history by one unit, overwriting the old value
|
||||
*/
|
||||
void
|
||||
enqueue_slice(const sgpem::ReadyQueue& status);
|
||||
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
||||
*/
|
||||
void
|
||||
truncate_at(int instant);
|
||||
|
||||
|
||||
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
||||
*/
|
||||
void
|
||||
truncate_at(int instant);
|
||||
/** Returns the singleton instance.
|
||||
*/
|
||||
static History&
|
||||
get_instance();
|
||||
|
||||
|
||||
/** Returns the singleton instance.
|
||||
*/
|
||||
static History&
|
||||
get_instance();
|
||||
private:
|
||||
History();
|
||||
|
||||
|
||||
private:
|
||||
History();
|
||||
|
||||
static History * _instance;
|
||||
int _total_time_elapsed;
|
||||
memory::smart_ptr<Slice> _slice;
|
||||
};
|
||||
static History * _instance;
|
||||
int _total_time_elapsed;
|
||||
memory::smart_ptr<Slice> _slice;
|
||||
};
|
||||
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
|
@ -28,24 +28,24 @@ PolicyManager::PolicyManager()
|
|||
PolicyManager&
|
||||
PolicyManager::get_registered_manager()
|
||||
{
|
||||
if (_registered == NULL)
|
||||
_registered = new PolicyManager();
|
||||
return *_registered;
|
||||
if (_registered == NULL)
|
||||
_registered = new PolicyManager();
|
||||
return *_registered;
|
||||
}
|
||||
|
||||
Policy&
|
||||
Policy&
|
||||
PolicyManager::get_policy()
|
||||
{
|
||||
return PRRPolicy::get_instance();
|
||||
return PRRPolicy::get_instance();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
PolicyManager::init()
|
||||
{}
|
||||
|
||||
PolicyManager::~PolicyManager()
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
if(_registered == this) _registered = NULL;
|
||||
if (_registered == this) _registered = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,29 +45,29 @@
|
|||
|
||||
namespace sgpem
|
||||
{
|
||||
/** A policyManager stub, provides access to the PRRPolicy.
|
||||
*/
|
||||
class PolicyManager
|
||||
{
|
||||
public:
|
||||
/** A policyManager stub, provides access to the PRRPolicy.
|
||||
*/
|
||||
class PolicyManager
|
||||
{
|
||||
public:
|
||||
|
||||
PolicyManager();
|
||||
PolicyManager();
|
||||
|
||||
static PolicyManager&
|
||||
get_registered_manager();
|
||||
static PolicyManager&
|
||||
get_registered_manager();
|
||||
|
||||
virtual Policy&
|
||||
get_policy();
|
||||
virtual Policy&
|
||||
get_policy();
|
||||
|
||||
virtual void
|
||||
init();
|
||||
virtual void
|
||||
init();
|
||||
|
||||
virtual
|
||||
~PolicyManager();
|
||||
virtual
|
||||
~PolicyManager();
|
||||
|
||||
private:
|
||||
static PolicyManager* _registered;
|
||||
};
|
||||
private:
|
||||
static PolicyManager* _registered;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,97 +24,97 @@ using namespace sgpem;
|
|||
|
||||
PRRPolicy::PRRPolicy()
|
||||
{
|
||||
_instance = this;
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
PRRPolicy::PRRPolicy(int quantum)
|
||||
: _quantum(quantum)
|
||||
{
|
||||
_instance = this;
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
Policy&
|
||||
PRRPolicy::get_instance()
|
||||
{
|
||||
if(_instance == NULL) _instance = new PRRPolicy(3); // quantum size
|
||||
return *_instance;
|
||||
if (_instance == NULL) _instance = new PRRPolicy(3); // quantum size
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
||||
PRRPolicy::~PRRPolicy()
|
||||
{}
|
||||
|
||||
void
|
||||
void
|
||||
PRRPolicy::configure()
|
||||
throw(UserInterruptException)
|
||||
throw(UserInterruptException)
|
||||
{}
|
||||
|
||||
void
|
||||
void
|
||||
PRRPolicy::sort_queue() const
|
||||
throw(UserInterruptException)
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
ReadyQueue* 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);
|
||||
ReadyQueue* 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
|
||||
void
|
||||
PRRPolicy::activate()
|
||||
{}
|
||||
|
||||
void
|
||||
void
|
||||
PRRPolicy::deactivate()
|
||||
{}
|
||||
|
||||
int
|
||||
int
|
||||
PRRPolicy::get_id() const
|
||||
{
|
||||
return 42;
|
||||
return 42;
|
||||
}
|
||||
|
||||
sgpem::policy_sorts_type
|
||||
sgpem::policy_sorts_type
|
||||
PRRPolicy::wants() const
|
||||
throw(UserInterruptException)
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return policy_sorts_processes;
|
||||
return policy_sorts_processes;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Glib::ustring
|
||||
PRRPolicy::get_name() const
|
||||
{
|
||||
return "42";
|
||||
return "42";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Glib::ustring
|
||||
PRRPolicy::get_description() const
|
||||
{
|
||||
return "42";
|
||||
return "42";
|
||||
}
|
||||
|
||||
bool
|
||||
bool
|
||||
PRRPolicy::is_pre_emptive() const
|
||||
throw(UserInterruptException)
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
PRRPolicy::get_time_slice() const
|
||||
throw(UserInterruptException)
|
||||
throw(UserInterruptException)
|
||||
{
|
||||
return _quantum;
|
||||
return _quantum;
|
||||
}
|
||||
|
||||
PolicyParameters&
|
||||
PolicyParameters&
|
||||
PRRPolicy::get_parameters()
|
||||
{
|
||||
return _parameters;
|
||||
return _parameters;
|
||||
}
|
||||
|
||||
Policy*
|
||||
|
|
|
@ -48,81 +48,81 @@
|
|||
|
||||
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:
|
||||
/** 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();
|
||||
|
||||
PRRPolicy(int quantum);
|
||||
PRRPolicy(int quantum);
|
||||
|
||||
static Policy&
|
||||
get_instance();
|
||||
|
||||
virtual
|
||||
~PRRPolicy();
|
||||
static Policy&
|
||||
get_instance();
|
||||
|
||||
virtual void
|
||||
configure()
|
||||
throw(UserInterruptException);
|
||||
virtual
|
||||
~PRRPolicy();
|
||||
|
||||
virtual void
|
||||
sort_queue() const
|
||||
throw(UserInterruptException);
|
||||
virtual void
|
||||
configure()
|
||||
throw(UserInterruptException);
|
||||
|
||||
virtual void
|
||||
sort_queue() const
|
||||
throw(UserInterruptException);
|
||||
|
||||
|
||||
virtual void
|
||||
activate();
|
||||
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 void
|
||||
deactivate();
|
||||
|
||||
|
||||
virtual PolicyParameters&
|
||||
get_parameters();
|
||||
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:
|
||||
protected:
|
||||
|
||||
PolicyParameters _parameters;
|
||||
int _id;
|
||||
int _quantum;
|
||||
PolicyParameters _parameters;
|
||||
int _id;
|
||||
int _quantum;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
static Policy* _instance;
|
||||
};
|
||||
static Policy* _instance;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -32,33 +32,34 @@
|
|||
// from here and further until the bottom, all to throw away I suppose
|
||||
|
||||
int
|
||||
main(int argc, char** argv) {
|
||||
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
|
||||
using namespace sgpem;
|
||||
using Glib::ustring;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::ostringstream;
|
||||
|
||||
|
||||
GlobalPreferences& gp = GlobalPreferences::get_instance();
|
||||
|
||||
if(argc<2)
|
||||
if (argc < 2)
|
||||
{
|
||||
cout << "GlobalPreferences serialization test program" << endl;
|
||||
cout << "Syntax: test-global_preferences_serialization [mod1 mod2 ...][% pol1 pol2 ...]" << endl << endl;
|
||||
cout << "This test add modules directories (mod1 mod2 ...) and modules directories (mod1 mod2 ...)" << endl
|
||||
<< "to GlobalPreferences, write it to the configuration file " << gp.get_config_filename()
|
||||
<< ", read it and compare with saved one." << endl << endl;
|
||||
<< "to GlobalPreferences, write it to the configuration file " << gp.get_config_filename()
|
||||
<< ", read it and compare with saved one." << endl << endl;
|
||||
}
|
||||
|
||||
int i=1;
|
||||
while(i<argc && (*argv[i]!='%'))
|
||||
int i = 1;
|
||||
while (i < argc && (*argv[i] != '%'))
|
||||
{
|
||||
gp.add_modules_dir( Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
while(i<argc)
|
||||
while (i < argc)
|
||||
{
|
||||
gp.add_policies_dir( Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
|
@ -78,19 +79,19 @@ main(int argc, char** argv) {
|
|||
gp.write_configrc(os1);
|
||||
|
||||
|
||||
i=1;
|
||||
while(i<argc && (*argv[i]!='%'))
|
||||
i = 1;
|
||||
while (i < argc && (*argv[i] != '%'))
|
||||
{
|
||||
gp.add_modules_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
while(i<argc)
|
||||
while (i < argc)
|
||||
{
|
||||
gp.add_policies_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cout << "Other data added" << endl << endl;
|
||||
gp.write_configrc(cout);
|
||||
|
@ -107,13 +108,13 @@ main(int argc, char** argv) {
|
|||
ostringstream os3;
|
||||
cout << "Preferences writed into os3 (t3)" << endl << endl;
|
||||
gp.write_configrc(os3);
|
||||
|
||||
cout << "Comparing dump of (t1) and (t2): " << (os1.str()==os2.str()?"equals":"not equals") << endl;
|
||||
cout << "Comparing dump of (t1) and (t3): " << (os1.str()==os3.str()?"equals":"not equals") << endl;
|
||||
|
||||
cout << "Comparing dump of (t1) and (t2): " << (os1.str() == os2.str() ? "equals" : "not equals") << endl;
|
||||
cout << "Comparing dump of (t1) and (t3): " << (os1.str() == os3.str() ? "equals" : "not equals") << endl;
|
||||
|
||||
int ret = 1;
|
||||
if(os1.str()!=os2.str()
|
||||
&& os1.str()==os3.str())
|
||||
if (os1.str() != os2.str()
|
||||
&& os1.str() == os3.str())
|
||||
{
|
||||
cout << "test successful" << endl;
|
||||
ret = 0;
|
||||
|
|
|
@ -42,13 +42,13 @@ using Glib::ustring;
|
|||
// it is updated
|
||||
class DummyObserver : public HistoryObserver
|
||||
{
|
||||
public:
|
||||
DummyObserver() : _i(0) {}
|
||||
void update(const History& history)
|
||||
{
|
||||
cout << "Observer.update() : " << ++_i << endl;
|
||||
}
|
||||
unsigned int _i;
|
||||
public:
|
||||
DummyObserver() : _i(0) {}
|
||||
void update(const History& history)
|
||||
{
|
||||
cout << "Observer.update() : " << ++_i << endl;
|
||||
}
|
||||
unsigned int _i;
|
||||
};
|
||||
|
||||
struct ProcessCreationData
|
||||
|
@ -87,25 +87,25 @@ struct SubRequestCreationData
|
|||
History::resource_key_t resource_key;
|
||||
time_t duration;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DynamicThread&
|
||||
find_thread(ConcreteEnvironment& env, Thread& _thread)
|
||||
{
|
||||
DynamicThread& thread = (DynamicThread&)_thread;
|
||||
Environment::Processes& processes = env.get_processes();
|
||||
|
||||
|
||||
// please forgive me, I'm sick of using iterators...
|
||||
for(unsigned int i = 0; i < processes.size(); ++i)
|
||||
for (unsigned int i = 0; i < processes.size(); ++i)
|
||||
{
|
||||
Process& p = *processes[i];
|
||||
vector<Thread*> threads = p.get_threads();
|
||||
|
||||
for(unsigned int j = 0; j < threads.size(); ++j)
|
||||
for (unsigned int j = 0; j < threads.size(); ++j)
|
||||
{
|
||||
DynamicThread& t = (DynamicThread&)*threads[j];
|
||||
if(t == thread)
|
||||
return t;
|
||||
DynamicThread& t = (DynamicThread&) * threads[j];
|
||||
if (t == thread)
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,18 +117,18 @@ find_thread(const ConcreteEnvironment& env, const Thread& _thread)
|
|||
{
|
||||
const DynamicThread& thread = (DynamicThread&)_thread;
|
||||
const Environment::Processes& processes = env.get_processes();
|
||||
|
||||
|
||||
// please forgive me, I'm sick of using iterators...
|
||||
for(unsigned int i = 0; i < processes.size(); ++i)
|
||||
for (unsigned int i = 0; i < processes.size(); ++i)
|
||||
{
|
||||
const Process& p = *processes[i];
|
||||
vector<const Thread*> threads = p.get_threads();
|
||||
|
||||
for(unsigned int j = 0; j < threads.size(); ++j)
|
||||
for (unsigned int j = 0; j < threads.size(); ++j)
|
||||
{
|
||||
const DynamicThread& t = (const DynamicThread&)*threads[j];
|
||||
if(t == thread)
|
||||
return t;
|
||||
const DynamicThread& t = (const DynamicThread&) * threads[j];
|
||||
if (t == thread)
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ main(int argc, char** argv)
|
|||
{
|
||||
ostream& info = cout;
|
||||
ostream& test = cerr;
|
||||
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
ConcreteHistory h;
|
||||
|
@ -148,20 +148,20 @@ main(int argc, char** argv)
|
|||
info << "Created the ConcreteHistory instance\n";
|
||||
|
||||
test << "Checking if it contains only one Environment... ";
|
||||
|
||||
if(h.get_size() == 1)
|
||||
|
||||
if (h.get_size() == 1)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
|
||||
|
||||
const ConcreteEnvironment& environment = h.get_last_environment();
|
||||
|
||||
info << "Obtained the only contained environment\n";
|
||||
|
||||
test << "Checking if the environment is empty... ";
|
||||
|
||||
if(environment.get_processes().size() == 0 &&
|
||||
if (environment.get_processes().size() == 0 &&
|
||||
environment.get_resources().size() == 0 &&
|
||||
environment.get_sorted_queue().size() == 0)
|
||||
test << "PASS";
|
||||
|
@ -172,101 +172,101 @@ main(int argc, char** argv)
|
|||
DummyObserver observer;
|
||||
|
||||
info << "Created the observer\n";
|
||||
|
||||
|
||||
h.attach(observer);
|
||||
|
||||
info << "Attached to the history\n";
|
||||
|
||||
const ProcessCreationData processes[2] =
|
||||
{
|
||||
{ "p1", 0, 3 },
|
||||
{ "p2", 3, 1 }
|
||||
};
|
||||
const ProcessCreationData processes[2] =
|
||||
{
|
||||
{ "p1", 0, 3 },
|
||||
{ "p2", 3, 1 }
|
||||
};
|
||||
|
||||
DynamicProcess& p1 = h.add_process(processes[0].name,
|
||||
processes[0].arrival_time,
|
||||
processes[0].base_priority);
|
||||
DynamicProcess& p1 = h.add_process(processes[0].name,
|
||||
processes[0].arrival_time,
|
||||
processes[0].base_priority);
|
||||
|
||||
DynamicProcess& p2 = h.add_process(processes[1].name,
|
||||
processes[1].arrival_time,
|
||||
processes[1].base_priority);
|
||||
DynamicProcess& p2 = h.add_process(processes[1].name,
|
||||
processes[1].arrival_time,
|
||||
processes[1].base_priority);
|
||||
|
||||
const ThreadCreationData threads[4] =
|
||||
{
|
||||
{ "p2_1", &p2, 3, 0, 0 },
|
||||
{ "p1_1", &p1, 2, 0, 2 },
|
||||
{ "p1_2", &p1, 1, 1, 0 },
|
||||
{ "p2_2", &p2, 5, 3, 1 }
|
||||
};
|
||||
const ThreadCreationData threads[4] =
|
||||
{
|
||||
{ "p2_1", &p2, 3, 0, 0 },
|
||||
{ "p1_1", &p1, 2, 0, 2 },
|
||||
{ "p1_2", &p1, 1, 1, 0 },
|
||||
{ "p2_2", &p2, 5, 3, 1 }
|
||||
};
|
||||
|
||||
DynamicThread& p2_1 = h.add_thread(threads[0].name,
|
||||
*threads[0].parent,
|
||||
threads[0].cpu_time,
|
||||
threads[0].arrival_time,
|
||||
threads[0].base_priority);
|
||||
*threads[0].parent,
|
||||
threads[0].cpu_time,
|
||||
threads[0].arrival_time,
|
||||
threads[0].base_priority);
|
||||
|
||||
DynamicThread& p1_1 = h.add_thread(threads[1].name,
|
||||
*threads[1].parent,
|
||||
threads[1].cpu_time,
|
||||
threads[1].arrival_time,
|
||||
threads[1].base_priority);
|
||||
*threads[1].parent,
|
||||
threads[1].cpu_time,
|
||||
threads[1].arrival_time,
|
||||
threads[1].base_priority);
|
||||
|
||||
DynamicThread& p1_2 = h.add_thread(threads[2].name,
|
||||
*threads[2].parent,
|
||||
threads[2].cpu_time,
|
||||
threads[2].arrival_time,
|
||||
threads[2].base_priority);
|
||||
|
||||
DynamicThread& p2_2 = h.add_thread(threads[3].name,
|
||||
*threads[3].parent,
|
||||
threads[3].cpu_time,
|
||||
threads[3].arrival_time,
|
||||
threads[3].base_priority);
|
||||
*threads[2].parent,
|
||||
threads[2].cpu_time,
|
||||
threads[2].arrival_time,
|
||||
threads[2].base_priority);
|
||||
|
||||
const ResourceCreationData resources[2] =
|
||||
{
|
||||
{ "res1", true, 2, 0 },
|
||||
{ "res2", false, 1, 0 }
|
||||
};
|
||||
DynamicThread& p2_2 = h.add_thread(threads[3].name,
|
||||
*threads[3].parent,
|
||||
threads[3].cpu_time,
|
||||
threads[3].arrival_time,
|
||||
threads[3].base_priority);
|
||||
|
||||
const ResourceCreationData resources[2] =
|
||||
{
|
||||
{ "res1", true, 2, 0 },
|
||||
{ "res2", false, 1, 0 }
|
||||
};
|
||||
|
||||
const History::ResourcePair res1 = h.add_resource(resources[0].name,
|
||||
resources[0].preemptable,
|
||||
resources[0].places,
|
||||
resources[0].availability);
|
||||
|
||||
const History::ResourcePair res2 = h.add_resource(resources[1].name,
|
||||
resources[1].preemptable,
|
||||
resources[1].places,
|
||||
resources[1].availability);
|
||||
resources[0].preemptable,
|
||||
resources[0].places,
|
||||
resources[0].availability);
|
||||
|
||||
const RequestCreationData requests[2] =
|
||||
{
|
||||
{ &p1_2, 0 },
|
||||
{ &p2_1, 1 }
|
||||
};
|
||||
const History::ResourcePair res2 = h.add_resource(resources[1].name,
|
||||
resources[1].preemptable,
|
||||
resources[1].places,
|
||||
resources[1].availability);
|
||||
|
||||
const RequestCreationData requests[2] =
|
||||
{
|
||||
{ &p1_2, 0 },
|
||||
{ &p2_1, 1 }
|
||||
};
|
||||
|
||||
DynamicRequest& req1 = h.add_request(*requests[0].owner, requests[0].instant);
|
||||
|
||||
DynamicRequest& req2 = h.add_request(*requests[1].owner, requests[1].instant);
|
||||
|
||||
const SubRequestCreationData subrequests[3] =
|
||||
{
|
||||
{ &req1, res1.first, 1 },
|
||||
{ &req2, res2.first, 2 },
|
||||
{ &req2, res1.first, 1 }
|
||||
};
|
||||
const SubRequestCreationData subrequests[3] =
|
||||
{
|
||||
{ &req1, res1.first, 1 },
|
||||
{ &req2, res2.first, 2 },
|
||||
{ &req2, res1.first, 1 }
|
||||
};
|
||||
|
||||
const DynamicSubRequest& sreq1 = h.add_subrequest(*subrequests[0].request,
|
||||
subrequests[0].resource_key,
|
||||
subrequests[0].duration);
|
||||
|
||||
subrequests[0].resource_key,
|
||||
subrequests[0].duration);
|
||||
|
||||
const DynamicSubRequest& sreq2 = h.add_subrequest(*subrequests[1].request,
|
||||
subrequests[1].resource_key,
|
||||
subrequests[1].duration);
|
||||
|
||||
subrequests[1].resource_key,
|
||||
subrequests[1].duration);
|
||||
|
||||
const DynamicSubRequest& sreq3 = h.add_subrequest(*subrequests[2].request,
|
||||
subrequests[2].resource_key,
|
||||
subrequests[2].duration);
|
||||
subrequests[2].resource_key,
|
||||
subrequests[2].duration);
|
||||
|
||||
info << "Done adding required data by using the History factory interface\n";
|
||||
|
||||
|
@ -275,7 +275,7 @@ main(int argc, char** argv)
|
|||
// const Environment::SubRequestQueue res2_queue = environment.get_request_queue(res2.first);
|
||||
|
||||
test << "Checking if the environment contains the correct request queues... ";
|
||||
|
||||
|
||||
typedef Environment::SubRequestQueue::const_iterator ReqIterator;
|
||||
|
||||
// ************* FIXME *************** :
|
||||
|
@ -286,15 +286,15 @@ main(int argc, char** argv)
|
|||
// bool res1_req2_match = false;
|
||||
// bool res2_req1_match = false;
|
||||
// bool bad_match = false;
|
||||
|
||||
|
||||
// for(ReqIterator it = res1_queue.begin(); it != res1_queue.end(); ++it)
|
||||
// {
|
||||
// if(!res1_req1_match && *it == &req1)
|
||||
// res1_req1_match = true;
|
||||
// res1_req1_match = true;
|
||||
// else if(!res1_req2_match && *it == &req2)
|
||||
// res1_req2_match == true;
|
||||
// res1_req2_match == true;
|
||||
// else
|
||||
// bad_match = true;
|
||||
// bad_match = true;
|
||||
// }
|
||||
|
||||
// if(!res2_req1_match && *res2_queue.begin() == &req1)
|
||||
|
@ -309,25 +309,25 @@ main(int argc, char** argv)
|
|||
// }
|
||||
// else
|
||||
// test << "FAIL";
|
||||
test << endl;
|
||||
test << endl;
|
||||
|
||||
|
||||
ConcreteEnvironment* environment1 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment2 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment3 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment4 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment5 = new ConcreteEnvironment(environment);
|
||||
|
||||
ConcreteEnvironment* environment1 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment2 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment3 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment4 = new ConcreteEnvironment(environment);
|
||||
ConcreteEnvironment* environment5 = new ConcreteEnvironment(environment);
|
||||
|
||||
info << "Created 5 copies of inital environment\n";
|
||||
|
||||
const History::prio_t priorities[5] = { 3, 1, 4, 5, 2 };
|
||||
|
||||
|
||||
find_thread(*environment1, p1_1).set_priority_push(priorities[0]);
|
||||
find_thread(*environment2, p1_1).set_priority_push(priorities[1]);
|
||||
find_thread(*environment3, p1_1).set_priority_push(priorities[2]);
|
||||
find_thread(*environment4, p1_1).set_priority_push(priorities[3]);
|
||||
find_thread(*environment5, p1_1).set_priority_push(priorities[4]);
|
||||
|
||||
|
||||
info << "Updated dynamic priority of threads\n";
|
||||
|
||||
h.append_new_environment(environment1);
|
||||
|
@ -340,7 +340,7 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking if history size is 6... ";
|
||||
|
||||
if(h.get_size() == 6)
|
||||
if (h.get_size() == 6)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
@ -351,7 +351,7 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking if dynamic priority of thread at instant 1 and 5 is different... ";
|
||||
|
||||
if(t1.get_priority_push() != t5.get_priority_push())
|
||||
if (t1.get_priority_push() != t5.get_priority_push())
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
@ -361,10 +361,10 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking if dynamic priority of thread at instant 4, is different ";
|
||||
test << "from that at instant 1 and 5, and equal to the one expected... ";
|
||||
|
||||
if(t4.get_priority_push() != t1.get_priority_push() &&
|
||||
t4.get_priority_push() != t5.get_priority_push() &&
|
||||
t4.get_priority_push() == priorities[3])
|
||||
|
||||
if (t4.get_priority_push() != t1.get_priority_push() &&
|
||||
t4.get_priority_push() != t5.get_priority_push() &&
|
||||
t4.get_priority_push() == priorities[3])
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
@ -372,55 +372,55 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking whether all subrequests in the last environment ";
|
||||
test << "refer to valid resources... ";
|
||||
|
||||
|
||||
const ConcreteEnvironment& last_env = h.get_last_environment();
|
||||
const Environment::Processes& le_processes = last_env.get_processes();
|
||||
const Environment::Resources& le_resources = last_env.get_resources();
|
||||
|
||||
|
||||
bool subreq_pass = true;
|
||||
|
||||
for(unsigned int i = 0; i < le_processes.size(); ++i)
|
||||
|
||||
for (unsigned int i = 0; i < le_processes.size(); ++i)
|
||||
{
|
||||
vector<Thread*> threads = le_processes[i]->get_threads();
|
||||
|
||||
for(unsigned int j = 0; j < threads.size(); ++j)
|
||||
for (unsigned int j = 0; j < threads.size(); ++j)
|
||||
{
|
||||
vector<Request*> requests = threads[j]->get_requests();
|
||||
|
||||
for(unsigned int k = 0; k < requests.size(); ++k)
|
||||
for (unsigned int k = 0; k < requests.size(); ++k)
|
||||
{
|
||||
vector<SubRequest*> subrequests = requests[k]->get_subrequests();
|
||||
vector<SubRequest*> subrequests = requests[k]->get_subrequests();
|
||||
|
||||
for(unsigned int x = 0; x < subrequests.size(); ++x)
|
||||
{
|
||||
if(le_resources.find(subrequests[x]->get_resource_key()) == le_resources.end())
|
||||
subreq_pass = false;
|
||||
}
|
||||
for (unsigned int x = 0; x < subrequests.size(); ++x)
|
||||
{
|
||||
if (le_resources.find(subrequests[x]->get_resource_key()) == le_resources.end())
|
||||
subreq_pass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(subreq_pass)
|
||||
if (subreq_pass)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
|
||||
test << "Checking if history throws an exception on accessing a nonexistent environment... ";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
h.get_environment_at(6);
|
||||
test << "FAIL";
|
||||
}
|
||||
catch(out_of_range)
|
||||
catch (out_of_range)
|
||||
{
|
||||
test << "PASS";
|
||||
}
|
||||
test << endl;
|
||||
|
||||
ThreadCreationData p1_3_d = { "p1_3", &p1, 3, 4, 0 };
|
||||
|
||||
|
||||
Thread& p1_3 = h.add_thread(p1_3_d.name,
|
||||
*p1_3_d.parent,
|
||||
p1_3_d.cpu_time,
|
||||
|
@ -431,7 +431,7 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking if history has size 1 after adding a thread... ";
|
||||
|
||||
if(h.get_size() == 1)
|
||||
if (h.get_size() == 1)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
@ -442,12 +442,12 @@ main(int argc, char** argv)
|
|||
h.append_new_environment(environment6);
|
||||
|
||||
info << "Added a new environment to the history as a clear-cut copy of the last" << endl;
|
||||
|
||||
|
||||
h.remove(res1.first);
|
||||
|
||||
test << "Checking if history has size 1 after removing a resource... ";
|
||||
|
||||
if(h.get_size() == 1)
|
||||
if (h.get_size() == 1)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
@ -456,7 +456,7 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Checking whether objects inside the history are the same as the beginning, ";
|
||||
test << "except for the missing thread and associated requests... ";
|
||||
|
||||
|
||||
const Environment::Processes& final_processes = h.get_last_environment().get_processes();
|
||||
const Environment::Resources& final_resources = h.get_last_environment().get_resources();
|
||||
|
||||
|
@ -464,57 +464,57 @@ main(int argc, char** argv)
|
|||
bool final_p2_match = false;
|
||||
bool final_bad_match = false;
|
||||
bool final_sreq2_match = false;
|
||||
|
||||
for(unsigned int i = 0; i < final_processes.size(); ++i)
|
||||
{
|
||||
DynamicProcess& p = (DynamicProcess&)*final_processes[i];
|
||||
|
||||
if(!final_p1_match && p == p1)
|
||||
for (unsigned int i = 0; i < final_processes.size(); ++i)
|
||||
{
|
||||
DynamicProcess& p = (DynamicProcess&) * final_processes[i];
|
||||
|
||||
if (!final_p1_match && p == p1)
|
||||
final_p1_match = true;
|
||||
else if(!final_p2_match && p == p2)
|
||||
else if (!final_p2_match && p == p2)
|
||||
final_p2_match = true;
|
||||
else
|
||||
final_bad_match = true;
|
||||
|
||||
vector<DynamicThread*>& threads = p.get_dynamic_threads();
|
||||
|
||||
for(unsigned int j = 0; j < threads.size(); ++j)
|
||||
for (unsigned int j = 0; j < threads.size(); ++j)
|
||||
{
|
||||
vector<DynamicRequest*> requests = threads[j]->get_dynamic_requests();
|
||||
|
||||
for(unsigned int k = 0; k < requests.size(); ++k)
|
||||
for (unsigned int k = 0; k < requests.size(); ++k)
|
||||
{
|
||||
vector<DynamicSubRequest*> subrequests = requests[k]->get_dynamic_subrequests();
|
||||
vector<DynamicSubRequest*> subrequests = requests[k]->get_dynamic_subrequests();
|
||||
|
||||
for(unsigned int x = 0; x < subrequests.size(); ++x)
|
||||
{
|
||||
// NOTE this will of course fail if the subrequests which should not be here
|
||||
// are still in the environment
|
||||
if(!final_sreq2_match && *subrequests[x] == sreq2)
|
||||
final_sreq2_match = true;
|
||||
else
|
||||
final_bad_match = true;
|
||||
}
|
||||
for (unsigned int x = 0; x < subrequests.size(); ++x)
|
||||
{
|
||||
// NOTE this will of course fail if the subrequests which should not be here
|
||||
// are still in the environment
|
||||
if (!final_sreq2_match && *subrequests[x] == sreq2)
|
||||
final_sreq2_match = true;
|
||||
else
|
||||
final_bad_match = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef Environment::Resources::const_iterator ResourceIt;
|
||||
|
||||
if(final_resources.size() == 1)
|
||||
if (final_resources.size() == 1)
|
||||
{
|
||||
DynamicResource& r = (DynamicResource&)*(final_resources.begin()->second);
|
||||
if(!(r == *res2.second))
|
||||
DynamicResource& r = (DynamicResource&) * (final_resources.begin()->second);
|
||||
if (!(r == *res2.second))
|
||||
final_bad_match = true;
|
||||
}
|
||||
else
|
||||
final_bad_match = true;
|
||||
|
||||
if(!final_bad_match && final_p1_match && final_p2_match && final_sreq2_match)
|
||||
if (!final_bad_match && final_p1_match && final_p2_match && final_sreq2_match)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
test << endl;
|
||||
|
||||
|
||||
test << "Checking whether ConcreteHistory throws an exception if we try to use ";
|
||||
|
@ -523,12 +523,12 @@ main(int argc, char** argv)
|
|||
try
|
||||
{
|
||||
// FIXME This causes a warning because we force a conversion of a negative number
|
||||
// to an unsigned integer. What did the designers wanted to test by doing this?
|
||||
// to an unsigned integer. What did the designers wanted to test by doing this?
|
||||
// The compiler?
|
||||
h.get_environment_at(-17);
|
||||
test << "FAIL";
|
||||
}
|
||||
catch(out_of_range)
|
||||
catch (out_of_range)
|
||||
{
|
||||
test << "PASS";
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ main(int argc, char** argv)
|
|||
|
||||
test << "Internal observer's counter should be 21... ";
|
||||
|
||||
if(observer._i == 21)
|
||||
if (observer._i == 21)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
|
|
|
@ -31,68 +31,69 @@
|
|||
// from here and further until the bottom, all to throw away I suppose
|
||||
|
||||
int
|
||||
main(int argc, char** argv) {
|
||||
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
|
||||
using namespace sgpem;
|
||||
using Glib::ustring;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
if((argc<4) || (argc%2)!=0)
|
||||
|
||||
if ((argc < 4) || (argc % 2) != 0)
|
||||
{
|
||||
cout << "KeyFile class test program" << endl;
|
||||
cout << "Syntax: test-key_file filename key1 value1 [key2 value2...]" << endl;
|
||||
cout << "total number of parameters must be odd."
|
||||
<< endl << endl;
|
||||
cout << "This test create a KeyFile object, fill it with all key/value pairs," << endl
|
||||
<< "write it to the file \"filename\", read it into a new KeyFile object" << endl
|
||||
<< "and compare all readed values against original values." << endl << endl
|
||||
<< "If all key/values match the program print \"Test was successful\" and return 0." << endl
|
||||
<< "If some key/values doesn't match the program print \"Test failed\" and return 1."
|
||||
<< endl << endl;
|
||||
cout << "If there isn't any parameter or bad number of parameters return 2."
|
||||
<< endl << endl;
|
||||
cout << "NOTE: 1) Test fails with invalid filenames or duplicated key in input."
|
||||
<< endl;
|
||||
cout << " 2) File \"filename\" remains in current directory after test execution."
|
||||
<< endl << endl;
|
||||
cout << "total number of parameters must be odd."
|
||||
<< endl << endl;
|
||||
cout << "This test create a KeyFile object, fill it with all key/value pairs," << endl
|
||||
<< "write it to the file \"filename\", read it into a new KeyFile object" << endl
|
||||
<< "and compare all readed values against original values." << endl << endl
|
||||
<< "If all key/values match the program print \"Test was successful\" and return 0." << endl
|
||||
<< "If some key/values doesn't match the program print \"Test failed\" and return 1."
|
||||
<< endl << endl;
|
||||
cout << "If there isn't any parameter or bad number of parameters return 2."
|
||||
<< endl << endl;
|
||||
cout << "NOTE: 1) Test fails with invalid filenames or duplicated key in input."
|
||||
<< endl;
|
||||
cout << " 2) File \"filename\" remains in current directory after test execution."
|
||||
<< endl << endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
KeyFile kfile;
|
||||
KeyFile kfile_bis;
|
||||
|
||||
// fill KeyFile object
|
||||
for(int index = 2; index<argc; index+=2)
|
||||
|
||||
// fill KeyFile object
|
||||
for (int index = 2; index < argc; index += 2)
|
||||
{
|
||||
kfile.insert_key_value(Glib::ustring(argv[index]), Glib::ustring(argv[index+1]));
|
||||
}
|
||||
|
||||
|
||||
// write KeyFile object to file
|
||||
kfile.file_write(Glib::ustring(argv[1]));
|
||||
|
||||
|
||||
// read new KeyFile object from file
|
||||
kfile_bis.file_read(Glib::ustring(argv[1]));
|
||||
|
||||
|
||||
// compare writed vs. readed data
|
||||
bool ok = true;
|
||||
for(int index = 2; ok && index<argc; index+=2)
|
||||
for (int index = 2; ok && index < argc; index += 2)
|
||||
{
|
||||
Glib::ustring val(argv[index+1]);
|
||||
const Glib::ustring* pt = kfile_bis.search_value(Glib::ustring(argv[index]));
|
||||
if(!pt || (*pt)!=val)
|
||||
if (!pt || (*pt) != val)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// output response...
|
||||
if(ok)
|
||||
if (ok)
|
||||
{
|
||||
cout << "Test successful" << endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cout << "Test failed" << endl;
|
||||
return 1;
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace sgpem
|
|||
History&
|
||||
TestHistory::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
if (!_instance)
|
||||
_instance = new TestHistory();
|
||||
return *_instance;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace sgpem
|
|||
|
||||
static Policy& get_instance()
|
||||
{
|
||||
if(!_instance) _instance = new Policy(3); // quantum size
|
||||
if (!_instance) _instance = new Policy(3); // quantum size
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace sgpem
|
|||
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
if(_registered == this) _registered = NULL;
|
||||
if (_registered == this) _registered = NULL;
|
||||
}
|
||||
|
||||
PolicyManager&
|
||||
|
@ -199,7 +199,7 @@ namespace sgpem
|
|||
History::get_instance()
|
||||
|
||||
{
|
||||
if(!_instance) _instance = new Policy(3); // quantum size
|
||||
if (!_instance) _instance = new Policy(3); // quantum size
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,6 @@ namespace sgpem
|
|||
// this class should invoke the Scheduler Stepforward method.
|
||||
class StepForwardTester
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// from here and further until the bottom, all to throw away I suppose
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue