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 |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 12 | |
| 13 | from chromite.lib import cros_test_lib |
| 14 | from chromite.scripts import cros_install_debug_syms |
| 15 | |
| 16 | |
| 17 | SimpleIndex = namedtuple('SimpleIndex', 'header packages') |
| 18 | |
| 19 | |
| 20 | class InstallDebugSymsTest(cros_test_lib.MockTestCase): |
| 21 | """Test the parsing of package index""" |
| 22 | |
| 23 | def setUp(self): |
| 24 | self.local_binhosts = ['/build/something/packages/', |
| 25 | 'file:///build/somethingelse/packages', |
| 26 | 'file://localhost/build/another/packages'] |
| 27 | |
| 28 | self.remote_binhosts = ['http://domain.com/binhost', |
| 29 | 'gs://chromeos-stuff/binhost'] |
| 30 | |
| 31 | def testGetLocalPackageIndex(self): |
| 32 | """Check that local binhosts are fetched correctly.""" |
Mike Frysinger | 80de501 | 2019-08-01 14:10:53 -0400 | [diff] [blame] | 33 | self.PatchObject(cros_install_debug_syms.binpkg, 'GrabLocalPackageIndex', |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 34 | return_value=SimpleIndex({}, {})) |
| 35 | self.PatchObject(cros_install_debug_syms.os.path, 'isdir', |
| 36 | return_value=True) |
| 37 | for binhost in self.local_binhosts: |
| 38 | cros_install_debug_syms.GetPackageIndex(binhost) |
| 39 | |
| 40 | def testGetRemotePackageIndex(self): |
| 41 | """Check that remote binhosts are fetched correctly.""" |
Mike Frysinger | 80de501 | 2019-08-01 14:10:53 -0400 | [diff] [blame] | 42 | self.PatchObject(cros_install_debug_syms.binpkg, 'GrabRemotePackageIndex', |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 43 | return_value=SimpleIndex({}, {})) |
| 44 | for binhost in self.remote_binhosts: |
| 45 | cros_install_debug_syms.GetPackageIndex(binhost) |
| 46 | |
| 47 | def testListRemoteBinhost(self): |
| 48 | """Check that urls are generated correctly for remote binhosts.""" |
| 49 | chaps_cpv = 'chromeos-base/chaps-0-r2' |
| 50 | metrics_cpv = 'chromeos-base/metrics-0-r4' |
| 51 | |
| 52 | index = SimpleIndex({}, [{'CPV': 'chromeos-base/shill-0-r1'}, |
| 53 | {'CPV': chaps_cpv, |
| 54 | 'DEBUG_SYMBOLS': 'yes'}, |
| 55 | {'CPV': metrics_cpv, |
| 56 | 'DEBUG_SYMBOLS': 'yes', |
| 57 | 'PATH': 'path/to/binpkg.tbz2'}]) |
| 58 | self.PatchObject(cros_install_debug_syms, 'GetPackageIndex', |
| 59 | return_value=index) |
| 60 | |
| 61 | for binhost in self.remote_binhosts: |
| 62 | expected = {chaps_cpv: os.path.join(binhost, chaps_cpv + '.debug.tbz2'), |
| 63 | metrics_cpv: os.path.join(binhost, |
| 64 | 'path/to/binpkg.debug.tbz2')} |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame^] | 65 | self.assertEqual(cros_install_debug_syms.ListBinhost(binhost), expected) |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 66 | |
| 67 | def testListRemoteBinhostWithURI(self): |
| 68 | """Check that urls are generated correctly when URI is defined.""" |
| 69 | index = SimpleIndex({'URI': 'gs://chromeos-prebuilts'}, |
| 70 | [{'CPV': 'chromeos-base/shill-0-r1', |
| 71 | 'DEBUG_SYMBOLS': 'yes', |
| 72 | 'PATH': 'amd64-generic/paladin1234/shill-0-r1.tbz2'}]) |
| 73 | self.PatchObject(cros_install_debug_syms, 'GetPackageIndex', |
| 74 | return_value=index) |
| 75 | |
| 76 | binhost = 'gs://chromeos-prebuilts/gizmo-paladin/' |
| 77 | debug_symbols_url = ('gs://chromeos-prebuilts/amd64-generic' |
| 78 | '/paladin1234/shill-0-r1.debug.tbz2') |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame^] | 79 | self.assertEqual(cros_install_debug_syms.ListBinhost(binhost), |
| 80 | {'chromeos-base/shill-0-r1': debug_symbols_url}) |