Commit dc427a7e authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix list of active tc for random simulation

parent 12329335
...@@ -34,6 +34,7 @@ LICENSE: LGPL - see LICENSE file ...@@ -34,6 +34,7 @@ LICENSE: LGPL - see LICENSE file
CHANGELOG: CHANGELOG:
1.5.5 - Bugfix for random simulation
1.5.4 - Bugfix - needed for MSC editor 1.5.4 - Bugfix - needed for MSC editor
1.5.3 - Minor accomodation for the MSC editor 1.5.3 - Minor accomodation for the MSC editor
1.5.2 - Minor bugfix with SDL interface 1.5.2 - Minor bugfix with SDL interface
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
__author__ = "Maxime Perrotin" __author__ = "Maxime Perrotin"
__license__ = "LGPLv3" __license__ = "LGPLv3"
__version__ = "1.5.4" __version__ = "1.5.5"
__url__ = "http://taste.tuxfamily.org" __url__ = "http://taste.tuxfamily.org"
import sys import sys
......
...@@ -128,8 +128,9 @@ class sdlHandler(QObject): ...@@ -128,8 +128,9 @@ class sdlHandler(QObject):
self.proc = root_ast.processes[0] self.proc = root_ast.processes[0]
except IndexError: except IndexError:
raise IOError('SDL Handler failed to initialize') raise IOError('SDL Handler failed to initialize')
#opengeode.Helper.flatten(self.proc)
graph = opengeode.Statechart.create_dot_graph(self.proc, basic=True) graph = opengeode.Statechart.create_dot_graph(self.proc, basic=True)
# Flatten the model to have the nested states names in process.mapping
opengeode.Helper.flatten(self.proc)
self.sdl_scene = opengeode.SDL_Scene('statechart') self.sdl_scene = opengeode.SDL_Scene('statechart')
self.sdl_view = opengeode.SDL_View(self.sdl_scene) self.sdl_view = opengeode.SDL_View(self.sdl_scene)
opengeode.Statechart.render_statechart(self.sdl_scene, graph) opengeode.Statechart.render_statechart(self.sdl_scene, graph)
...@@ -181,8 +182,13 @@ class sdlHandler(QObject): ...@@ -181,8 +182,13 @@ class sdlHandler(QObject):
def active_tc(self): def active_tc(self):
''' Yield list of TCs that can be sent (including timeouts) ''' ''' Yield list of TCs that can be sent (including timeouts) '''
# Find the list of allowed TC based on the current state # Find the list of allowed TC based on the current state
st = self.current_sdl_state curr_state = self.current_sdl_state.replace(UNICODE_SEP, '_').lower()
inputs = self.proc.mapping[st.replace(UNICODE_SEP, '_').lower()] try:
inputs = self.proc.mapping[curr_state]
except KeyError:
# Raised in there is a bug in the tool
print curr_state, 'not in', self.proc.mapping.keys(), '(BUG?)'
else:
allowed_tc = (tc for each in inputs for tc in each.inputlist) allowed_tc = (tc for each in inputs for tc in each.inputlist)
for each in allowed_tc: for each in allowed_tc:
if each in self.timers and not self.buttons[each].isEnabled(): if each in self.timers and not self.buttons[each].isEnabled():
...@@ -541,34 +547,37 @@ class sdlHandler(QObject): ...@@ -541,34 +547,37 @@ class sdlHandler(QObject):
''' Depending on the current SDL state, enable or disable the buttons ''' Depending on the current SDL state, enable or disable the buttons
for sending TCs ''' for sending TCs '''
# Find the list of allowed TC based on the current state # Find the list of allowed TC based on the current state
st = self.current_sdl_state.split(UNICODE_SEP) # Removed all the logic below, self.active_tc is doing it already
st_iter = st.pop(0) # st = self.current_sdl_state.split(UNICODE_SEP)
context = self.proc # st_iter = st.pop(0)
# context = self.proc
def find_allowed_tc(context, statename): # statename = '_'.join(st).lower()
try: # def find_allowed_tc(context, statename):
inputs = context.mapping[statename.lower()] # try:
for each in inputs: # inputs = context.mapping[statename.lower()]
for inp in each.inputlist: # for each in inputs:
yield inp # for inp in each.inputlist:
except KeyError as err: # yield inp
# FIXME: State Aggregations are not in context.mapping # except KeyError as err:
print('State {} not supported/found'.format(statename)) # # FIXME: State Aggregations are not in context.mapping
# print('State {} not supported/found'.format(statename))
allowed_tc = list(find_allowed_tc(context, st_iter)) #
# print '1'
while len(st): # allowed_tc = list(find_allowed_tc(context, st_iter))
# Handle state composition # print '2'
next_st = st.pop(0) #
for each in context.composite_states: # while len(st):
if each.statename.lower() == st_iter.lower(): # # Handle state composition (when model is not flattened)
context = each # next_st = st.pop(0)
break # for each in context.composite_states:
allowed_tc.extend(list(find_allowed_tc(context, next_st))) # if each.statename.lower() == st_iter.lower():
st_iter = next_st # context = each
# break
# allowed_tc.extend(list(find_allowed_tc(context, next_st)))
# st_iter = next_st
# Remove timers from the list # Remove timers from the list
allowed_tc = set(allowed_tc) - set(self.proc.timers) allowed_tc = set(self.active_tc) - set(self.proc.timers)
# Enable/disable the parameterless TC buttons accordingly # Enable/disable the parameterless TC buttons accordingly
for tc, button in self.buttons.viewitems(): for tc, button in self.buttons.viewitems():
if tc in self.proc.timers: if tc in self.proc.timers:
...@@ -738,6 +747,7 @@ class sdlHandler(QObject): ...@@ -738,6 +747,7 @@ class sdlHandler(QObject):
nb_states += 1 nb_states += 1
print 'Visited', nb_states print 'Visited', nb_states
if nb_states >= max_states: if nb_states >= max_states:
print 'End (limit reached)'
return return
def exhaustive_simulation(self): def exhaustive_simulation(self):
...@@ -747,7 +757,6 @@ class sdlHandler(QObject): ...@@ -747,7 +757,6 @@ class sdlHandler(QObject):
self.sim_param['state'] = 'exhaustive' self.sim_param['state'] = 'exhaustive'
self.breadth_first() self.breadth_first()
def random_simulation(self): def random_simulation(self):
''' Random simulator - read the config from the checker_table and ''' Random simulator - read the config from the checker_table and
call TC either randomly or periodically, until the stop button is call TC either randomly or periodically, until the stop button is
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment