[Coverage] Support criterion incoherent state
BZ: 115218
In case of incoherent log (corrupted), some transitions described
in the log are not permitted by the internal criterion state machine.
Resulting in raising an exception and stopping the program.
Add an optional parameter to ignore integrity.
Change-Id: I288c0e482b223aa0023e09fb158036b39d0ed8bf
Signed-off-by: Kevin Rocard <kevinx.rocard@intel.com>
Reviewed-on: http://android.intel.com:8080/112711
Reviewed-by: Denneulin, Guillaume <guillaume.denneulin@intel.com>
Reviewed-by: Gonzalve, Sebastien <sebastien.gonzalve@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: Dixon, CharlesX <charlesx.dixon@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/tools/coverage.py b/tools/coverage.py
index f62fd9a..5a00f45 100755
--- a/tools/coverage.py
+++ b/tools/coverage.py
@@ -594,7 +594,18 @@
tag = "Criterion"
inclusivenessTranslate = {True: "Inclusive", False: "Exclusive"}
- def __init__(self, name, isInclusif, stateNamesList, currentStateNamesList):
+ class ChangeRequestToNonAccessibleState(CustomError):
+ def __init__(self, requestedState, detail):
+ self.requestedState = requestedState
+ self.detail = detail
+
+ def __str__(self):
+ return ("Change request to non accessible state %s. Detail: %s" %
+ (self.requestedState, self.detail))
+
+ def __init__(self, name, isInclusif,
+ stateNamesList, currentStateNamesList,
+ ignoreIntegrity=False):
super().__init__(name)
self.isInclusif = isInclusif
@@ -602,21 +613,21 @@
self.addChild(CriterionState(state))
self.currentState = []
+ self.initStateNamesList = list(currentStateNamesList)
+ self.changeState(self.initStateNamesList, ignoreIntegrity)
- # Set current state as provided
- self.currentState = [self.getChildFromName(childName)
- for childName in currentStateNamesList]
+ def reset(self):
+ # Set current state as provided at initialisation
+ self.changeState(self.initStateNamesList, ignoreIntegrity=True)
- def childUsed(self, child):
- self.currentState = child
- super().childUsed(child)
-
- def changeState(self, subStateNames):
+ def changeState(self, subStateNames, ignoreIntegrity=False):
self.debug("Changing state from: %s to: %s" % (
list(self._getElementNames(self.currentState)),
subStateNames))
- assert(len(subStateNames) > 0 or self.isInclusif)
+ if not ignoreIntegrity and not self.isIntegre(subStateNames):
+ raise self.ChangeRequestToNonAccessibleState(subStateNames,
+ "An exclusive criterion must have a non empty state")
newCurrentState = []
for subStateName in subStateNames :
@@ -629,9 +640,17 @@
self._incNbUse()
self._tellParentThatChildUsed()
+ def isIntegre(self, subStateNames):
+ return self.isInclusif or len(subStateNames) == 1
+
+ def childUsed(self, child):
+ self.currentState = child
+ super().childUsed(child)
+
def export(self):
subStateNames = self._getElementNames(self.currentState)
- return Criterion(self.name, self.isInclusif, subStateNames, subStateNames)
+ return Criterion(self.name, self.isInclusif, subStateNames, subStateNames,
+ ignoreIntegrity=True)
def stateIncludes(self, subStateName):
subStateCurrentNames = list(self._getElementNames(self.currentState))