Kazuhiro Inaba | f020822 | 2020-03-05 10:33:07 +0900 | [diff] [blame] | 1 | # Copyright 2020 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 build_lib unittests.""" |
| 6 | |
| 7 | import unittest |
| 8 | |
| 9 | import build_lib |
| 10 | |
| 11 | |
Jack Neus | cb14a3b | 2022-04-01 16:39:38 +0000 | [diff] [blame] | 12 | class FakeBuildClient(object): |
| 13 | """Mock rest_client.BuildBucketBigqueryClient.""" |
| 14 | |
| 15 | def __init__(self): |
| 16 | self.firmware_builds_called = 0 |
| 17 | |
| 18 | def get_passed_builds(self, earliest, latest, event_type): |
| 19 | """Mock get_passed_builds.""" |
| 20 | del earliest # unused |
| 21 | del latest # unused |
| 22 | del event_type #unused |
| 23 | return [ |
| 24 | build_lib.BuildInfo( |
| 25 | 'link', None, '62', '9868.0.0', 'link-release'), |
| 26 | build_lib.BuildInfo( |
| 27 | 'zako', None, '62', '9868.0.0', 'zako-release'), |
| 28 | build_lib.BuildInfo('samus-kernelnext', None, '62', |
| 29 | '9868.0.0', 'samus-kernelnext-release'), |
| 30 | build_lib.BuildInfo( |
| 31 | 'reef', None, '62', '1234.0.0', 'reef-release'), |
| 32 | build_lib.BuildInfo( |
| 33 | 'coral', 'santa', '62', '9868.0.0', 'coral-release'), |
| 34 | build_lib.BuildInfo( |
| 35 | 'coral', 'astronaut', '62', '9868.0.0', 'coral-release'), |
| 36 | build_lib.BuildInfo( |
| 37 | 'coral', 'lava', '62', '9868.0.0', 'coral-release'), |
| 38 | build_lib.BuildInfo( |
| 39 | 'atlas-kernelnext', None, '62', '9868.0.0', 'atlas-kernelnext-release'), |
| 40 | ] |
| 41 | |
| 42 | def get_passed_rubik_builds(self, earliest, latest, event_type): |
| 43 | """Mock get_passed_rubik_builds.""" |
| 44 | del earliest # unused |
| 45 | del latest # unused |
| 46 | del event_type #unused |
| 47 | return [ |
| 48 | build_lib.BuildInfo( |
| 49 | 'atlas-kernelnext', None, '62', '9869.0.0', 'atlas-kernelnext-release'), |
| 50 | build_lib.BuildInfo( |
| 51 | 'coral', 'lava', '62', '9869.0.0', 'coral-release'), |
| 52 | ] |
| 53 | |
| 54 | def get_relaxed_passed_builds(self, earliest, latest, event_type): |
| 55 | """Mock get_relaxed_pased_builds.""" |
| 56 | del earliest # unused |
| 57 | del latest # unused |
| 58 | del event_type #unused |
| 59 | return [] |
| 60 | |
| 61 | |
Kazuhiro Inaba | f020822 | 2020-03-05 10:33:07 +0900 | [diff] [blame] | 62 | class BuildLibTestCase(unittest.TestCase): |
| 63 | |
| 64 | def testReshapeBoard(self): |
| 65 | self.assertEqual(build_lib.reshape_board('samus-kernelnext'), 'samus') |
| 66 | self.assertEqual(build_lib.reshape_board('eve-arcvm'), 'eve') |
| 67 | self.assertEqual(build_lib.reshape_board('kukui-arc-r'), 'kukui') |
Federico 'Morg' Pareschi | 4b39e69 | 2020-06-01 12:04:05 +0900 | [diff] [blame] | 68 | self.assertEqual(build_lib.reshape_board('hatch-arc-r-userdebug'), 'hatch') |
Jiyoun Ha | ff42b7d | 2021-04-22 13:35:33 +0900 | [diff] [blame] | 69 | self.assertEqual(build_lib.reshape_board('hatch-arc-s'), 'hatch'), |
Kazuhiro Inaba | 840dac7 | 2021-02-01 16:47:05 +0900 | [diff] [blame] | 70 | self.assertEqual(build_lib.reshape_board('kevin-userdebug'), 'kevin') |
Kazuhiro Inaba | f020822 | 2020-03-05 10:33:07 +0900 | [diff] [blame] | 71 | self.assertEqual(build_lib.reshape_board('octopus'), 'octopus') |
Navil Perez | c7a2917 | 2021-03-09 22:06:25 +0000 | [diff] [blame] | 72 | self.assertEqual(build_lib.reshape_board('hana-arc64'), 'hana') |
Kazuhiro Inaba | f020822 | 2020-03-05 10:33:07 +0900 | [diff] [blame] | 73 | |
Jack Neus | cb14a3b | 2022-04-01 16:39:38 +0000 | [diff] [blame] | 74 | def testGetCrosBuilds(self): |
| 75 | mock_build_client = FakeBuildClient() |
| 76 | cros_board_list = ['coral', 'atlas-kernelnext'] |
Jack Neus | 2cbdc43 | 2022-06-24 20:21:30 +0000 | [diff] [blame] | 77 | stable_rubik_milestones = {'atlas-kernelnext': 62} |
Jack Neus | cb14a3b | 2022-04-01 16:39:38 +0000 | [diff] [blame] | 78 | build_dict, relaxed_build_dict = build_lib.get_cros_builds( |
| 79 | mock_build_client, cros_board_list, None, None, None, |
Jack Neus | 2cbdc43 | 2022-06-24 20:21:30 +0000 | [diff] [blame] | 80 | stable_rubik_milestones=stable_rubik_milestones) |
Jack Neus | cb14a3b | 2022-04-01 16:39:38 +0000 | [diff] [blame] | 81 | |
| 82 | expected_build_dict = { |
| 83 | ('coral', 'santa', 'release', '62'): '9868.0.0', |
| 84 | ('coral', 'astronaut', 'release', '62'): '9868.0.0', |
| 85 | ('coral', 'lava', 'release', '62'): '9868.0.0', |
| 86 | ('atlas-kernelnext', None, 'release', '62'): '9869.0.0' |
| 87 | } |
| 88 | self.assertEqual(expected_build_dict, build_dict) |
| 89 | self.assertEqual(expected_build_dict, relaxed_build_dict) |
| 90 | |
| 91 | |
Kazuhiro Inaba | f020822 | 2020-03-05 10:33:07 +0900 | [diff] [blame] | 92 | if __name__ == '__main__': |
| 93 | unittest.main() |