Mike Frysinger | e58c0e2 | 2017-10-04 15:43:30 -0400 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 2 | # Copyright 2014 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 | """Unittests for cros_install_debug_syms.py""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | from collections import namedtuple |
| 11 | import os |
Mike Frysinger | 6a2b0f2 | 2020-02-20 13:34:07 -0500 | [diff] [blame] | 12 | import sys |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 13 | |
| 14 | from chromite.lib import cros_test_lib |
| 15 | from chromite.scripts import cros_install_debug_syms |
Mike Frysinger | 8e99b37 | 2019-12-05 19:05:02 -0500 | [diff] [blame] | 16 | from chromite.utils import outcap |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 17 | |
Greg Edelston | a4c9b3b | 2020-01-07 17:51:13 -0700 | [diff] [blame^] | 18 | pytestmark = cros_test_lib.pytestmark_inside_only |
| 19 | |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 20 | |
Mike Frysinger | 6a2b0f2 | 2020-02-20 13:34:07 -0500 | [diff] [blame] | 21 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 22 | |
| 23 | |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 24 | SimpleIndex = namedtuple('SimpleIndex', 'header packages') |
| 25 | |
| 26 | |
| 27 | class InstallDebugSymsTest(cros_test_lib.MockTestCase): |
| 28 | """Test the parsing of package index""" |
| 29 | |
| 30 | def setUp(self): |
| 31 | self.local_binhosts = ['/build/something/packages/', |
| 32 | 'file:///build/somethingelse/packages', |
| 33 | 'file://localhost/build/another/packages'] |
| 34 | |
| 35 | self.remote_binhosts = ['http://domain.com/binhost', |
| 36 | 'gs://chromeos-stuff/binhost'] |
| 37 | |
| 38 | def testGetLocalPackageIndex(self): |
| 39 | """Check that local binhosts are fetched correctly.""" |
Mike Frysinger | 80de501 | 2019-08-01 14:10:53 -0400 | [diff] [blame] | 40 | self.PatchObject(cros_install_debug_syms.binpkg, 'GrabLocalPackageIndex', |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 41 | return_value=SimpleIndex({}, {})) |
| 42 | self.PatchObject(cros_install_debug_syms.os.path, 'isdir', |
| 43 | return_value=True) |
| 44 | for binhost in self.local_binhosts: |
| 45 | cros_install_debug_syms.GetPackageIndex(binhost) |
| 46 | |
| 47 | def testGetRemotePackageIndex(self): |
| 48 | """Check that remote binhosts are fetched correctly.""" |
Mike Frysinger | 80de501 | 2019-08-01 14:10:53 -0400 | [diff] [blame] | 49 | self.PatchObject(cros_install_debug_syms.binpkg, 'GrabRemotePackageIndex', |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 50 | return_value=SimpleIndex({}, {})) |
| 51 | for binhost in self.remote_binhosts: |
| 52 | cros_install_debug_syms.GetPackageIndex(binhost) |
| 53 | |
| 54 | def testListRemoteBinhost(self): |
| 55 | """Check that urls are generated correctly for remote binhosts.""" |
| 56 | chaps_cpv = 'chromeos-base/chaps-0-r2' |
| 57 | metrics_cpv = 'chromeos-base/metrics-0-r4' |
| 58 | |
| 59 | index = SimpleIndex({}, [{'CPV': 'chromeos-base/shill-0-r1'}, |
| 60 | {'CPV': chaps_cpv, |
| 61 | 'DEBUG_SYMBOLS': 'yes'}, |
| 62 | {'CPV': metrics_cpv, |
| 63 | 'DEBUG_SYMBOLS': 'yes', |
| 64 | 'PATH': 'path/to/binpkg.tbz2'}]) |
| 65 | self.PatchObject(cros_install_debug_syms, 'GetPackageIndex', |
| 66 | return_value=index) |
| 67 | |
| 68 | for binhost in self.remote_binhosts: |
| 69 | expected = {chaps_cpv: os.path.join(binhost, chaps_cpv + '.debug.tbz2'), |
| 70 | metrics_cpv: os.path.join(binhost, |
| 71 | 'path/to/binpkg.debug.tbz2')} |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 72 | self.assertEqual(cros_install_debug_syms.ListBinhost(binhost), expected) |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 73 | |
| 74 | def testListRemoteBinhostWithURI(self): |
| 75 | """Check that urls are generated correctly when URI is defined.""" |
| 76 | index = SimpleIndex({'URI': 'gs://chromeos-prebuilts'}, |
| 77 | [{'CPV': 'chromeos-base/shill-0-r1', |
| 78 | 'DEBUG_SYMBOLS': 'yes', |
| 79 | 'PATH': 'amd64-generic/paladin1234/shill-0-r1.tbz2'}]) |
| 80 | self.PatchObject(cros_install_debug_syms, 'GetPackageIndex', |
| 81 | return_value=index) |
| 82 | |
| 83 | binhost = 'gs://chromeos-prebuilts/gizmo-paladin/' |
| 84 | debug_symbols_url = ('gs://chromeos-prebuilts/amd64-generic' |
| 85 | '/paladin1234/shill-0-r1.debug.tbz2') |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 86 | self.assertEqual(cros_install_debug_syms.ListBinhost(binhost), |
| 87 | {'chromeos-base/shill-0-r1': debug_symbols_url}) |
Mike Frysinger | 8e99b37 | 2019-12-05 19:05:02 -0500 | [diff] [blame] | 88 | |
| 89 | |
| 90 | class InstallArgsTest(cros_test_lib.MockTestCase): |
| 91 | """Test InstallArgs utility funcs.""" |
| 92 | |
| 93 | def testListInstallArgs(self): |
| 94 | """Check ListInstallArgs behavior.""" |
| 95 | parser = cros_install_debug_syms.GetParser() |
| 96 | opts = parser.parse_args(['--board', 'betty', 'sys-fs/fuse']) |
| 97 | self.PatchObject(cros_install_debug_syms, 'GetInstallArgs', return_value=[ |
| 98 | ('a/b-1', 'gs://bucket/b-1.tbz2'), |
| 99 | ('c/d-1', 'gs://bucket/d-1.tbz2'), |
| 100 | ]) |
| 101 | with outcap.OutputCapturer() as cap: |
| 102 | cros_install_debug_syms.ListInstallArgs(opts, '/foo') |
| 103 | self.assertEqual('a/b-1 gs://bucket/b-1.tbz2\nc/d-1 gs://bucket/d-1.tbz2\n', |
| 104 | cap.GetStdout()) |
| 105 | |
| 106 | def testGetInstallArgsList(self): |
| 107 | """Check GetInstallArgsList behavior.""" |
| 108 | stdout = ('sys-apps/which-2.21 gs://bucket/board/which-2.21.debug.tbz2\n' |
| 109 | 'dev-libs/foo-1-r1 gs://bucket/board/foo-1-r1.debug.tbz2\n') |
| 110 | rc = self.StartPatcher(cros_test_lib.RunCommandMock()) |
| 111 | rc.AddCmdResult(cmd=['foo', '--list'], stdout=stdout) |
| 112 | self.assertEqual( |
| 113 | [['sys-apps/which-2.21', 'gs://bucket/board/which-2.21.debug.tbz2'], |
| 114 | ['dev-libs/foo-1-r1', 'gs://bucket/board/foo-1-r1.debug.tbz2']], |
| 115 | cros_install_debug_syms.GetInstallArgsList(['foo'])) |