Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 1 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Module for task unittests.""" |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 6 | # pylint: disable=g-missing-super-call |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 7 | |
| 8 | import re |
| 9 | import unittest |
| 10 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 11 | import build_lib |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 12 | import config_reader |
| 13 | import mock |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 14 | import task |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 15 | import task_config_reader |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 16 | import tot_manager |
| 17 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 18 | class FakeTotMilestoneManager(tot_manager.TotMilestoneManager): |
| 19 | """Mock class for tot_manager.TotMilestoneManager.""" |
| 20 | |
| 21 | def __init__(self, is_sanity): |
| 22 | self.is_sanity = is_sanity |
| 23 | self.storage_client = None |
| 24 | self.tot = self._tot_milestone() |
| 25 | |
| 26 | |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 27 | class FakeLabConfig(object): |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 28 | """Mock class for config_reader.LabConfig.""" |
| 29 | |
| 30 | def get_cros_model_map(self): |
| 31 | return {'coral': ['robo', 'nasher', 'lava']} |
| 32 | |
| 33 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 34 | class TaskBaseTestCase(unittest.TestCase): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 35 | |
| 36 | BOARD = 'fake_board' |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 37 | UNIBUILD_BOARD = 'coral' |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 38 | EXCLUDE_BOARD = 'exclude_fake_board' |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 39 | NAME = 'fake_name' |
| 40 | SUITE = 'fake_suite' |
| 41 | POOL = 'fake_pool' |
| 42 | PLATFORM = '6182.0.0-rc2' |
| 43 | MILESTONE = '30' |
| 44 | NUM = 1 |
| 45 | PRIORITY = 50 |
| 46 | TIMEOUT = 600 |
| 47 | |
| 48 | def setUp(self): |
| 49 | tot_patcher = mock.patch('tot_manager.TotMilestoneManager') |
| 50 | self._mock_tot = tot_patcher.start() |
| 51 | self.addCleanup(tot_patcher.stop) |
| 52 | # Can't pass in False since storage_client is not mocked. |
| 53 | self._mock_tot.return_value = FakeTotMilestoneManager(True) |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 54 | self.task = task.Task(task_config_reader.TaskInfo( |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 55 | name=self.NAME, |
| 56 | suite=self.SUITE, |
| 57 | branch_specs=[], |
| 58 | pool=self.POOL, |
| 59 | num=self.NUM, |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 60 | boards=','.join([self.BOARD, self.UNIBUILD_BOARD]), |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 61 | exclude_boards=self.EXCLUDE_BOARD, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 62 | priority=self.PRIORITY, |
| 63 | timeout=self.TIMEOUT)) |
| 64 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 65 | self._empty_configs = config_reader.Configs( |
Xinan Lin | 576022d | 2020-01-21 18:12:47 -0800 | [diff] [blame] | 66 | lab_config=config_reader.LabConfig(None)) |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 67 | self._fake_configs = config_reader.Configs( |
Xinan Lin | 576022d | 2020-01-21 18:12:47 -0800 | [diff] [blame] | 68 | lab_config=FakeLabConfig()) |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 69 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 70 | self.firmware_dict = { |
| 71 | ('cros', 'fake_board'): ('fake_board-release/R30-6182.0.0-rc2'), |
| 72 | ('firmware', 'fake_board'): ('firmware-fake_board-12345.67.' |
| 73 | 'A-firmwarebranch/RFoo-1.0.0-b1234567' |
| 74 | '/fake_board') |
| 75 | } |
| 76 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 77 | |
| 78 | class TaskTestCase(TaskBaseTestCase): |
| 79 | |
| 80 | def setUp(self): |
| 81 | super(TaskTestCase, self).setUp() |
| 82 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 83 | mock_push = mock.patch('task.Task._push_suite') |
| 84 | self._mock_push = mock_push.start() |
| 85 | self.addCleanup(mock_push.stop) |
| 86 | |
| 87 | def testSetSpecCompareInfoEqual(self): |
| 88 | """Test compare info setting for specs that equals to a milestone.""" |
| 89 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot-2') |
| 90 | self.task._set_spec_compare_info() |
| 91 | self.assertTrue(self.task._version_equal_constraint) |
| 92 | self.assertFalse(self.task._version_gte_constraint) |
| 93 | self.assertFalse(self.task._version_lte_constraint) |
| 94 | self.assertEqual(self.task._bare_branches, []) |
| 95 | |
| 96 | def testSetSpecCompareInfoLess(self): |
| 97 | """Test compare info setting for specs that is less than a milestone.""" |
| 98 | self.task.branch_specs = re.split(r'\s*,\s*', '<=tot') |
| 99 | self.task._set_spec_compare_info() |
| 100 | self.assertFalse(self.task._version_equal_constraint) |
| 101 | self.assertFalse(self.task._version_gte_constraint) |
| 102 | self.assertTrue(self.task._version_lte_constraint) |
| 103 | self.assertEqual(self.task._bare_branches, []) |
| 104 | |
| 105 | def testSetSpecCompareInfoGreater(self): |
| 106 | """Test compare info setting for specs that is greater than a milestone.""" |
| 107 | self.task.branch_specs = re.split(r'\s*,\s*', '>=tot-2') |
| 108 | self.task._set_spec_compare_info() |
| 109 | self.assertFalse(self.task._version_equal_constraint) |
| 110 | self.assertTrue(self.task._version_gte_constraint) |
| 111 | self.assertFalse(self.task._version_lte_constraint) |
| 112 | self.assertEqual(self.task._bare_branches, []) |
| 113 | |
| 114 | def testFitsSpecEqual(self): |
| 115 | """Test milestone check for specs that equals to a milestone.""" |
| 116 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot-1') |
| 117 | self.task._set_spec_compare_info() |
| 118 | self.assertFalse(self.task._fits_spec('40')) |
| 119 | self.assertTrue(self.task._fits_spec('39')) |
| 120 | self.assertFalse(self.task._fits_spec('38')) |
| 121 | |
| 122 | def testFitsSpecLess(self): |
| 123 | """Test milestone check for specs that is less than a milestone.""" |
| 124 | self.task.branch_specs = re.split(r'\s*,\s*', '<=tot-1') |
| 125 | self.task._set_spec_compare_info() |
| 126 | self.assertFalse(self.task._fits_spec('40')) |
| 127 | self.assertTrue(self.task._fits_spec('39')) |
| 128 | self.assertTrue(self.task._fits_spec('38')) |
| 129 | |
| 130 | def testFitsSpecGreater(self): |
| 131 | """Test milestone check for specs that is greater than a milestone.""" |
| 132 | self.task.branch_specs = re.split(r'\s*,\s*', '>=tot-2') |
| 133 | self.task._set_spec_compare_info() |
| 134 | self.assertTrue(self.task._fits_spec('39')) |
| 135 | self.assertTrue(self.task._fits_spec('38')) |
| 136 | self.assertFalse(self.task._fits_spec('37')) |
| 137 | |
| 138 | def testGetFirmwareFromLabConfig(self): |
| 139 | """Test get firmware from lab config successfully.""" |
| 140 | with mock.patch('config_reader.LabConfig.get_firmware_ro_build_list', |
| 141 | return_value='build1,build2'): |
| 142 | firmware = self.task._get_firmware_build( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 143 | 'released_ro_2', self.BOARD, self.firmware_dict, |
| 144 | config_reader.LabConfig(None)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 145 | self.assertEqual(firmware, 'build2') |
| 146 | |
| 147 | def testGetFirmwareFromLabConfigOutofIndex(self): |
| 148 | """Test get firmware from lab config when firmware index is invalid.""" |
| 149 | with mock.patch('config_reader.LabConfig.get_firmware_ro_build_list', |
| 150 | return_value='build1,build2'): |
| 151 | self.assertRaises(ValueError, |
| 152 | self.task._get_latest_firmware_build_from_lab_config, |
| 153 | 'released_ro_3', |
| 154 | self.BOARD, |
| 155 | config_reader.LabConfig(None)) |
| 156 | self.assertIsNone(self.task._get_firmware_build( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 157 | 'released_ro_3', self.BOARD, self.firmware_dict, |
| 158 | config_reader.LabConfig(None))) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 159 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 160 | def testGetFirmwareSuccessfully(self): |
| 161 | """Test get firmware from firmware_dict successfully.""" |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 162 | |
| 163 | firmware = self.task._get_firmware_build( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 164 | 'cros', self.BOARD, self.firmware_dict, None) |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 165 | self.assertEqual( |
| 166 | firmware, |
| 167 | '{0}-release/R{1}-{2}'.format(self.BOARD, |
| 168 | self.MILESTONE, |
| 169 | self.PLATFORM)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 170 | firmware = self.task._get_firmware_build( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 171 | 'firmware', self.BOARD, self.firmware_dict, None) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 172 | self.assertEqual( |
| 173 | firmware, |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 174 | 'firmware-{0}-12345.67.A-firmwarebranch/' |
| 175 | 'RFoo-1.0.0-b1234567/{0}'.format(self.BOARD)) |
| 176 | |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 177 | def testGetNonExistentBoard(self): |
| 178 | """Test get firmware for non-existent board from firmware_dict.""" |
| 179 | self.assertIsNone(self.task._get_firmware_build( |
| 180 | 'firmware', 'non-existent', self.firmware_dict, None)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 181 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 182 | def testScheduleCrosSuccessfully(self): |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 183 | """test schedule cros builds successfully.""" |
| 184 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 185 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 186 | self.firmware_dict, |
| 187 | self._fake_configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 188 | self.assertEqual(self._mock_push.call_count, 1) |
| 189 | |
| 190 | def testScheduleCrosNonvalidBoard(self): |
| 191 | """Test schedule no cros builds due to non-allowed board.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 192 | branch_builds = {('%s_2' % self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 193 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 194 | self.firmware_dict, |
| 195 | self._empty_configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 196 | self.assertEqual(self._mock_push.call_count, 0) |
| 197 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 198 | def testScheduleCrosExcludeBoard(self): |
| 199 | """Test schedule no cros builds due to board is excluded.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 200 | branch_builds = {(self.EXCLUDE_BOARD, None, 'release', '56'): '0000.00.00'} |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 201 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 202 | self.firmware_dict, |
| 203 | self._empty_configs) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 204 | self.assertEqual(self._mock_push.call_count, 0) |
| 205 | |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 206 | def testScheduleCrosSuccessfullyWithSpecifiedModel(self): |
| 207 | """Test schedule unibuild with specific model.""" |
| 208 | self.task.board = self.UNIBUILD_BOARD |
| 209 | branch_builds = {(self.UNIBUILD_BOARD, 'robo', 'release', '56'): |
| 210 | '0000.00.00', |
| 211 | (self.UNIBUILD_BOARD, 'lava', 'release', '56'): |
| 212 | '0000.00.00'} |
| 213 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 214 | self.firmware_dict, |
| 215 | self._fake_configs) |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 216 | self.assertEqual(self._mock_push.call_count, 2) |
| 217 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 218 | def testScheduleCrosNonValidSpec(self): |
| 219 | """Test schedule no cros builds due to non-allowed branch milestone.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 220 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 221 | # Only run tasks whose milestone = tot (R40) |
| 222 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot') |
| 223 | self.task._set_spec_compare_info() |
| 224 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 225 | self.firmware_dict, |
| 226 | self._empty_configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 227 | self.assertEqual(self._mock_push.call_count, 0) |
| 228 | |
| 229 | def testScheduleCrosSuccessfullyWithValidFirmware(self): |
| 230 | """Test schedule cros builds successfully with valid firmware.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 231 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 232 | self.task.firmware_ro_build_spec = 'firmware' |
| 233 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 234 | self.firmware_dict, |
| 235 | self._fake_configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 236 | self.assertEqual(self._mock_push.call_count, 1) |
| 237 | |
| 238 | def testScheduleCrosWithNonValidFirmware(self): |
| 239 | """Test schedule no cros builds due to non-existent firmware.""" |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 240 | branch_builds = {('foo-board', None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 241 | self.task.firmware_ro_build_spec = 'firmware' |
| 242 | self.task._schedule_cros_builds(branch_builds, |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 243 | self.firmware_dict, |
| 244 | self._empty_configs) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 245 | self.assertEqual(self._mock_push.call_count, 0) |
| 246 | |
| 247 | def testScheduleLaunchControlWithFullBranches(self): |
| 248 | """Test schedule all launch control builds successfully.""" |
| 249 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 250 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 251 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 252 | self.task.launch_control_branches = [ |
| 253 | t.lstrip() for t in lc_branches.split(',')] |
| 254 | self.task._schedule_launch_control_builds(lc_builds) |
| 255 | self.assertEqual(self._mock_push.call_count, 2) |
| 256 | |
| 257 | def testScheduleLaunchControlWithPartlyBranches(self): |
| 258 | """Test schedule part of launch control builds due to branch check.""" |
| 259 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 260 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 261 | lc_branches = 'git_nyc-mr1-release' |
| 262 | self.task.launch_control_branches = [ |
| 263 | t.lstrip() for t in lc_branches.split(',')] |
| 264 | self.task._schedule_launch_control_builds(lc_builds) |
| 265 | self.assertEqual(self._mock_push.call_count, 1) |
| 266 | |
| 267 | def testScheduleLaunchControlWithNoBranches(self): |
| 268 | """Test schedule none of launch control builds due to branch check.""" |
| 269 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 270 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 271 | self.task.launch_control_branches = [] |
| 272 | self.task._schedule_launch_control_builds(lc_builds) |
| 273 | self.assertEqual(self._mock_push.call_count, 0) |
| 274 | |
| 275 | def testScheduleLaunchControlNonvalidBoard(self): |
| 276 | """Test schedule none of launch control builds due to board check.""" |
| 277 | lc_builds = {'%s_2' % self.BOARD: |
| 278 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 279 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 280 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 281 | self.task.launch_control_branches = [ |
| 282 | t.lstrip() for t in lc_branches.split(',')] |
| 283 | self.task._schedule_launch_control_builds(lc_builds) |
| 284 | self.assertEqual(self._mock_push.call_count, 0) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 285 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 286 | def testScheduleLaunchControlExcludeBoard(self): |
| 287 | """Test schedule none of launch control builds due to board check.""" |
| 288 | lc_builds = {self.EXCLUDE_BOARD: |
| 289 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 290 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 291 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 292 | self.task.launch_control_branches = [ |
| 293 | t.lstrip() for t in lc_branches.split(',')] |
| 294 | self.task._schedule_launch_control_builds(lc_builds) |
| 295 | self.assertEqual(self._mock_push.call_count, 0) |
| 296 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 297 | |
| 298 | class TaskPushTestCase(TaskBaseTestCase): |
| 299 | |
| 300 | def setUp(self): |
| 301 | super(TaskPushTestCase, self).setUp() |
| 302 | mock_push = mock.patch('task_executor.push') |
| 303 | self._mock_push = mock_push.start() |
| 304 | self.addCleanup(mock_push.stop) |
| 305 | |
| 306 | def testScheduleCrOSIsPushSuccessfully(self): |
| 307 | """Test IS_PUSHED is changed if some CrOS suites are scheduled.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 308 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 309 | self.task.os_type = build_lib.OS_TYPE_CROS |
| 310 | self.assertTrue(self.task.schedule( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 311 | [], (branch_builds, []), self.firmware_dict, self._fake_configs)) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 312 | |
| 313 | def testScheduleLaunchControlIsPushSuccessfully(self): |
| 314 | """Test IS_PUSHED is changed if some launch control suites are scheduled.""" |
| 315 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 316 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 317 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 318 | self.task.launch_control_branches = [ |
| 319 | t.lstrip() for t in lc_branches.split(',')] |
| 320 | self.task.os_type = build_lib.OS_TYPES_LAUNCH_CONTROL |
| 321 | self.assertTrue(self.task.schedule( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 322 | lc_builds, ([], []), self.firmware_dict, |
| 323 | self._empty_configs)) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 324 | |
| 325 | def testScheduleCrosIsPushInvalidBoard(self): |
| 326 | """Test schedule no cros builds due to non-allowed board.""" |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 327 | branch_builds = ( |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 328 | {('%s_2' % self.BOARD, None, 'release', '56'): '0000.00.00'}, {}, |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 329 | ) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 330 | self.task.os_type = build_lib.OS_TYPE_CROS |
| 331 | self.assertFalse(self.task.schedule( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 332 | [], branch_builds, self.firmware_dict, self._empty_configs)) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 333 | |
| 334 | def testScheduleLaunchControlIsPushInvalidBoard(self): |
| 335 | """Test schedule none of launch control builds due to board check.""" |
| 336 | lc_builds = {'%s_2' % self.BOARD: |
| 337 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 338 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 339 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 340 | self.task.launch_control_branches = [ |
| 341 | t.lstrip() for t in lc_branches.split(',')] |
| 342 | self.task.os_type = build_lib.OS_TYPES_LAUNCH_CONTROL |
| 343 | self.task._schedule_launch_control_builds(lc_builds) |
| 344 | self.assertFalse(self.task.schedule( |
Xinan Lin | 028f958 | 2019-12-11 10:55:33 -0800 | [diff] [blame] | 345 | lc_builds, ([], []), self.firmware_dict, |
| 346 | self._empty_configs)) |