From 6a0bf4f44486e0c8ba172522a6436e93703de431 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Wed, 8 Mar 2006 16:47:39 +0000 Subject: [PATCH] - 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 --- ChangeLog | 17 ++++++ Makefile.am | 9 +++- src/backend/pyloader/python_policy.hh | 5 +- src/backend/pyloader/python_policy_manager.cc | 7 ++- src/backend/pyloader/python_policy_manager.hh | 9 ++-- src/main.cc | 4 +- src/testsuite/python_loader_configure.py | 19 +++++++ src/testsuite/python_loader_get_time_slice.py | 20 +++++++ src/testsuite/python_loader_is_preemptive.py | 20 +++++++ src/testsuite/python_loader_sort_queue.py | 19 +++++++ src/testsuite/test-python_loader.cc | 53 +++++++++++-------- 11 files changed, 145 insertions(+), 37 deletions(-) create mode 100644 src/testsuite/python_loader_configure.py create mode 100644 src/testsuite/python_loader_get_time_slice.py create mode 100644 src/testsuite/python_loader_is_preemptive.py create mode 100644 src/testsuite/python_loader_sort_queue.py diff --git a/ChangeLog b/ChangeLog index b90a1e2..46cef03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 * trunk/src/templates/smartp.tcc: - Fix obscure bug (with reference diff --git a/Makefile.am b/Makefile.am index d359e90..6def8d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,7 @@ bin_PROGRAMS = plugin_LTLIBRARIES = noinst_HEADERS = pkglib_LTLIBRARIES = +tests_PYTHON = EXTRA_DIST = MAINTAINERCLEANFILES = MOSTLYCLEANFILES = @@ -329,7 +330,7 @@ tests_PROGRAMS = src/testsuite/test-python_loader src_testsuite_test_python_loader_CPPFLAGS = \ -I@top_srcdir@/src \ - -DPOLDIR="\"$(policiesdir)\"" \ + -DPOLDIR="\"$(testsdir)\"" \ -DMODDIR="\"$(pyloaderdir)\"" \ $(PYTHON_CPPFLAGS) \ $(GLIBMM_CFLAGS) \ @@ -338,6 +339,7 @@ src_testsuite_test_python_loader_DEPENDENCIES = \ src/backend/pyloader/libpyloader.la src_testsuite_test_python_loader_LDFLAGS = \ src/backend/libbackend.la \ + src/backend/pyloader/libpyloader.la \ $(GTKMM_LIBS) $(GTHREAD_LIBS) src_testsuite_test_python_loader_SOURCES = \ src/testsuite/test-python_loader.cc \ @@ -346,6 +348,11 @@ src_testsuite_test_python_loader_SOURCES = \ src/observer.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 # while it's finishing the distcheck target CLEANFILES += src/testsuite/.libs/test-python_loader diff --git a/src/backend/pyloader/python_policy.hh b/src/backend/pyloader/python_policy.hh index 8a6466a..4c65f3a 100644 --- a/src/backend/pyloader/python_policy.hh +++ b/src/backend/pyloader/python_policy.hh @@ -45,9 +45,7 @@ namespace sgpem class SG_DLLEXPORT PythonPolicy : public Policy { public: - //only PythonPolicyManager can create a PythonPolicy object - friend class PythonPolicyManager; - + PythonPolicy(const char* name); virtual ~PythonPolicy(); /** @@ -77,7 +75,6 @@ namespace sgpem int get_time_slice() const throw(UserInterruptException); private: - PythonPolicy(const char* name); PythonPolicy(const PythonPolicy&); PythonPolicy& operator=(const PythonPolicy&); diff --git a/src/backend/pyloader/python_policy_manager.cc b/src/backend/pyloader/python_policy_manager.cc index 4be5d0a..705de4e 100644 --- a/src/backend/pyloader/python_policy_manager.cc +++ b/src/backend/pyloader/python_policy_manager.cc @@ -56,10 +56,9 @@ PythonPolicyManager::get_policy() void PythonPolicyManager::init() { - if(_initialized) { - _python_policy = std::auto_ptr(0); - Py_Finalize(); - } + if(_initialized) + // No-op + return; Py_Initialize(); _initialized = true; diff --git a/src/backend/pyloader/python_policy_manager.hh b/src/backend/pyloader/python_policy_manager.hh index 7090481..85a2673 100644 --- a/src/backend/pyloader/python_policy_manager.hh +++ b/src/backend/pyloader/python_policy_manager.hh @@ -67,17 +67,18 @@ namespace sgpem */ static PythonPolicyManager* const get_instance(); - private: + protected: + /** The selected and active PyhonPolicy object. */ PythonPolicyManager(); + std::auto_ptr _python_policy; + + private: PythonPolicyManager(const PythonPolicyManager&); PythonPolicyManager& operator=(const PythonPolicyManager&); /** Singleton support. */ static PythonPolicyManager* _instance; - /** The selected and active PyhonPolicy object. */ - std::auto_ptr _python_policy; - bool _initialized; }; diff --git a/src/main.cc b/src/main.cc index 1c5beb7..e897805 100644 --- a/src/main.cc +++ b/src/main.cc @@ -72,7 +72,7 @@ main(int argc, char* argv[]) // Set up Glib thread support Glib::thread_init(); - /* + // Parses options and prepares vector with // filenames of documents to be opened vector filenames; @@ -82,7 +82,7 @@ main(int argc, char* argv[]) parse_options(a_count, a_ptr); filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); } - */ + // Create an INITIAL STATE Process p1("P1", 0,5,1); diff --git a/src/testsuite/python_loader_configure.py b/src/testsuite/python_loader_configure.py new file mode 100644 index 0000000..b15ca09 --- /dev/null +++ b/src/testsuite/python_loader_configure.py @@ -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 diff --git a/src/testsuite/python_loader_get_time_slice.py b/src/testsuite/python_loader_get_time_slice.py new file mode 100644 index 0000000..37e1cea --- /dev/null +++ b/src/testsuite/python_loader_get_time_slice.py @@ -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 diff --git a/src/testsuite/python_loader_is_preemptive.py b/src/testsuite/python_loader_is_preemptive.py new file mode 100644 index 0000000..01f6fc3 --- /dev/null +++ b/src/testsuite/python_loader_is_preemptive.py @@ -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 diff --git a/src/testsuite/python_loader_sort_queue.py b/src/testsuite/python_loader_sort_queue.py new file mode 100644 index 0000000..5accd57 --- /dev/null +++ b/src/testsuite/python_loader_sort_queue.py @@ -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 diff --git a/src/testsuite/test-python_loader.cc b/src/testsuite/test-python_loader.cc index e3b3c68..ce836ca 100644 --- a/src/testsuite/test-python_loader.cc +++ b/src/testsuite/test-python_loader.cc @@ -23,6 +23,7 @@ * here, thanks very much. */ #include "backend/pyloader/python_policy_manager.hh" +#include "backend/pyloader/python_policy.hh" #include "backend/process.hh" #include "backend/schedulable_status.hh" #include "backend/schedulable_list.hh" @@ -31,49 +32,42 @@ #include "text_simulation.hh" #include "templates/smartp.hh" +#include #include #include #include +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(new PythonPolicy(policy_name)); + } +}; + + int main(int argc, char** argv) { 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?). + // Cross fingers //the textual simulation TextSimulation text_sim; @@ -83,6 +77,21 @@ main(int argc, char** argv) { memory::smart_ptr io(new StandardIO()); text_sim.add_io_device(io); text_sim.update(); + + // Self-register itself to Scheduler + TestPythonPolicyManager polman; + + polman.test_init("python_loader_configure"); 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); }