OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for functions in runtest.py.""" | 6 """Unit tests for functions in runtest.py.""" |
7 | 7 |
8 import unittest | 8 import unittest |
9 | 9 |
10 import test_env # pylint: disable=W0403,W0611 | 10 import test_env # pylint: disable=W0403,W0611 |
11 | 11 |
12 import mock | 12 import mock |
13 from slave import runtest | 13 from slave import runtest |
14 | 14 |
15 | 15 |
| 16 # Note: The git-svn id / cr pos is intentionally modified. |
| 17 # Also commit messages modified to be < 80 char. |
| 18 CHROMIUM_LOG = """ |
| 19 Update GPU rasterization device whitelist |
| 20 |
| 21 This replaces the whitelisting of all Qualcomm GPUs on |
| 22 Android 4.4 with whitelisting all Android 4.4 devices |
| 23 with GL ES version >= 3.0. |
| 24 |
| 25 BUG=405646 |
| 26 |
| 27 Review URL: https://codereview.chromium.org/468103003 |
| 28 |
| 29 Cr-Commit-Position: refs/heads/master@{#291141} |
| 30 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291140 0039d316-1c4b-4281 |
| 31 """ |
| 32 |
| 33 BLINK_LOG = """ |
| 34 [Sheriff-o-matic] Remove race condition on the commit list. |
| 35 |
| 36 By always modifying the same list of commits, we ensure that data binding |
| 37 |
| 38 As well, renamed "revisionLog" to "commitLog" everywhere, to better reflect |
| 39 |
| 40 BUG=405327 |
| 41 NOTRY=true |
| 42 |
| 43 Review URL: https://codereview.chromium.org/485253004 |
| 44 |
| 45 git-svn-id: svn://svn.chromium.org/blink/trunk@180728 bbb929c8-8fbe-4397-9dbb-9 |
| 46 """ |
| 47 |
| 48 |
16 class FakeLogProcessor(object): | 49 class FakeLogProcessor(object): |
17 """A fake log processor to use in the test below.""" | 50 """A fake log processor to use in the test below.""" |
18 | 51 |
19 def __init__(self, output): | 52 def __init__(self, output): |
20 self._output = output | 53 self._output = output |
21 | 54 |
22 def PerformanceLogs(self): | 55 def PerformanceLogs(self): |
23 return self._output | 56 return self._output |
24 | 57 |
25 | 58 |
(...skipping 29 matching lines...) Expand all Loading... |
55 # If it doesn't meet this expectation, ignore that graph. | 88 # If it doesn't meet this expectation, ignore that graph. |
56 self.assertEqual({}, runtest._GetDataFromLogProcessor(log_processor)) | 89 self.assertEqual({}, runtest._GetDataFromLogProcessor(log_processor)) |
57 | 90 |
58 def test_GetDataFromLogProcessor_InvalidJson(self): | 91 def test_GetDataFromLogProcessor_InvalidJson(self): |
59 log_processor = FakeLogProcessor({ | 92 log_processor = FakeLogProcessor({ |
60 'graph-summary.dat': ['this string is not valid json'] | 93 'graph-summary.dat': ['this string is not valid json'] |
61 }) | 94 }) |
62 self.assertEqual({}, runtest._GetDataFromLogProcessor(log_processor)) | 95 self.assertEqual({}, runtest._GetDataFromLogProcessor(log_processor)) |
63 | 96 |
64 | 97 |
| 98 class GetGitRevisionTest(unittest.TestCase): |
| 99 """Tests related to getting revisions from a directory.""" |
| 100 def test_GitSvnCase(self): |
| 101 # pylint: disable=W0212 |
| 102 self.assertEqual(runtest._GetGitCommitPositionFromLog(CHROMIUM_LOG), |
| 103 '291141') |
| 104 # pylint: disable=W0212 |
| 105 self.assertEqual(runtest._GetGitCommitPositionFromLog(BLINK_LOG), |
| 106 '180728') |
| 107 |
| 108 def test_GetCommitPosFromBuildPropTest(self): |
| 109 """Tests related to getting a commit position from build properties.""" |
| 110 # pylint: disable=W0212 |
| 111 self.assertEqual(runtest._GetCommitPos( |
| 112 {'got_revision_cp': 'refs/heads/master@{#12345}'}), 12345) |
| 113 # pylint: disable=W0212 |
| 114 self.assertIsNone(runtest._GetCommitPos({'got_revision': 12345})) |
| 115 |
| 116 |
65 class SendResultsToDashboardTest(unittest.TestCase): | 117 class SendResultsToDashboardTest(unittest.TestCase): |
66 """Tests related to sending requests and saving data from failed requests.""" | 118 """Tests related to sending requests and saving data from failed requests.""" |
67 | 119 |
68 def setUp(self): | 120 def setUp(self): |
69 super(SendResultsToDashboardTest, self).setUp() | 121 super(SendResultsToDashboardTest, self).setUp() |
70 | 122 |
71 # Testing private method _GetDataFromLogProcessor. | 123 # Testing private method _GetDataFromLogProcessor. |
72 # Also, this test method doesn't reference self. | 124 # Also, this test method doesn't reference self. |
73 # pylint: disable=W0212,R0201 | 125 # pylint: disable=W0212,R0201 |
74 @mock.patch('slave.runtest._GetDataFromLogProcessor') | 126 @mock.patch('slave.runtest._GetDataFromLogProcessor') |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 'buildnumber': 123, | 267 'buildnumber': 123, |
216 'revisions': {'rev': 343}, | 268 'revisions': {'rev': 343}, |
217 'supplemental_columns': {}}) | 269 'supplemental_columns': {}}) |
218 | 270 |
219 # Should not call functions to generate JSON and send to JSON if Telemetry | 271 # Should not call functions to generate JSON and send to JSON if Telemetry |
220 # did not return results. | 272 # did not return results. |
221 self.assertFalse(MakeDashboardJsonV1.called) | 273 self.assertFalse(MakeDashboardJsonV1.called) |
222 self.assertFalse(SendResults.called) | 274 self.assertFalse(SendResults.called) |
223 fake_results_tracker.Cleanup.assert_called_with() | 275 fake_results_tracker.Cleanup.assert_called_with() |
224 | 276 |
| 277 def test_GetTelemetryRevisions(self): |
| 278 options = mock.MagicMock() |
| 279 options.point_id = 1470050195 |
| 280 options.revision = '294850' |
| 281 options.webkit_revision = '34f9d01' |
| 282 options.build_properties = { |
| 283 'got_webrtc_revision': None, |
| 284 'got_v8_revision': 'undefined', |
| 285 'git_revision': '9a7b354', |
| 286 } |
| 287 versions = runtest._GetTelemetryRevisions(options) |
| 288 self.assertEqual( |
| 289 {'rev': '294850', 'webkit_rev': '34f9d01', 'git_revision': '9a7b354', |
| 290 'point_id': 1470050195}, |
| 291 versions) |
225 | 292 |
226 if __name__ == '__main__': | 293 if __name__ == '__main__': |
227 unittest.main() | 294 unittest.main() |
OLD | NEW |