blob: bb9d44e8a340e76bd901b5412981429f16f3cd3e [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -08002# 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
8from __future__ import print_function
9
10from collections import namedtuple
11import os
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -080012
13from chromite.lib import cros_test_lib
14from chromite.scripts import cros_install_debug_syms
15
16
17SimpleIndex = namedtuple('SimpleIndex', 'header packages')
18
19
20class 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 Frysinger80de5012019-08-01 14:10:53 -040033 self.PatchObject(cros_install_debug_syms.binpkg, 'GrabLocalPackageIndex',
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -080034 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 Frysinger80de5012019-08-01 14:10:53 -040042 self.PatchObject(cros_install_debug_syms.binpkg, 'GrabRemotePackageIndex',
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -080043 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 Frysinger2d589a12019-08-25 14:15:12 -040065 self.assertEqual(cros_install_debug_syms.ListBinhost(binhost), expected)
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -080066
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 Frysinger2d589a12019-08-25 14:15:12 -040079 self.assertEqual(cros_install_debug_syms.ListBinhost(binhost),
80 {'chromeos-base/shill-0-r1': debug_symbols_url})