Commit 2646e4c7 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Prepare for exhaustive simulation

parent a9625d4c
......@@ -282,6 +282,8 @@ class sdlHandler(QObject):
# Keep a state graph to allow undo/redo and state exploration
self.set_of_states = {}
self.current_hash = None
# Flag set to true when a new state is created
self.new_state_created = False
# Create a stack for handling undo/redo commands
self.undo_stack = QUndoStack(self)
# Associate the Undo, Redo, Reset buttons with an action
......@@ -588,6 +590,11 @@ class sdlHandler(QObject):
root=self.tree_items['_states'])
# And save this new state in the graph, if it was not there yet
new_hash = hash(frozenset(complete_state))
# Set a flag indicating a new state was added
if new_hash not in self.set_of_states:
self.new_state_created = True
else:
self.new_state_created = False
self.set_of_states[new_hash] = complete_state
# Disable the TC buttons the current state does does allow
self.update_button_state(tc_name)
......@@ -646,40 +653,44 @@ class sdlHandler(QObject):
docks.append(dock)
return docks
def click_tc(self, name, arg=None):
''' Send a TC by clicking on the Send button automatically
Inputs: name of Input,
arg: parameter in GSER format (ASN.1 Value Notation)
Doing so enables Undo/Redo, MSC Trace, etc. '''
if name not in self.active_tc:
return
if name in self.buttons:
# paramless TC
self.buttons[name].click()
else:
# tc with a param, use the Send button
for vals in self.param_tc_editors:
if vals['name'] == name:
argpy = vn.fromValueNotationToPySide(name, arg)
vals['editor'].updateVariable(argpy)
vals['send_btn'].click()
def random_step(self):
''' One step of random simulation '''
def send_random_tc(name, asn1_ty=None):
''' Send a TC by clicking on the Send button automatically
Doing so enables Undo/Redo, MSC Trace, etc. '''
if name not in self.active_tc:
return
if name in self.buttons:
# paramless TC
self.buttons[name].click()
else:
# tc with a param, use the Send button
for vals in self.param_tc_editors:
if vals['name'] == name:
arg = compute_random_value(asn1_ty, self.proc.dataview)
argpy = vn.fromValueNotationToPySide(name, arg)
vals['editor'].updateVariable(argpy)
vals['send_btn'].click()
if self.sim_param['state'] != 'random':
return
arg = None
for name, asn1_ty in self.sim_param['periodic']:
send_random_tc(name, asn1_ty)
if asn1_ty:
arg = compute_random_value(asn1_ty, self.proc.dataview)
self.click_tc(name, arg)
# Select randomly an active TC and call it
random_tc = random.choice(list(self.active_tc))
ty = None
for inp in self.proc.input_signals:
if inp['name'].lower() == random_tc.lower():
sort = inp.get('type', None)
if sort:
typename = sort.ReferencedTypeName.replace('-', '_')
ty = self.proc.dataview[sort.ReferencedTypeName]
arg = compute_random_value(ty, self.proc.dataview)
break
send_random_tc(random_tc, ty)
self.click_tc(random_tc, arg)
QTimer().singleShot(1000, self.random_step)
......@@ -706,6 +717,17 @@ class sdlHandler(QObject):
print 'End of simulation'
self.sim_param['state'] = 'manual'
def exhaustive_simulation(self):
''' Model checker - try all combinations of all inputs in all
possible states, and verify properties on the fly '''
print 'Exhaustive simulation - Breadth first '
def exhaust_interface(name, asn1_ty):
''' Send all combinations of an input signal and return
a list of new states '''
for each in compute_combinations(asn1_ty, self.proc.dataview):
pass
@Slot()
def add_to_msc(self, direction, msg):
''' Create an undo command and display message on the MSC diagram '''
......@@ -880,6 +902,8 @@ class sdlHandler(QObject):
# Plug the "Random" button to the function handling random simulation
random_btn = widget.findChild(QToolButton, 'randomButton')
random_btn.pressed.connect(self.random_simulation)
exhaust_btn = widget.findChild(QToolButton, 'exhaustButton')
exhaust_btn.pressed.connect(self.exhaustive_simulation)
stop_btn = widget.findChild(QToolButton, 'stopButton')
stop_btn.pressed.connect(self.stop_simulation)
return checker_table
......
Markdown is supported
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