- Update test-python_loader, do not link to libpyloader anymore

- TODO: sigsegv (due to an hidden vtable?)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@519 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-03-09 21:56:16 +00:00
parent 3c75e1391d
commit ef733b37e8
13 changed files with 87 additions and 24 deletions

View File

@ -358,6 +358,7 @@ src_testsuite_test_history_SOURCES = \
src_testsuite_test_python_loader_CPPFLAGS = \
-I@top_srcdir@/src \
-DMODDIR="\"$(pyloaderdir)\"" \
$(PYTHON_CPPFLAGS) \
$(GLIBMM_CFLAGS) \
$(GTHREAD_CFLAGS)
@ -365,10 +366,14 @@ 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 \
$(GLIBMM_LIBS) $(GTHREAD_LIBS)
$(GLIBMM_LIBS) $(GTHREAD_LIBS) \
$(PYTHON_LDFLAGS) \
$(PYTHON_EXTRA_LIBS) \
$(PYTHON_EXTRA_LDFLAGS)
src_testsuite_test_python_loader_SOURCES = \
src/testsuite/test-python_loader.cc \
src/backend/pyloader/python_policy.cc \
src/backend/pyloader/python_policy_manager.cc \
src/standard_io.cc \
src/text_simulation.cc \
src/observer.cc \

View File

@ -173,6 +173,12 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException)
if(i++ > 120)
{
PyThreadState_Clear(_save);
PyEval_RestoreThread(_save);
//Py_UNBLOCK_THREADS;
throw UserInterruptException("User-defined policy is "
"taking too long to terminate.");
}

View File

@ -80,7 +80,7 @@ Scheduler::get_policy()
void
Scheduler::step_forward()
Scheduler::step_forward() throw(UserInterruptException)
{
try
{
@ -196,11 +196,13 @@ Scheduler::step_forward()
}
catch( UserInterruptException e )
{
// FIXME : Naive.
cerr << "Exception: " << e.what() << endl;
// Errrrr.... you won't like this:
_policy_manager.init();
throw;
//TODO Do we need to perform some cleanup operation here?
// Do we need to update something?
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
@ -210,3 +212,4 @@ Scheduler::step_forward()
// - SimulationController that everything stopped
}
}

View File

@ -35,6 +35,7 @@ namespace sgpem
#include "observed_subject.hh"
#include "history.hh"
#include "schedulable_list.hh"
#include "user_interrupt_exception.hh"
namespace sgpem
{
@ -96,7 +97,7 @@ namespace sgpem
at the simulation instant next to the current one, and extends the History by
one instant with it.
*/
void step_forward();
void step_forward() throw(UserInterruptException);
/**
Sets the policy that will be used to generate the simulation at the next instant.
\param policy the policy that will be used to generate the simulation at the next instant.

View File

@ -73,7 +73,7 @@ Simulation::reset()
}
void
Simulation::run()
Simulation::run() throw(UserInterruptException)
{
History& h = History::get_instance();
@ -105,12 +105,22 @@ loop:
return;
}
try
{
//step forward
Scheduler::get_instance().step_forward();
//sleep
Glib::usleep(_timer_interval*1000);
}
catch(UserInterruptException e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
@ -136,24 +146,43 @@ loop:
//by the last execution of upadate()
_state = state_paused;
else
{
try
{
//step forward
Scheduler::get_instance().step_forward();
}
catch(UserInterruptException e)
{
throw;
}
}
}
}
void
Simulation::jump_to(const uint& where)
Simulation::jump_to(const uint& where) throw(UserInterruptException)
{
//jump to position 0
reset();
bool old = _mode;
_mode = false;
try
{
// executes "where" steps
for (uint i=0; i < where; i++)
run();
}
catch(UserInterruptException e)
{
_mode = old;
throw;
}
_state = state_paused;
_mode = old;

View File

@ -72,7 +72,7 @@ namespace sgpem
Advances the simulation by one or more steps, depending on the
actual state and on the value set with set_mode().
*/
void run();
void run() throw(UserInterruptException);
/**
\brief Pauses a running simulation.
@ -103,7 +103,7 @@ namespace sgpem
/**
\brief Causes the simulation to jump to the given time unit.
*/
void jump_to(const uint&);
void jump_to(const uint&) throw(UserInterruptException);
/**
\brief Setter for the attribute timer_interval.

View File

@ -6,6 +6,7 @@ class python_loader_configure(Policy) :
pass;
def configure(self):
print "[II] Entering willingly an endless loop."
while True:
pass

View File

@ -12,6 +12,7 @@ class python_loader_get_time_slice(Policy) :
return False
def get_time_slice(self):
print "[II] Entering willingly an endless loop."
while True:
pass
return -1

View File

@ -9,6 +9,7 @@ class python_loader_is_preemptive(Policy) :
pass
def is_preemptive(self):
print "[II] Entering willingly an endless loop."
while True:
pass
return False

View File

@ -15,5 +15,6 @@ class python_loader_sort_queue(Policy) :
return -1
def sort_queue(self, event, queue):
print "[II] Entering willingly an endless loop."
while True:
pass

View File

@ -62,7 +62,7 @@ main(int argc, char** argv) {
exit(-1);
}
else
// Add current directory to search for uninstalled policies
// Add argv[1] as the directory to search for uninstalled policies
sgpem::GlobalSettings::instance().add_policies_dir(argv[1]);
Glib::thread_init();
@ -94,15 +94,19 @@ main(int argc, char** argv) {
polman.test_init("python_loader_configure");
text_sim.run();
text_sim.stop();
polman.test_init("python_loader_is_preemptive");
text_sim.run();
text_sim.stop();
polman.test_init("python_loader_get_time_slice");
text_sim.run();
text_sim.stop();
polman.test_init("python_loader_sort_queue");
text_sim.run();
text_sim.stop();
exit(0);
}

View File

@ -110,8 +110,19 @@ check:
"by its priority enclosed between round parenthesis."));
return;
}
try
{
obj->run();
}
catch(UserInterruptException e)
{
obj->_devices[quale]->write_buffer(_("\nERROR: "));
obj->_devices[quale]->write_buffer(_(e.what()));
obj->_devices[quale]->write_buffer(_("\nSimulation is now stopped"));
}
}
else if (arguments[param] == "PAUSE")
{
if (show_help)