blob: 0170662f5ffcb4cdd350a9567a68aae48cc94914 [file] [log] [blame]
A.R Karthick7eb2ce02016-06-10 19:00:50 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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
A.R Karthick7eb2ce02016-06-10 19:00:50 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A.R Karthick7eb2ce02016-06-10 19:00:50 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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 Karthicka2e53d62016-02-19 17:38:30 -080016class 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:
A R Karthick76a497a2017-04-12 10:59:39 -070031 print('Current state: %s, Current event: %s' %(self.stateTable.toStr(self.currentState),
32 self.eventTable.toStr(self.currentEvent)))
A R Karthicka2e53d62016-02-19 17:38:30 -080033 key = (self.currentState, self.currentEvent)
34 (actions, nextState) = self.fsmTable[key]
35 if actions:
36 for a in actions:
37 a()
A.R Karthick7eb2ce02016-06-10 19:00:50 -070038 self.currentState = nextState if self.nextState is None else self.nextState
A R Karthicka2e53d62016-02-19 17:38:30 -080039 self.currentEvent = self.nextEvent