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