Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 5 | """Module for task config reader unittests.""" |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 6 | # pylint: disable=g-missing-super-call |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 7 | |
| 8 | import unittest |
| 9 | |
| 10 | import config_reader |
Xixuan Wu | 244e0ec | 2018-05-23 14:49:55 -0700 | [diff] [blame] | 11 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 12 | |
| 13 | class LabReaderTestCase(unittest.TestCase): |
| 14 | |
| 15 | def setUp(self): |
| 16 | self.config = config_reader.ConfigReader(None) |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 17 | self.config.add_section(config_reader.ANDROID_SETTINGS) |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 18 | self.config.add_section(config_reader.CROS_SETTINGS) |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 19 | |
| 20 | def testGetAndroidBoardList(self): |
| 21 | """Ensure android board list can be correctly fetched.""" |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 22 | self.config.set(config_reader.ANDROID_SETTINGS, 'board_list', |
| 23 | '\nabox_edge,\nandroid-angler-1,\nangler-6') |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 24 | lab_config = config_reader.LabConfig(self.config) |
| 25 | self.assertEqual(lab_config.get_android_board_list(), |
Dhanya Ganesh | c45d319 | 2020-08-06 20:52:12 +0000 | [diff] [blame] | 26 | set([])) |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 27 | |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 28 | def testGetCrOSBoardList(self): |
| 29 | """Ensure android board list can be correctly fetched.""" |
| 30 | self.config.set(config_reader.CROS_SETTINGS, 'board_list', |
Dhanya Ganesh | c45d319 | 2020-08-06 20:52:12 +0000 | [diff] [blame] | 31 | '\nlink') |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 32 | lab_config = config_reader.LabConfig(self.config) |
| 33 | self.assertEqual(lab_config.get_cros_board_list(), |
| 34 | set(['link'])) |
| 35 | |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 36 | def testGetCrOSModelMap(self): |
| 37 | """Ensure cros_model_map can be correctly fetched.""" |
| 38 | self.config.set(config_reader.CROS_SETTINGS, 'model_list', |
| 39 | '\ncoral_astronaut,\ncoral_robo360') |
| 40 | lab_config = config_reader.LabConfig(self.config) |
| 41 | result = lab_config.get_cros_model_map() |
| 42 | self.assertEqual(len(result), 1) |
| 43 | self.assertEqual(result['coral'], ['astronaut', 'robo360']) |
| 44 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 45 | def testGetEmptyCrOSModelMap(self): |
| 46 | """Ensure cros_model_map can be correctly fetched.""" |
| 47 | lab_config = config_reader.LabConfig(self.config) |
| 48 | self.assertEqual(lab_config.get_cros_model_map(), {}) |
| 49 | |
Garry Wang | 6ca42dd | 2022-02-28 21:54:19 -0800 | [diff] [blame] | 50 | def testGetAndroidModelMap(self): |
| 51 | """Ensure android_model_map can be correctly fetched.""" |
| 52 | self.config.set(config_reader.ANDROID_SETTINGS, 'model_list', |
| 53 | '\npixel3_pixel3xl,\npixel3_pixel3a,\npixel4_pixel4a') |
| 54 | lab_config = config_reader.LabConfig(self.config) |
| 55 | expected = {'pixel3': ['pixel3xl', 'pixel3a'], |
| 56 | 'pixel4': ['pixel4a']} |
| 57 | actual = lab_config.get_android_model_map() |
| 58 | self.assertEqual(len(actual), 2) |
| 59 | self.assertEqual(actual, expected) |
| 60 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 61 | |
Jack Neus | 8f0edb4 | 2022-03-17 20:21:39 +0000 | [diff] [blame] | 62 | class RubikReaderTestCase(unittest.TestCase): |
| 63 | |
| 64 | def setUp(self): |
| 65 | self.config = config_reader.ConfigReader(None) |
| 66 | self.config.add_section(config_reader.RUBIK_SETTINGS) |
| 67 | |
Jack Neus | 2cbdc43 | 2022-06-24 20:21:30 +0000 | [diff] [blame] | 68 | def testGetStableRubikMilestones(self): |
| 69 | """Ensure Rubik stable milestones can be correctly fetched.""" |
| 70 | self.config.set(config_reader.RUBIK_SETTINGS, 'stable_rubik_milestones', |
| 71 | '\natlas-kernelnext=105,\neve=103') |
Jack Neus | 8f0edb4 | 2022-03-17 20:21:39 +0000 | [diff] [blame] | 72 | rubik_config = config_reader.RubikConfig(self.config) |
Jack Neus | 2cbdc43 | 2022-06-24 20:21:30 +0000 | [diff] [blame] | 73 | self.assertEqual(rubik_config.get_stable_rubik_milestones(), |
| 74 | {'atlas-kernelnext': 105, 'eve': 103}) |
Jack Neus | 8f0edb4 | 2022-03-17 20:21:39 +0000 | [diff] [blame] | 75 | |
| 76 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 77 | if __name__ == '__main__': |
| 78 | unittest.main() |