- added some test drafts

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@512 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-03-09 05:19:43 +00:00
parent 8afcc2edbb
commit 24a0194368
2 changed files with 545 additions and 0 deletions

View File

@ -0,0 +1,239 @@
// src/testsuite/test-history.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
/* This executable tests for workingness of the whole History services,
* and nothing else. */
#include <glibmm/module.h> // ??
#include <cassert>
#include <string>
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include <iostream>
#include "backend/process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_list.hh"
#include "backend/schedulable_status.hh"
#include "templates/smartp.hh"
class HistoryTester
{
public:
HistoryTester(SchedulableList sl) : _history_length(-1), _internal_schedulable_list(sl)
{
}
/** this method gets a sequence of operations as a parameter and performs them
* checking for incongruences.
* E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion
*/
void test(std::string commands_sequence)
{
// prints the test sequence
std::cout << commands_sequence << endl;
// executes the test sequence
for (int i = 0; i < commands_sequence.length() && i < 400; i++)
{
switch(commands_sequence[i])
{
case E:
_insert(_internal_schedulable_list);
break;
case R:
_randomize(_internal_schedulable_list);
break;
case T:
_truncate();
break;
default:
break;
}
_standard_test();
}
return;
}
private:
int _history_length; // mirrors the correct length of the history
SchedulableList* _get_simulation_status_at[400]; // mirrors the correct content of the history
SchedulableStatus* _get_scheduled_at[400]; // mirrors the correct content of the history
SchedulableList _internal_schedulable_list;
void _standard_test()
{
// checks if the Singleton Pattern has been actually implemented
if (&History::get_instance() != &History::get_instance()) std::cout << "get_instance";
// checks if the History is long how it should be
if (!History::get_instance().get_current_time() != _history_length) std::cout << "get_current_time";
// checks if the History contains the right stuff
for (int i = 0; i <= _history_length; i++)
{
// watch out here, it's if (NOT ...) operator != was not available.
if (!(History::get_instance().get_simulation_status_at(i) == *_get_simulation_status_at[i]))
{
std::cout << "get_simulation_status_at";
}
if (History::get_instance().get_scheduled_at(i) != *_get_scheduled_at[i])
{
std::cout << "get_simulation_status_at";
}
}
return;
}
void _insert(sgpem::SchedulableList& status)
{
History::get_instance().enqueue_slice(status);
_history_length = _history_length + 1;
// I hope the copy constructor is available..
_get_simulation_status_at[history_length] = new SchedulableList(status);
_get_scheduled_at[history_length] = new SchedulableStatus(*(status.top()));
return;
}
void _randomize(sgpem::SchedulableList& status)
{
status.swap(9, 10);
status.swap(1, 16);
status.swap(3, 19);
status.swap(2, 18);
status.swap(5, 16);
status.swap(4, 11);
status.swap(6, 12);
status.swap(7, 14);
status.swap(15, 13);
status.swap(0, 10);
status.swap(9, 4);
status.swap(4, 5);
status.swap(7, 1);
for (int i = 0; i <= status.size(); i++)
{
status.get_item_at(i).give_cpu_time(1);
status.get_item_at(i).set_last_scheduled(_history_length);
status.get_item_at(i).set_state(1<<(i%4));
}
return;
}
void _truncate()
{
delete _get_simulation_status_at[history_length]
delete _get_scheduled_at[history_length]
_history_length = _history_length - 1;
History::get_instance().truncate_at(history_length);
return;
}
}
int
main(int argc, char** argv) {
using namespace sgpem;
using Glib::Module;
std::string command(ERERERT); // the sequence of commands to test
// sets up the test data
Process p1("P1", 1,5,1);
Process p2("P2", 5,55,2);
Process p3("P3", 36,30,3);
Process p4("P4", 4,26,3);
Process p5("P5", 15,200,3);
Process p6("P6", 6,250,1);
Process p7("P7", 8,42,15);
Process p8("P8", 8,56,1);
Process p9("P9", 9,42,1);
Process p10("PA", 12,42,1);
Process p11("PB", 106,42,1);
Process p12("PC", 100,42,1);
Process p13("PD", 29,42,18);
Process p14("PE", 0,42,1);
Process p15("PF", 2,88,1);
Process p16("PG", 3666,9,1);
Process p17("PH", 5,72,10);
Process p18("PJ", 6,26,1);
Process p19("PK", 10,24,17);
Process p20("PK2", 11,34,67); // not used!
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
SchedulableStatus ss7(p7);
SchedulableStatus ss8(p8);
SchedulableStatus ss9(p9);
SchedulableStatus ss10(p10);
SchedulableStatus ss11(p11);
SchedulableStatus ss12(p12);
SchedulableStatus ss13(p13);
SchedulableStatus ss14(p14);
SchedulableStatus ss15(p15);
SchedulableStatus ss16(p16);
SchedulableStatus ss17(p17);
SchedulableStatus ss18(p18);
SchedulableStatus ss19(p19); // not used!
SchedulableList initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);
initial.add_at_bottom(ss4);
initial.add_at_bottom(ss5);
initial.add_at_bottom(ss6);
initial.add_at_bottom(ss7);
initial.add_at_bottom(ss8);
initial.add_at_bottom(ss9);
initial.add_at_bottom(ss10);
initial.add_at_bottom(ss11);
initial.add_at_bottom(ss12);
initial.add_at_bottom(ss13);
initial.add_at_bottom(ss14);
initial.add_at_bottom(ss15);
initial.add_at_bottom(ss16);
initial.add_at_bottom(ss17);
initial.add_at_bottom(ss18);
HistoryTester HT(initial);
HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT");
exit(0);
}

