- Give facelift to test_loader. Still to be finished.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@509 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-03-08 16:47:39 +00:00
parent d462f6d1d3
commit 6a0bf4f444
11 changed files with 145 additions and 37 deletions

View File

@ -1,3 +1,20 @@
2006-03-08 12:49 tchernobog
* trunk/src/templates/smartp.hh, trunk/src/templates/smartp.tcc: -
Add extended support for casting between different types of
smart_ptr
2006-03-07 01:27 tchernobog
* trunk/src/templates/smartp.hh, trunk/src/templates/smartp.tcc: -
Update smartp to version 1.1: add support for dynamic casting
2006-03-05 23:06 tchernobog
* trunk/ChangeLog, trunk/Makefile.am, trunk/po/sgpemv2.pot: - Use
kluge to an automake bug to have ``make distcheck'' working again
- Update ChangeLog
2006-03-05 01:07 tchernobog 2006-03-05 01:07 tchernobog
* trunk/src/templates/smartp.tcc: - Fix obscure bug (with reference * trunk/src/templates/smartp.tcc: - Fix obscure bug (with reference

View File

@ -38,6 +38,7 @@ bin_PROGRAMS =
plugin_LTLIBRARIES = plugin_LTLIBRARIES =
noinst_HEADERS = noinst_HEADERS =
pkglib_LTLIBRARIES = pkglib_LTLIBRARIES =
tests_PYTHON =
EXTRA_DIST = EXTRA_DIST =
MAINTAINERCLEANFILES = MAINTAINERCLEANFILES =
MOSTLYCLEANFILES = MOSTLYCLEANFILES =
@ -329,7 +330,7 @@ tests_PROGRAMS = src/testsuite/test-python_loader
src_testsuite_test_python_loader_CPPFLAGS = \ src_testsuite_test_python_loader_CPPFLAGS = \
-I@top_srcdir@/src \ -I@top_srcdir@/src \
-DPOLDIR="\"$(policiesdir)\"" \ -DPOLDIR="\"$(testsdir)\"" \
-DMODDIR="\"$(pyloaderdir)\"" \ -DMODDIR="\"$(pyloaderdir)\"" \
$(PYTHON_CPPFLAGS) \ $(PYTHON_CPPFLAGS) \
$(GLIBMM_CFLAGS) \ $(GLIBMM_CFLAGS) \
@ -338,6 +339,7 @@ src_testsuite_test_python_loader_DEPENDENCIES = \
src/backend/pyloader/libpyloader.la src/backend/pyloader/libpyloader.la
src_testsuite_test_python_loader_LDFLAGS = \ src_testsuite_test_python_loader_LDFLAGS = \
src/backend/libbackend.la \ src/backend/libbackend.la \
src/backend/pyloader/libpyloader.la \
$(GTKMM_LIBS) $(GTHREAD_LIBS) $(GTKMM_LIBS) $(GTHREAD_LIBS)
src_testsuite_test_python_loader_SOURCES = \ src_testsuite_test_python_loader_SOURCES = \
src/testsuite/test-python_loader.cc \ src/testsuite/test-python_loader.cc \
@ -346,6 +348,11 @@ src_testsuite_test_python_loader_SOURCES = \
src/observer.cc \ src/observer.cc \
src/simulation.cc src/simulation.cc
tests_PYTHON += src/testsuite/python_loader_configure.py \
src/testsuite/python_loader_sort_queue.py \
src/testsuite/python_loader_is_preemptive.py \
src/testsuite/python_loader_get_time_slice.py
# Workaround an automake bug that leaves behind some files # Workaround an automake bug that leaves behind some files
# while it's finishing the distcheck target # while it's finishing the distcheck target
CLEANFILES += src/testsuite/.libs/test-python_loader CLEANFILES += src/testsuite/.libs/test-python_loader

View File

@ -45,9 +45,7 @@ namespace sgpem
class SG_DLLEXPORT PythonPolicy : public Policy class SG_DLLEXPORT PythonPolicy : public Policy
{ {
public: public:
//only PythonPolicyManager can create a PythonPolicy object PythonPolicy(const char* name);
friend class PythonPolicyManager;
virtual ~PythonPolicy(); virtual ~PythonPolicy();
/** /**
@ -77,7 +75,6 @@ namespace sgpem
int get_time_slice() const throw(UserInterruptException); int get_time_slice() const throw(UserInterruptException);
private: private:
PythonPolicy(const char* name);
PythonPolicy(const PythonPolicy&); PythonPolicy(const PythonPolicy&);
PythonPolicy& operator=(const PythonPolicy&); PythonPolicy& operator=(const PythonPolicy&);

View File

@ -56,10 +56,9 @@ PythonPolicyManager::get_policy()
void void
PythonPolicyManager::init() PythonPolicyManager::init()
{ {
if(_initialized) { if(_initialized)
_python_policy = std::auto_ptr<PythonPolicy>(0); // No-op
Py_Finalize(); return;
}
Py_Initialize(); Py_Initialize();
_initialized = true; _initialized = true;

View File

@ -67,17 +67,18 @@ namespace sgpem
*/ */
static PythonPolicyManager* const get_instance(); static PythonPolicyManager* const get_instance();
private: protected:
/** The selected and active PyhonPolicy object. */
PythonPolicyManager(); PythonPolicyManager();
std::auto_ptr<PythonPolicy> _python_policy;
private:
PythonPolicyManager(const PythonPolicyManager&); PythonPolicyManager(const PythonPolicyManager&);
PythonPolicyManager& operator=(const PythonPolicyManager&); PythonPolicyManager& operator=(const PythonPolicyManager&);
/** Singleton support. */ /** Singleton support. */
static PythonPolicyManager* _instance; static PythonPolicyManager* _instance;
/** The selected and active PyhonPolicy object. */
std::auto_ptr<PythonPolicy> _python_policy;
bool _initialized; bool _initialized;
}; };

View File

@ -72,7 +72,7 @@ main(int argc, char* argv[])
// Set up Glib thread support // Set up Glib thread support
Glib::thread_init(); Glib::thread_init();
/*
// Parses options and prepares vector with // Parses options and prepares vector with
// filenames of documents to be opened // filenames of documents to be opened
vector<string> filenames; vector<string> filenames;
@ -82,7 +82,7 @@ main(int argc, char* argv[])
parse_options(a_count, a_ptr); parse_options(a_count, a_ptr);
filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count);
} }
*/
// Create an INITIAL STATE // Create an INITIAL STATE
Process p1("P1", 0,5,1); Process p1("P1", 0,5,1);

View File

@ -0,0 +1,19 @@
from Policy import Policy
import sys
class python_loader_configure(Policy) :
def __init__(self):
pass;
def configure(self):
while True:
pass
def is_preemptive(self):
return False
def get_time_slice(self):
return -1
def sort_queue(self, event, queue):
pass

View File

@ -0,0 +1,20 @@
from Policy import Policy
import sys
class python_loader_get_time_slice(Policy) :
def __init__(self):
pass
def configure(self):
pass
def is_preemptive(self):
return False
def get_time_slice(self):
while True:
pass
return -1
def sort_queue(self, event, queue):
pass

View File

@ -0,0 +1,20 @@
from Policy import Policy
import sys
class python_loader_is_preemptive(Policy) :
def __init__(self):
pass
def configure(self):
pass
def is_preemptive(self):
while True:
pass
return False
def get_time_slice(self):
return -1
def sort_queue(self, event, queue):
pass

View File

@ -0,0 +1,19 @@
from Policy import Policy
import sys
class python_loader_sort_queue(Policy) :
def __init__(self):
pass
def configure(self):
pass
def is_preemptive(self):
return False
def get_time_slice(self):
return -1
def sort_queue(self, event, queue):
while True:
pass

View File

@ -23,6 +23,7 @@
* here, thanks very much. */ * here, thanks very much. */
#include "backend/pyloader/python_policy_manager.hh" #include "backend/pyloader/python_policy_manager.hh"
#include "backend/pyloader/python_policy.hh"
#include "backend/process.hh" #include "backend/process.hh"
#include "backend/schedulable_status.hh" #include "backend/schedulable_status.hh"
#include "backend/schedulable_list.hh" #include "backend/schedulable_list.hh"
@ -31,49 +32,42 @@
#include "text_simulation.hh" #include "text_simulation.hh"
#include "templates/smartp.hh" #include "templates/smartp.hh"
#include <Python.h>
#include <glibmm/module.h> #include <glibmm/module.h>
#include <cassert> #include <cassert>
#include <string> #include <string>
class TestPythonPolicyManager : public PythonPolicyManager {
public:
void test_init(const char* policy_name) {
init();
PyRun_SimpleString("import sys\n"
"sys.path[:0] = [ '" MODDIR "', '" POLDIR "' ]\n");
_python_policy = std::auto_ptr<PythonPolicy>(new PythonPolicy(policy_name));
}
};
int int
main(int argc, char** argv) { main(int argc, char** argv) {
using namespace sgpem; using namespace sgpem;
using Glib::Module; using Glib::Module;
std::string pyloader_path = Module::build_path(MODDIR, "pyloader");
Glib::Module pyloader(pyloader_path);
assert(pyloader);
Glib::thread_init(); Glib::thread_init();
// Create an INITIAL STATE // Create an INITIAL STATE
Process p1("P1", 0,5,1); 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 ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
SchedulableList initial; SchedulableList initial;
initial.add_at_bottom(ss1); 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); History::get_instance().enqueue_slice(initial);
Scheduler::get_instance(); // Forces initialization of scheduler. Scheduler::get_instance(); // Forces initialization of scheduler.
// Cross fingers (depends if PythonPolicyManager // Cross fingers
// static object has been initialized before?).
//the textual simulation //the textual simulation
TextSimulation text_sim; TextSimulation text_sim;
@ -83,6 +77,21 @@ main(int argc, char** argv) {
memory::smart_ptr<IOManager> io(new StandardIO()); memory::smart_ptr<IOManager> io(new StandardIO());
text_sim.add_io_device(io); text_sim.add_io_device(io);
text_sim.update(); text_sim.update();
// Self-register itself to Scheduler
TestPythonPolicyManager polman;
polman.test_init("python_loader_configure");
text_sim.run(); text_sim.run();
polman.test_init("python_loader_is_preemptive");
text_sim.run();
polman.test_init("python_loader_get_time_slice");
text_sim.run();
polman.test_init("python_loader_sort_queue");
text_sim.run();
exit(0); exit(0);
} }