Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: telemetry/telemetry/story/expectations.py

Issue 2843403005: [Telemetry] Add Expectation module that enables disabling benchmarks/stories (Closed)
Patch Set: [Telemetry] Have benchmarks have story expectations. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: telemetry/telemetry/story/expectations.py
diff --git a/telemetry/telemetry/story/expectations.py b/telemetry/telemetry/story/expectations.py
new file mode 100644
index 0000000000000000000000000000000000000000..6e843f1e6000324dd266074c887517c549e09c33
--- /dev/null
+++ b/telemetry/telemetry/story/expectations.py
@@ -0,0 +1,121 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+class StoryExpectations(object):
+ def __init__(self):
+ self._disabled_platforms = []
+ self._expectations = {}
+ self._frozen = False
+ self.SetExpectations()
+ self._Freeze()
+
+ def SetExpectations(self):
+ """ Sets the Expectations for test disabling
+
+ Override in subclasses to disable tests."""
+ pass
+
+ def _Freeze(self):
+ self._frozen = True
+
+ def DisableBenchmark(self, conditions, reason):
nednguyen 2017/05/10 21:10:57 Add doc string for this. Also include example of h
rnephew (Reviews Here) 2017/05/10 21:28:32 Done.
+ assert reason
+ assert not self._frozen, ('Cannot disable benchmark on a frozen '
+ 'StoryExpectation object.')
+ for condition in conditions:
+ assert issubclass(condition, _TestCondition)
+
+ self._disabled_platforms.append((conditions, reason))
+
+ def IsBenchmarkDisabled(self, state):
nednguyen 2017/05/10 21:10:57 Same
rnephew (Reviews Here) 2017/05/10 21:28:32 Done.
+ for conditions, reason in self._disabled_platforms:
+ for condition in conditions:
+ if condition.ShouldDisable(state):
+ return True, reason
+ return False, None
+
+ def DisableStory(self, story_name, conditions, reason):
nednguyen 2017/05/10 21:10:57 Ditto
rnephew (Reviews Here) 2017/05/10 21:28:32 Done.
+ assert reason
+ assert len(story_name) < 30, 'Story name too long.'
+ assert not self._frozen, ('Cannot disable stories on a frozen '
+ 'StoryExpectation object.')
+ for condition in conditions:
+ assert issubclass(condition, _TestCondition)
+ if not self._expectations.get(story_name):
+ self._expectations[story_name] = []
+ self._expectations[story_name].append((conditions, reason))
+
+ def IsStoryDisabled(self, story, state):
nednguyen 2017/05/10 21:10:57 Ditto
rnephew (Reviews Here) 2017/05/10 21:28:32 Done.
+ for conditions, reason in self._expectations.get(story.display_name, []):
+ for condition in conditions:
+ if condition.ShouldDisable(state):
+ return True, reason
+ return False, None
+
+
+class _TestCondition(object):
+ @staticmethod
+ def ShouldDisable(state):
+ raise NotImplementedError
+
+
+class AllTestCondition(_TestCondition):
nednguyen 2017/05/10 21:10:57 let hide all these class with prefix "_" so users
rnephew (Reviews Here) 2017/05/10 21:28:32 Done.
+ @staticmethod
+ def ShouldDisable(_):
+ return True
+
+
+class MacTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return state.platform.GetOSName() == 'mac'
+
+
+class WinTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return state.platform.GetOSName() == 'win'
+
+
+class LinuxTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return state.platform.GetOSName() == 'linux'
+
+
+class AndroidTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return state.platform.GetOSName() == 'android'
+
+
+class DesktopTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ current_platform = state.platform.GetOSName()
+ return (current_platform == 'mac' or current_platform == 'win' or
+ current_platform == 'linux')
+
+
+class MobileTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return state.platform.GetOSName() == 'android'
+
+
+class NoBattOrTestCondition(_TestCondition):
+ @staticmethod
+ def ShouldDisable(state):
+ return not state.platform.HasBattOrConnected()
+
+
+ALL = AllTestCondition
+ALL_MAC = MacTestCondition
+ALL_WIN = WinTestCondition
+ALL_LINUX = LinuxTestCondition
+ALL_ANDROID = AndroidTestCondition
+ALL_DESKTOP = DesktopTestCondition
+ALL_MOBILE = MobileTestCondition
+NO_BATTOR = NoBattOrTestCondition

Powered by Google App Engine
This is Rietveld 408576698