Alex Klein | 8212d49 | 2018-08-27 07:47:23 -0600 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Test install_toolchain.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import cros_test_lib |
| 13 | from chromite.lib import osutils |
| 14 | from chromite.lib import sysroot_lib |
| 15 | from chromite.scripts import install_toolchain |
| 16 | |
| 17 | |
| 18 | class ParseArgsTest(cros_test_lib.TempDirTestCase): |
| 19 | """Tests for argument parsing and validation rules.""" |
| 20 | |
| 21 | # pylint: disable=protected-access |
| 22 | def setUp(self): |
| 23 | D = cros_test_lib.Directory |
| 24 | filesystem = ( |
| 25 | D('build', ( |
| 26 | D('board', ( |
| 27 | D('etc', ( |
| 28 | 'make.conf.board_setup', |
| 29 | )), |
| 30 | )), |
| 31 | )), |
| 32 | ) |
| 33 | cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem) |
| 34 | |
| 35 | self.chost_value = 'chost' |
| 36 | osutils.WriteFile(os.path.join(self.tempdir, |
| 37 | 'build/board/etc/make.conf.board_setup'), |
| 38 | 'CHOST="%s"' % self.chost_value) |
| 39 | |
| 40 | self.sysroot_dir = os.path.join(self.tempdir, 'build/board') |
| 41 | |
| 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) |