- Started test-history
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@777 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d839e4dcf6
commit
53073295d5
|
@ -35,30 +35,218 @@
|
|||
|
||||
using namespace sgpem;
|
||||
using namespace std;
|
||||
using Glib::ustring;
|
||||
|
||||
|
||||
// History observer used to see how many times
|
||||
// it is updated
|
||||
class DummyObserver : public HistoryObserver
|
||||
{
|
||||
public:
|
||||
DummyObserver() : _i(0) {}
|
||||
void update(const History& history)
|
||||
{
|
||||
cout << "Observer.update() : " << ++_i << endl;
|
||||
}
|
||||
private:
|
||||
unsigned int _i;
|
||||
public:
|
||||
DummyObserver() : _i(0) {}
|
||||
void update(const History& history)
|
||||
{
|
||||
cout << "Observer.update() : " << ++_i << endl;
|
||||
}
|
||||
private:
|
||||
unsigned int _i;
|
||||
};
|
||||
|
||||
struct ProcessCreationData
|
||||
{
|
||||
ustring name;
|
||||
time_t arrival_time;
|
||||
History::prio_t base_priority;
|
||||
};
|
||||
|
||||
struct ThreadCreationData
|
||||
{
|
||||
ustring name;
|
||||
Process* parent;
|
||||
time_t cpu_time;
|
||||
time_t arrival_time;
|
||||
History::prio_t base_priority;
|
||||
};
|
||||
|
||||
struct ResourceCreationData
|
||||
{
|
||||
ustring name;
|
||||
bool preemptable;
|
||||
size_t places;
|
||||
size_t availability;
|
||||
};
|
||||
|
||||
struct RequestCreationData
|
||||
{
|
||||
Thread* owner;
|
||||
time_t instant;
|
||||
};
|
||||
|
||||
struct SubRequestCreationData
|
||||
{
|
||||
Request* request;
|
||||
History::resource_key_t resource_key;
|
||||
time_t duration;
|
||||
size_t places;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
ostream& info = cout;
|
||||
ostream& test = cerr;
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
#warning "Nobody wrote me!"
|
||||
ConcreteHistory h;
|
||||
|
||||
return 0;
|
||||
info << "Created the ConcreteHistory instance\n";
|
||||
|
||||
test << "Checking if it contains only one Environment... ";
|
||||
|
||||
if(h.get_size() == 1)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
|
||||
Environment& environment = h.get_last_environment();
|
||||
|
||||
info << "Obtained the only contained environment\n";
|
||||
|
||||
test << "Checking if it is a ConcreteEnvironment... ";
|
||||
|
||||
if(typeid(environment) == typeid(ConcreteEnvironment))
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
|
||||
test << "Checking if the environment is empty... ";
|
||||
|
||||
if(environment.get_processes().size() == 0 &&
|
||||
environment.get_resources().size() == 0 &&
|
||||
environment.get_request_queue().size() == 0 &&
|
||||
environment.get_sorted_queue().size() == 0)
|
||||
test << "PASS";
|
||||
else
|
||||
test << "FAIL";
|
||||
test << endl;
|
||||
|
||||
DummyObserver observer;
|
||||
|
||||
info << "Created the observer\n";
|
||||
|
||||
h.attach(observer);
|
||||
|
||||
info << "Attached to the history\n;
|
||||
|
||||
ProcessCreationData processes[2] =
|
||||
{
|
||||
{ "p1", 0, 3 },
|
||||
{ "p2", 3, 1 }
|
||||
};
|
||||
|
||||
Process& p1 = h.add_process(processes[0].name,
|
||||
processes[0].arrival_time,
|
||||
processes[0].base_priority);
|
||||
|
||||
Process& p2 = h.add_process(processes[1].name,
|
||||
processes[1].arrival_time,
|
||||
processes[1].base_priority);
|
||||
|
||||
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 }
|
||||
};
|
||||
|
||||
Thread& p2_1 = h.add_thread(threads[0].name,
|
||||
*threads[0].parent,
|
||||
threads[0].cpu_time,
|
||||
threads[0].arrival_time,
|
||||
threads[0].base_priority);
|
||||
|
||||
Thread& p1_1 = h.add_thread(threads[1].name,
|
||||
*threads[1].parent,
|
||||
threads[1].cpu_time,
|
||||
threads[1].arrival_time,
|
||||
threads[1].base_priority);
|
||||
|
||||
Thread& p1_2 = h.add_thread(threads[2].name,
|
||||
*threads[2].parent,
|
||||
threads[2].cpu_time,
|
||||
threads[2].arrival_time,
|
||||
threads[2].base_priority);
|
||||
|
||||
Thread& p2_2 = h.add_thread(threads[3].name,
|
||||
*threads[3].parent,
|
||||
threads[3].cpu_time,
|
||||
threads[3].arrival_time,
|
||||
threads[3].base_priority);
|
||||
|
||||
ResourceCreationData resources[2] =
|
||||
{
|
||||
{ "res1", true, 2, 0 },
|
||||
{ "res2", false, 1, 0 }
|
||||
};
|
||||
|
||||
History::ResourcePair res1 = h.add_resource(resources[0].name,
|
||||
resources[0].preemptable,
|
||||
resources[0].places,
|
||||
resources[0].availability);
|
||||
|
||||
History::ResourcePair res2 = h.add_resource(resources[1].name,
|
||||
resources[1].preemptable,
|
||||
resources[1].places,
|
||||
resources[1].availability);
|
||||
|
||||
RequestCreationData requests[2] =
|
||||
{
|
||||
{ &p1_2, 0 },
|
||||
{ &p2_1, 1 }
|
||||
};
|
||||
|
||||
Request& req1 = h.add_request(*requests[0].owner, requests[0].instant);
|
||||
|
||||
Request& req2 = h.add_request(*requests[1].owner, requests[1].instant);
|
||||
|
||||
SubRequestCreationData subrequests[3] =
|
||||
{
|
||||
{ &req1, res1.first, 1, 1 },
|
||||
{ &req2, res2.first, 2, 1 },
|
||||
{ &req2, res1.first, 1, 2 }
|
||||
};
|
||||
|
||||
SubRequest& sreq1 = h.add_subrequest(*subrequests[0].request,
|
||||
subrequests[0].resource_key,
|
||||
subrequests[0].duration,
|
||||
subrequests[0].places);
|
||||
|
||||
SubRequest& sreq2 = h.add_subrequest(*subrequests[1].request,
|
||||
subrequests[1].resource_key,
|
||||
subrequests[1].duration,
|
||||
subrequests[1].places);
|
||||
|
||||
SubRequest& sreq2 = h.add_subrequest(*subrequests[2].request,
|
||||
subrequests[2].resource_key,
|
||||
subrequests[2].duration,
|
||||
subrequests[2].places);
|
||||
|
||||
info << "Done adding required data by using the History factory interface\n";
|
||||
|
||||
Environment::Requests res1_queue = environment.get_request_queue(res1.first);
|
||||
Environment::Requests res2_queue = environment.get_request_queue(res2.first);
|
||||
|
||||
//typedef Environment::Requests::iterator ReqIterator;
|
||||
|
||||
//for(ReqIterator it = res1_queue.begin(); it !+ res1_queue.end(); ++it)
|
||||
//{
|
||||
|
||||
#warning "Finish me!"
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue