- added xml serialization classes (partial implementation)
- xml_serializer - xml_visitor - testsuite/test-xml_visitor git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@743 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
4d862a3c2f
commit
519e516314
5 changed files with 550 additions and 0 deletions
132
plugins/xmlsave/src/testsuite/test-xml_visitor.cc
Normal file
132
plugins/xmlsave/src/testsuite/test-xml_visitor.cc
Normal file
|
@ -0,0 +1,132 @@
|
|||
// 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 "config.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "backend/concrete_environment.hh"
|
||||
#include "backend/concrete_history.hh"
|
||||
#include "backend/history_observer.hh"
|
||||
#include "xml_serializer.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
using namespace std;
|
||||
|
||||
|
||||
void fillHistory(History &hist)
|
||||
{
|
||||
cout << "filling history..." << endl << endl;
|
||||
// add a resource - name, preemptable, places, availability
|
||||
History::ResourcePair respair = hist.add_resource(Glib::ustring("Resource 1"), false, 1, 2);
|
||||
// and print his values
|
||||
cout << "resource name: " << respair.second->get_name() << " key: " << respair.first << " places: " << respair.second->get_places() << endl;
|
||||
|
||||
// add a process - name, arrival time, priority
|
||||
Process& p1 = hist.add_process(Glib::ustring("Process 1"), 5, 2); // name, arrival time, priority
|
||||
// and print his values
|
||||
cout << "process name: " << p1.get_name() << " arrival_time: " << p1.get_arrival_time() << " base_priority: " << p1.get_base_priority() << endl;
|
||||
|
||||
// add a process - name, arrival time, priority
|
||||
Process& p2 = hist.add_process(Glib::ustring("Process 2"), 7, 3); // name, arrival time, priority
|
||||
// and print his values
|
||||
cout << "process name: " << p2.get_name() << " arrival_time: " << p2.get_arrival_time() << " base_priority: " << p2.get_base_priority() << endl;
|
||||
|
||||
// add a process - name, arrival time, priority
|
||||
Process& p3 = hist.add_process(Glib::ustring("Process 3"), 9, 1); // name, arrival time, priority
|
||||
// and print his values
|
||||
cout << "process name: " << p3.get_name() << " arrival_time: " << p3.get_arrival_time() << " base_priority: " << p3.get_base_priority() << endl;
|
||||
|
||||
// add a thread - name, parent, cpu time, arrival time, priority
|
||||
Thread& p1_t1 = hist.add_thread(Glib::ustring("Process 1 - Thread 1"), p1, 3, 2, 6);
|
||||
// and print his values
|
||||
cout << "thread name: " << p1_t1.get_name() << " total_cpu_time: " << p1_t1.get_total_cpu_time() << " arrival_time: " << p1_t1.get_arrival_time() << " base_priority: " << p1_t1.get_base_priority() << endl;
|
||||
|
||||
// add a request - Thread, time
|
||||
Request& req1 = hist.add_request(p1_t1, 7);
|
||||
// and print his values
|
||||
cout << "request arrival_time: " << req1.get_instant() << endl;
|
||||
|
||||
// add a sub request - Request, resource_key, duration, places
|
||||
SubRequest& req1_sub1 = hist.add_subrequest(req1, respair.first, 5, 2);
|
||||
// and print his values
|
||||
cout << "sub request resource_key: " << req1_sub1.get_resource_key() << " places: " << req1_sub1.get_places() << " length: " << req1_sub1.get_length() << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
void dumpEnvironment(const Environment& env)
|
||||
{
|
||||
const Environment::Processes& pvect = env.get_processes();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
proc_iterator iter = pvect.begin();
|
||||
proc_iterator end = pvect.end();
|
||||
while(iter!=end)
|
||||
{
|
||||
Process* p = (*iter);
|
||||
cout << "process name: " << p->get_name() << " arrival_time: " << p->get_arrival_time() << " base_priority: " << p->get_base_priority() << endl;
|
||||
iter++;
|
||||
|
||||
|
||||
typedef std::vector<Thread*> Threads;
|
||||
typedef std::vector<Thread*>::const_iterator thr_iterator;
|
||||
const Threads& tvect = p->get_threads();
|
||||
thr_iterator iter1 = tvect.begin();
|
||||
thr_iterator end1 = tvect.end();
|
||||
while(iter1!=end1)
|
||||
{
|
||||
|
||||
Thread* p = (*iter1);
|
||||
cout << "Thread name: " << p->get_name() << " arrival_time: " << p->get_arrival_time() << " base_priority: " << p->get_base_priority() << endl;
|
||||
iter1++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
// using namespace sgpem;
|
||||
|
||||
ConcreteHistory hist;
|
||||
|
||||
fillHistory(hist);
|
||||
|
||||
const Environment& env = hist.get_last_environment();
|
||||
dumpEnvironment(env);
|
||||
|
||||
XMLSerializer xmlser;
|
||||
xmlser.save_snapshot(Glib::ustring("xml-visit.xml"), hist);
|
||||
|
||||
|
||||
// typedef std::vector<Process*> Processes;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue