blob: 03c91c86ee46ca59a29331ff21aa219845bed2f7 [file] [log] [blame]
Alex Klein8212d492018-08-27 07:47:23 -06001# Copyright 2018 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"""Test install_toolchain."""
6
Alex Klein8212d492018-08-27 07:47:23 -06007import os
8
9from chromite.lib import cros_test_lib
10from chromite.lib import osutils
11from chromite.lib import sysroot_lib
Sloan Johnsona85640f2021-10-01 22:32:40 +000012from chromite.lib import unittest_lib
Alex Klein8212d492018-08-27 07:47:23 -060013from chromite.scripts import install_toolchain
14
15
Alex Klein8212d492018-08-27 07:47:23 -060016class ParseArgsTest(cros_test_lib.TempDirTestCase):
17 """Tests for argument parsing and validation rules."""
18
19 # pylint: disable=protected-access
20 def setUp(self):
21 D = cros_test_lib.Directory
22 filesystem = (
23 D('build', (
24 D('board', (
25 D('etc', (
26 'make.conf.board_setup',
27 )),
28 )),
29 )),
30 )
31 cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
32
33 self.chost_value = 'chost'
34 osutils.WriteFile(os.path.join(self.tempdir,
35 'build/board/etc/make.conf.board_setup'),
36 'CHOST="%s"' % self.chost_value)
37
38 self.sysroot_dir = os.path.join(self.tempdir, 'build/board')
Sloan Johnsona85640f2021-10-01 22:32:40 +000039 # make.conf needs to exist to correctly read back config.
40 unittest_lib.create_stub_make_conf(self.sysroot_dir)
Alex Klein8212d492018-08-27 07:47:23 -060041
42 def testInvalidArgs(self):
43 """Test invalid argument parsing."""
44 with self.assertRaises(SystemExit):
45 install_toolchain._ParseArgs([])
46
47 def testSysrootCreate(self):
48 """Test the sysroot is correctly built."""
49 opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir])
50 self.assertIsInstance(opts.sysroot, sysroot_lib.Sysroot)
51 self.assertEqual(self.sysroot_dir, opts.sysroot.path)
52
53 def testToolchain(self):
54 """Test toolchain arg precedence/fallback."""
55 toolchain = 'toolchain'
56 opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir,
57 '--toolchain', toolchain])
58 self.assertEqual(toolchain, opts.toolchain)
59
60 opts = install_toolchain._ParseArgs(['--sysroot', self.sysroot_dir])
61 self.assertEqual(self.chost_value, opts.toolchain)