blob: e6b95af76d9eae8fe0594ead377f53e3c8c0e39a [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
16
A.R Karthick7eb2ce02016-06-10 19:00:50 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
A.R Karthick7eb2ce02016-06-10 19:00:50 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
A.R Karthick7eb2ce02016-06-10 19:00:50 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
A R Karthicka2e53d62016-02-19 17:38:30 -080032class CordTester(object):
33
34 def __init__(self, fsmTable, stopState, stateTable = None, eventTable = None):
35 self.fsmTable = fsmTable
36 self.stopState = stopState
37 self.stateTable = stateTable
38 self.eventTable = eventTable
39 self.currentState = None
40 self.currentEvent = None
41 self.nextState = None
42 self.nextEvent = None
43
44 def runTest(self):
45 while self.currentState != self.stopState and self.currentEvent != None:
46 if self.stateTable and self.eventTable:
A R Karthick76a497a2017-04-12 10:59:39 -070047 print('Current state: %s, Current event: %s' %(self.stateTable.toStr(self.currentState),
48 self.eventTable.toStr(self.currentEvent)))
A R Karthicka2e53d62016-02-19 17:38:30 -080049 key = (self.currentState, self.currentEvent)
50 (actions, nextState) = self.fsmTable[key]
51 if actions:
52 for a in actions:
53 a()
A.R Karthick7eb2ce02016-06-10 19:00:50 -070054 self.currentState = nextState if self.nextState is None else self.nextState
A R Karthicka2e53d62016-02-19 17:38:30 -080055 self.currentEvent = self.nextEvent