- Fix compilation of test-history

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@515 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-03-09 11:37:09 +00:00
parent 92e6f3be2b
commit 0c2cba8bbe
6 changed files with 169 additions and 98 deletions

View file

@ -36,6 +36,7 @@
#include <vector>
#include <iostream>
#include "backend/history.hh"
#include "backend/process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
@ -43,16 +44,15 @@
#include "backend/schedulable_status.hh"
#include "templates/smartp.hh"
using namespace sgpem;
using namespace std;
class HistoryTester
{
public:
HistoryTester(SchedulableList sl) : _history_length(-1), _internal_schedulable_list(sl)
{
}
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.
@ -63,17 +63,17 @@ class HistoryTester
// prints the test sequence
std::cout << commands_sequence << endl;
// executes the test sequence
for (int i = 0; i < commands_sequence.length() && i < 400; i++)
for (unsigned int i = 0; i < commands_sequence.length() && i < 400; i++)
{
switch(commands_sequence[i])
{
case E:
case 'E':
_insert(_internal_schedulable_list);
break;
case R:
case 'R':
_randomize(_internal_schedulable_list);
break;
case T:
case 'T':
_truncate();
break;
default:
@ -103,11 +103,11 @@ class HistoryTester
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]))
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])
if (!(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
{
std::cout << "get_simulation_status_at";
}
@ -120,8 +120,8 @@ class HistoryTester
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()));
_get_simulation_status_at[_history_length] = new SchedulableList(status);
_get_scheduled_at[_history_length] = new SchedulableStatus(*(status.top()));
return;
}
@ -140,34 +140,35 @@ class HistoryTester
status.swap(9, 4);
status.swap(4, 5);
status.swap(7, 1);
for (int i = 0; i <= status.size(); i++)
for (unsigned 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));
// FIXME: These methods aren't implemented!!
//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]
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);
History::get_instance().truncate_at(_history_length);
return;
}
}
};
int
main(int argc, char** argv) {
main(int argc, char** argv)
{
using namespace sgpem;
using Glib::Module;
std::string command(ERERERT); // the sequence of commands to test
std::string command("ERERERT"); // the sequence of commands to test
// sets up the test data
Process p1("P1", 1,5,1);

View file

@ -21,11 +21,9 @@
/* This executable tests for workingness of the parseCommand method in the
* classTextSimulation class and the StandardIO class. */
#include "backend/standard_io.hh"
#include "backend/text_simulation.hh"
#include "backend/templates/smartp.hh"
#include <glibmm/module.h>
#include "standard_io.hh"
#include "text_simulation.hh"
#include "templates/smartp.hh"
#include <cassert>
#include <string>
@ -38,94 +36,76 @@
#include <vector>
#include <iostream>
#include "slice.hh"
#include "observed_subject.hh"
#include "schedulable_list.hh"
#include "schedulable_status.hh"
#include "../templates/smartp.hh"
#include "backend/process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_list.hh"
#include "backend/schedulable_status.hh"
namespace sgpem
{
/* History stub: every public method does nothing except printing
in std::cout the signature and the parameters. */
/* History stub: every public method does nothing except printing
in std::cout the signature and the parameters. */
class History;
class SG_DLLEXPORT History : public ObservedSubject
class TestHistory : public History
{
public:
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time)
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time)
{
std::cout << "get_scheduled_at" << time;
std::cout << "get_scheduled_at" << time;
return History::get_scheduled_at(time);
}
memory::smart_ptr<sgpem::SchedulableList> get_simulation_status_at(int time) const
{
std::cout << "get_simulation_status_at" << time;
std::cout << "get_simulation_status_at" << time;
return History::get_simulation_status_at(time);
}
int get_current_time() const
{
std::cout << "getCurrentTime";
std::cout << "getCurrentTime";
return History::get_current_time();
}
void enqueue_slice(const sgpem::SchedulableList& status)
{
std::cout << "enqueue_slice";
std::cout << "enqueue_slice";
History::enqueue_slice(status);
}
void truncate_at(int instant)
{
std::cout << "TruncateAt" << instant;
std::cout << "TruncateAt" << instant;
History::truncate_at(instant);
}
// The following method is not used by the user interface
// The following method is not used by the user interface
static History& get_instance();
private:
static TestHistory* _instance;
};
TestHistory* TestHistory::_instance = 0;
History&
TestHistory::get_instance()
{
if(!_instance)
_instance = new TestHistory();
return *_instance;
}
}//~ namespace sgpem
int
main(int argc, char** argv) {
main(int, char**) {
using namespace sgpem;
using Glib::Module;
std::string pyloader_path = Module::build_path(MODDIR, "pyloader");
Glib::Module pyloader(pyloader_path);
assert(pyloader);
Glib::thread_init();
// Create an INITIAL STATE
Process p1("P1", 0,5,1);
Process p2("P2", 0,5,2);
Process p3("P3", 5,3,3);
Process p4("P4", 6,2,3);
Process p5("P5", 1,2,3);
Process p6("P6", 10,2,1);
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
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);
History::get_instance().enqueue_slice(initial);
Scheduler::get_instance(); // Forces initialization of scheduler.
// Cross fingers (depends if PythonPolicyManager
// static object has been initialized before?).
//the textual simulation
TextSimulation text_sim;
History::get_instance().attach(&text_sim);
//initialize history
TestHistory::get_instance();
//textual IO
memory::smart_ptr<IOManager> io(new StandardIO());