blob: 2760165e62f7ddc279a895ccf2577cbab069421c [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2014 The ChromiumOS Authors
Gaurav Shah298aa372014-01-31 09:27:24 -08002# 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 Keshetb7519e12016-10-04 00:50:00 -07007from chromite.lib import constants
Jared Loucksa9e94bf2021-06-28 10:03:31 -06008from chromite.lib import cros_build_lib
Gaurav Shah298aa372014-01-31 09:27:24 -08009from chromite.lib import cros_test_lib
10from chromite.scripts import cbuildbot
11
12
Don Garrettb85658c2015-06-30 19:07:22 -070013# pylint: disable=protected-access
14
15
Gaurav Shah298aa372014-01-31 09:27:24 -080016class IsDistributedBuilderTest(cros_test_lib.TestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060017 """Test for cbuildbot._IsDistributedBuilder."""
Gaurav Shah298aa372014-01-31 09:27:24 -080018
Alex Klein1699fab2022-09-08 08:46:06 -060019 # 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 Shah298aa372014-01-31 09:27:24 -080026
Alex Klein1699fab2022-09-08 08:46:06 -060027 build_config = dict(manifest_version=False)
28 chrome_rev = None
Gaurav Shah298aa372014-01-31 09:27:24 -080029
Alex Klein1699fab2022-09-08 08:46:06 -060030 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 Shah298aa372014-01-31 09:27:24 -080039
Alex Klein1699fab2022-09-08 08:46:06 -060040 # Default options.
41 _TestConfig(False)
Gaurav Shah298aa372014-01-31 09:27:24 -080042
Alex Klein1699fab2022-09-08 08:46:06 -060043 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 Shah298aa372014-01-31 09:27:24 -080048
Alex Klein1699fab2022-09-08 08:46:06 -060049 for chrome_rev in (
50 constants.CHROME_REV_TOT,
51 constants.CHROME_REV_LOCAL,
52 constants.CHROME_REV_SPEC,
53 ):
54 _TestConfig(False)
Gregory Meinke5a25ac72019-01-31 13:20:51 -070055
56
57class PostsubmitBuilderTest(cros_test_lib.TestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060058 """Test for special parameters for ChromeOS Findit Integration."""
Gregory Meinke5a25ac72019-01-31 13:20:51 -070059
Alex Klein1699fab2022-09-08 08:46:06 -060060 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 Loucksa9e94bf2021-06-28 10:03:31 -060076
77
78class ParseHWTestDUTDimsTest(cros_test_lib.TestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060079 """Test for ParseHWTestDUTDims function."""
Jared Loucksa9e94bf2021-06-28 10:03:31 -060080
Alex Klein1699fab2022-09-08 08:46:06 -060081 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 Loucksa9e94bf2021-06-28 10:03:31 -060090
Alex Klein1699fab2022-09-08 08:46:06 -060091 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 Loucksa9e94bf2021-06-28 10:03:31 -0600105
Alex Klein1699fab2022-09-08 08:46:06 -0600106 def testParseNoDims(self):
107 self.assertIsNone(cbuildbot.ParseHWTestDUTDims([]))
108 self.assertIsNone(cbuildbot.ParseHWTestDUTDims(None))