Chromium Code Reviews| 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..e1923e2ca2f2c338413011d24f300898dae105ff |
| --- /dev/null |
| +++ b/telemetry/telemetry/story/expectations.py |
| @@ -0,0 +1,89 @@ |
| +# 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 TestConditions(object): |
|
perezju
2017/05/02 09:19:52
Throwing out for consideration a half-baked idea (
rnephew (Reviews Here)
2017/05/10 19:45:13
I really like this idea.
Done.
|
| + MAC = 'mac' |
| + WIN = 'win' |
| + LINUX = 'linux' |
| + ANDROID = 'android' |
| + MOBILE = 'mobile' |
| + DESKTOP = 'desktop' |
| + ALL = 'all' |
| + NO_BATTOR = 'no_battor' |
| + |
| + _DESKTOP_PLATFORMS = ['mac', 'win', 'linux'] |
| + _MOBILE_PLATFORMS = ['android'] |
| + |
| + @classmethod |
| + def IsDesktop(cls, platform): |
| + return platform in cls._DESKTOP_PLATFORMS |
| + |
| + @classmethod |
| + def IsMobile(cls, platform): |
| + return platform in cls._MOBILE_PLATFORMS |
| + |
| + |
| +class StoryExpectations(object): |
| + def __init__(self): |
| + self._expectations = {'disabled_platforms': []} |
|
perezju
2017/05/02 09:19:52
I know it's unlikely that we'll have a story named
rnephew (Reviews Here)
2017/05/10 19:45:13
Done.
|
| + 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, platforms, reason): |
| + assert not self._frozen, ('Cannot disable benchmark on a frozen ' |
| + 'StoryExpectation object.') |
| + self._expectations['disabled_platforms'].append((platforms, reason)) |
| + |
| + @staticmethod |
| + def _CommonPlatformChecks(platforms, state): |
| + current_platform = state.platform.GetOSName() |
| + if TestConditions.ALL in platforms: |
| + return True |
| + if (TestConditions.NO_BATTOR in platforms and |
| + not state.platform.HasBattOrConnected()): |
| + return True |
| + if current_platform in platforms: |
| + return True |
| + if (TestConditions.DESKTOP in platforms and |
| + TestConditions.IsDesktop(current_platform)): |
| + return True |
| + if (TestConditions.MOBILE in platforms and |
| + TestConditions.IsMobile(current_platform)): |
| + return True |
| + |
| + return False |
| + |
| + def IsBenchmarkDisabled(self, state): |
| + reason_for = None |
| + for platforms, reason in self._expectations.get('disabled_platforms'): |
| + if self._CommonPlatformChecks(platforms, state): |
| + reason_for = reason |
| + break |
| + return reason_for is not None, reason_for |
| + |
| + def DisableStory(self, story, platforms, reason=''): |
|
nednguyen
2017/05/02 00:04:01
s/platforms/conditions/g
we should also assert all
perezju
2017/05/02 09:19:52
Let's not provide a default for "reason", it shoul
nednguyen
2017/05/09 16:44:24
In addition, I think we should even assert that re
rnephew (Reviews Here)
2017/05/10 19:45:13
Done.
rnephew (Reviews Here)
2017/05/10 19:45:13
Done.
|
| + assert not self._frozen, ('Cannot disable stories on a frozen ' |
| + 'StoryExpectation object.') |
| + if not self._expectations.get(str(story)): |
| + self._expectations[str(story)] = [] |
|
nednguyen
2017/05/02 00:04:02
I don't think we should key by str(story). These 3
perezju
2017/05/02 09:19:52
Related, we should probably do an overall cleanup
nednguyen
2017/05/02 16:44:42
+1. I discussed with Ashley offline. We should do
nednguyen
2017/05/09 16:44:24
Discuss offline. We can move forward with this & d
rnephew (Reviews Here)
2017/05/10 19:45:13
1 is done, is there a way to do 2 as a linter warn
nednguyen
2017/05/10 20:01:38
It's not easy to add linter warning, and I doubt t
rnephew (Reviews Here)
2017/05/11 15:05:58
Thats what I feared (it not being easy and/or reli
|
| + self._expectations[str(story)].append((platforms, reason)) |
| + |
| + def IsStoryDisabled(self, story, state): |
| + reason_for = None |
| + for platforms, reason in self._expectations.get(str(story), []): |
| + if self._CommonPlatformChecks(platforms, state): |
| + reason_for = reason |
| + break |
| + return reason_for is not None, reason_for |
|
perezju
2017/05/02 09:19:52
when logging, I would also like to know the condit
rnephew (Reviews Here)
2017/05/10 19:45:13
Its returning a tuple of (is_disabled, reason)
perezju
2017/05/11 10:10:41
Yes, but the _condition_ is missing.
rnephew (Reviews Here)
2017/05/11 15:05:58
The reason (be it a bug or a text description) sho
perezju
2017/05/11 15:26:53
I've seen enough cases of "@disabled('win', crbug.
rnephew (Reviews Here)
2017/05/11 15:42:49
I see your point, and I think there are two possib
perezju
2017/05/11 16:14:28
No strong opinions on the implementation, but I wo
rnephew (Reviews Here)
2017/05/11 17:14:11
Done.
|