View File

@ -0,0 +1,306 @@
// 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
/* This executable tests for workingness of the stepForward method,
* and nothing else. */
#include <glibmm/module.h> // ??
#include <cassert>
#include <string>
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include <iostream>
#include "backend/process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_list.hh"
#include "backend/schedulable_status.hh"
#include "templates/smartp.hh"
#include "scheduler.hh"
#include "user_interrupt_exception.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:
Policy()
{
_instance = this;
}
Policy(int quantum) : _quantum(quantum)
{
_instance = this;
}
static Policy& get_instance()
{
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
virtual ~Policy()
{
}
virtual void configure()
{
}
virtual void sort_queue(Scheduler::event event) const throw(UserInterruptException)
{ // here a lot of fun, exactly O(n^2) fun!
SchedulableList sl = History.get_instance().get_simulation_status_at(get_current_time());
for (int i = 0; i < sl.size(); i++)
{
for (int j = 0; j < sl.size()-1; j++)
{
if (sl.get_item_at(j).get_schedulable().get_priority() < sl.get_item_at(j+1).get_schedulable().get_priority())
{
sl.swap(j, j+1);
}
}
}
}
int get_id() const
{
return 42;
}
virtual Glib::ustring get_description()
{
return "42";
}
virtual bool is_pre_emptive() const throw(UserInterruptException)
{
return 1;
}
virtual int get_time_slice() const throw(UserInterruptException)
{
return _quantum;
}
PolicyParameters& get_parameters()
{
return _parameters;
}
protected:
PolicyParameters _parameters;
int _id;
int _quantum;
private:
static Policy* _instance;
};
Policy*
PRRPolicy::_instance = NULL;
// A PolicyManager stub
class PolicyManager
{
public:
PolicyManager();
virtual ~PolicyManager();
virtual Policy& get_policy()
{
return PRRPolicy.get_instance();
}
virtual void init()
{
}
static PolicyManager& get_registered_manager();
private:
static PolicyManager* _registered;
};
PolicyManager*
PolicyManager::_registered = NULL;
PolicyManager::PolicyManager()
{
_registered = this;
}
PolicyManager::~PolicyManager()
{
if(_registered == this) _registered = NULL;
}
PolicyManager&
PolicyManager::get_registered_manager()
{
return *_registered;
}
// a History stub, should only save the last state included. but...
class History : public ObservedSubject
{
public:
// what the hell are these smart pointers?
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const;
memory::smart_ptr<sgpem::SchedulableList> get_simulation_status_at(int time) const;
int get_current_time() const;
void enqueue_slice(const sgpem::SchedulableList& status);
void truncate_at(int instant);
static History& get_instance();
private:
History(int); //private constructor. The parameter is discarded
static History _instance;
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
};
History&
History::get_instance()
{
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
} //~ 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
int
main(int argc, char** argv) {
using namespace sgpem;
using Glib::Module;
std::string command(ERERERT); // the sequence of commands to test
// sets up the test data
Process p1("P1", 1,5,1);
Process p2("P2", 5,55,2);
Process p3("P3", 36,30,3);
Process p4("P4", 4,26,3);
Process p5("P5", 15,200,3);
Process p6("P6", 6,250,1);
Process p7("P7", 8,42,15);
Process p8("P8", 8,56,1);
Process p9("P9", 9,42,1);
Process p10("PA", 12,42,1);
Process p11("PB", 106,42,1);
Process p12("PC", 100,42,1);
Process p13("PD", 29,42,18);
Process p14("PE", 0,42,1);
Process p15("PF", 2,88,1);
Process p16("PG", 3666,9,1);
Process p17("PH", 5,72,10);
Process p18("PJ", 6,26,1);
Process p19("PK", 10,24,17);
Process p20("PK2", 11,34,67); // not used!
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
SchedulableStatus ss7(p7);
SchedulableStatus ss8(p8);
SchedulableStatus ss9(p9);
SchedulableStatus ss10(p10);
SchedulableStatus ss11(p11);
SchedulableStatus ss12(p12);
SchedulableStatus ss13(p13);
SchedulableStatus ss14(p14);
SchedulableStatus ss15(p15);
SchedulableStatus ss16(p16);
SchedulableStatus ss17(p17);
SchedulableStatus ss18(p18);
SchedulableStatus ss19(p19); // not used!
SchedulableList initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);
initial.add_at_bottom(ss4);
initial.add_at_bottom(ss5);
initial.add_at_bottom(ss6);
initial.add_at_bottom(ss7);
initial.add_at_bottom(ss8);
initial.add_at_bottom(ss9);
initial.add_at_bottom(ss10);
initial.add_at_bottom(ss11);
initial.add_at_bottom(ss12);
initial.add_at_bottom(ss13);
initial.add_at_bottom(ss14);
initial.add_at_bottom(ss15);
initial.add_at_bottom(ss16);
initial.add_at_bottom(ss17);
initial.add_at_bottom(ss18);
HistoryTester HT(initial);
HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT");
exit(0);
}