blob: 16a4b4fe26ef10cdd05610129484a9732762d185 [file] [log] [blame]
Gaurav Shah298aa372014-01-31 09:27:24 -08001# 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 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):
17 """Test for cbuildbot._IsDistributedBuilder."""
18
Mike Frysinger27e21b72018-07-12 14:20:21 -040019 # pylint: disable=protected-access
Gaurav Shah298aa372014-01-31 09:27:24 -080020 def testIsDistributedBuilder(self):
21 """Tests for _IsDistributedBuilder() under various configurations."""
22 parser = cbuildbot._CreateParser()
Don Garrett211df8c2017-09-06 13:33:02 -070023 argv = ['--buildroot', '/foo', 'amd64-generic-paladin']
Mike Frysinger80bba8a2017-08-18 15:28:36 -040024 options = cbuildbot.ParseCommandLine(parser, argv)
Gaurav Shah298aa372014-01-31 09:27:24 -080025 options.buildbot = False
Gaurav Shah298aa372014-01-31 09:27:24 -080026
Mike Frysingerc3e88fa2020-03-26 02:49:02 -040027 build_config = dict(manifest_version=False)
Gaurav Shah298aa372014-01-31 09:27:24 -080028 chrome_rev = None
29
30 def _TestConfig(expected):
Mike Frysinger2d589a12019-08-25 14:15:12 -040031 self.assertEqual(expected,
32 cbuildbot._IsDistributedBuilder(
33 options=options,
34 chrome_rev=chrome_rev,
35 build_config=build_config))
Gaurav Shah298aa372014-01-31 09:27:24 -080036
37 # Default options.
38 _TestConfig(False)
39
Gaurav Shah298aa372014-01-31 09:27:24 -080040 build_config['manifest_version'] = True
41 # Not running in buildbot mode even though manifest_version=True.
42 _TestConfig(False)
43 options.buildbot = True
44 _TestConfig(True)
45
46 for chrome_rev in (constants.CHROME_REV_TOT,
47 constants.CHROME_REV_LOCAL,
48 constants.CHROME_REV_SPEC):
49 _TestConfig(False)
Gregory Meinke5a25ac72019-01-31 13:20:51 -070050
51
52class PostsubmitBuilderTest(cros_test_lib.TestCase):
53 """Test for special parameters for ChromeOS Findit Integration."""
54
55 def testBuildPackages(self):
56 parser = cbuildbot.CreateParser()
57 argv = ['--buildroot', '/foo', '--buildbot',
Gregory Meinkead6d5672019-02-19 08:41:12 -070058 '--cbb_snapshot_revision', 'hash1234',
Gregory Meinke5a25ac72019-01-31 13:20:51 -070059 '--cbb_build_packages', 'pkgA pkgB', 'caroline-postsubmit']
60 options = cbuildbot.ParseCommandLine(parser, argv)
61 expected = ['pkgA', 'pkgB']
Mike Frysinger2d589a12019-08-25 14:15:12 -040062 self.assertEqual(expected, options.cbb_build_packages)
63 self.assertEqual('hash1234', options.cbb_snapshot_revision)
Jared Loucksa9e94bf2021-06-28 10:03:31 -060064
65
66class ParseHWTestDUTDimsTest(cros_test_lib.TestCase):
67 """Test for ParseHWTestDUTDims function."""
68
69 def testParseInvalidDims(self):
70 invalid_dims = ['label-board:foo', 'label-model:bar', 'label-pol:baz',
71 'extra:haha']
72 with self.assertRaises(cros_build_lib.DieSystemExit):
73 cbuildbot.ParseHWTestDUTDims(invalid_dims)
74
75 def testParseValidDims(self):
76 dimsObject = cbuildbot.ParseHWTestDUTDims([
77 'label-board:foo', 'label-model:bar', 'label-pool:baz', 'a:b', 'c:d'])
78 self.assertEqual(dimsObject.board, 'foo')
79 self.assertEqual(dimsObject.model, 'bar')
80 self.assertEqual(dimsObject.pool, 'baz')
81 self.assertEqual(dimsObject.extra_dims, ['a:b', 'c:d'])
82
83 def testParseNoDims(self):
84 self.assertIsNone(cbuildbot.ParseHWTestDUTDims([]))
85 self.assertIsNone(cbuildbot.ParseHWTestDUTDims(None))