Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 1 | # Copyright (c) 2014 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 | """Unit tests for the cbuildbot program""" |
| 6 | |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 7 | from chromite.lib import constants |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 8 | from chromite.lib import cros_build_lib |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 9 | from chromite.lib import cros_test_lib |
| 10 | from chromite.scripts import cbuildbot |
| 11 | |
| 12 | |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 13 | # pylint: disable=protected-access |
| 14 | |
| 15 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 16 | class IsDistributedBuilderTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 17 | """Test for cbuildbot._IsDistributedBuilder.""" |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 18 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 19 | # pylint: disable=protected-access |
| 20 | def testIsDistributedBuilder(self): |
| 21 | """Tests for _IsDistributedBuilder() under various configurations.""" |
| 22 | parser = cbuildbot._CreateParser() |
| 23 | argv = ["--buildroot", "/foo", "amd64-generic-paladin"] |
| 24 | options = cbuildbot.ParseCommandLine(parser, argv) |
| 25 | options.buildbot = False |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 26 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 27 | build_config = dict(manifest_version=False) |
| 28 | chrome_rev = None |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 29 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 30 | def _TestConfig(expected): |
| 31 | self.assertEqual( |
| 32 | expected, |
| 33 | cbuildbot._IsDistributedBuilder( |
| 34 | options=options, |
| 35 | chrome_rev=chrome_rev, |
| 36 | build_config=build_config, |
| 37 | ), |
| 38 | ) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 39 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 40 | # Default options. |
| 41 | _TestConfig(False) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 42 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 43 | build_config["manifest_version"] = True |
| 44 | # Not running in buildbot mode even though manifest_version=True. |
| 45 | _TestConfig(False) |
| 46 | options.buildbot = True |
| 47 | _TestConfig(True) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 48 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 49 | for chrome_rev in ( |
| 50 | constants.CHROME_REV_TOT, |
| 51 | constants.CHROME_REV_LOCAL, |
| 52 | constants.CHROME_REV_SPEC, |
| 53 | ): |
| 54 | _TestConfig(False) |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 55 | |
| 56 | |
| 57 | class PostsubmitBuilderTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 58 | """Test for special parameters for ChromeOS Findit Integration.""" |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 59 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 60 | def testBuildPackages(self): |
| 61 | parser = cbuildbot.CreateParser() |
| 62 | argv = [ |
| 63 | "--buildroot", |
| 64 | "/foo", |
| 65 | "--buildbot", |
| 66 | "--cbb_snapshot_revision", |
| 67 | "hash1234", |
| 68 | "--cbb_build_packages", |
| 69 | "pkgA pkgB", |
| 70 | "caroline-postsubmit", |
| 71 | ] |
| 72 | options = cbuildbot.ParseCommandLine(parser, argv) |
| 73 | expected = ["pkgA", "pkgB"] |
| 74 | self.assertEqual(expected, options.cbb_build_packages) |
| 75 | self.assertEqual("hash1234", options.cbb_snapshot_revision) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 76 | |
| 77 | |
| 78 | class ParseHWTestDUTDimsTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 79 | """Test for ParseHWTestDUTDims function.""" |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 80 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 81 | def testParseInvalidDims(self): |
| 82 | invalid_dims = [ |
| 83 | "label-board:foo", |
| 84 | "label-model:bar", |
| 85 | "label-pol:baz", |
| 86 | "extra:haha", |
| 87 | ] |
| 88 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 89 | cbuildbot.ParseHWTestDUTDims(invalid_dims) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 90 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 91 | def testParseValidDims(self): |
| 92 | dimsObject = cbuildbot.ParseHWTestDUTDims( |
| 93 | [ |
| 94 | "label-board:foo", |
| 95 | "label-model:bar", |
| 96 | "label-pool:baz", |
| 97 | "a:b", |
| 98 | "c:d", |
| 99 | ] |
| 100 | ) |
| 101 | self.assertEqual(dimsObject.board, "foo") |
| 102 | self.assertEqual(dimsObject.model, "bar") |
| 103 | self.assertEqual(dimsObject.pool, "baz") |
| 104 | self.assertEqual(dimsObject.extra_dims, ["a:b", "c:d"]) |
Jared Loucks | a9e94bf | 2021-06-28 10:03:31 -0600 | [diff] [blame] | 105 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 106 | def testParseNoDims(self): |
| 107 | self.assertIsNone(cbuildbot.ParseHWTestDUTDims([])) |
| 108 | self.assertIsNone(cbuildbot.ParseHWTestDUTDims(None)) |