blob: 5d78571836b2d5bfd5e4d5bd885209b5c7a82c7e [file] [log] [blame]
Chetan Gaonkercb122cc2016-05-10 10:58:34 -07001#!/usr/bin/env python
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002#
3# Copyright 2016-present Ciena Corporation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
A R Karthicka2e53d62016-02-19 17:38:30 -080017class CordTester(object):
18
19 def __init__(self, fsmTable, stopState, stateTable = None, eventTable = None):
20 self.fsmTable = fsmTable
21 self.stopState = stopState
22 self.stateTable = stateTable
23 self.eventTable = eventTable
24 self.currentState = None
25 self.currentEvent = None
26 self.nextState = None
27 self.nextEvent = None
28
29 def runTest(self):
30 while self.currentState != self.stopState and self.currentEvent != None:
31 if self.stateTable and self.eventTable:
32 print 'Current state: %s, Current event: %s' %(self.stateTable.toStr(self.currentState),
33 self.eventTable.toStr(self.currentEvent))
34 key = (self.currentState, self.currentEvent)
35 (actions, nextState) = self.fsmTable[key]
36 if actions:
37 for a in actions:
38 a()
39 self.currentState = nextState
40 self.currentEvent = self.nextEvent