blob: b1fa3f876b1e87989006c598656a807c7a66ba8d [file] [log] [blame]
Bertrand SIMONNET1e146e52014-12-11 14:11:56 -08001#!/usr/bin/python
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
8from __future__ import print_function
9
10from collections import namedtuple
11import os
12import sys
13
14sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
15 '..', '..'))
16
17from chromite.lib import cros_test_lib
18from chromite.scripts import cros_install_debug_syms
19
20
21SimpleIndex = namedtuple('SimpleIndex', 'header packages')
22
23
24class InstallDebugSymsTest(cros_test_lib.MockTestCase):
25 """Test the parsing of package index"""
26
27 def setUp(self):
28 self.local_binhosts = ['/build/something/packages/',
29 'file:///build/somethingelse/packages',
30 'file://localhost/build/another/packages']
31
32 self.remote_binhosts = ['http://domain.com/binhost',
33 'gs://chromeos-stuff/binhost']
34
35 def testGetLocalPackageIndex(self):
36 """Check that local binhosts are fetched correctly."""
37 self.PatchObject(cros_install_debug_syms.binpkg, "GrabLocalPackageIndex",
38 return_value=SimpleIndex({}, {}))
39 self.PatchObject(cros_install_debug_syms.os.path, 'isdir',
40 return_value=True)
41 for binhost in self.local_binhosts:
42 cros_install_debug_syms.GetPackageIndex(binhost)
43
44 def testGetRemotePackageIndex(self):
45 """Check that remote binhosts are fetched correctly."""
46 self.PatchObject(cros_install_debug_syms.binpkg, "GrabRemotePackageIndex",
47 return_value=SimpleIndex({}, {}))
48 for binhost in self.remote_binhosts:
49 cros_install_debug_syms.GetPackageIndex(binhost)
50
51 def testListRemoteBinhost(self):
52 """Check that urls are generated correctly for remote binhosts."""
53 chaps_cpv = 'chromeos-base/chaps-0-r2'
54 metrics_cpv = 'chromeos-base/metrics-0-r4'
55
56 index = SimpleIndex({}, [{'CPV': 'chromeos-base/shill-0-r1'},
57 {'CPV': chaps_cpv,
58 'DEBUG_SYMBOLS': 'yes'},
59 {'CPV': metrics_cpv,
60 'DEBUG_SYMBOLS': 'yes',
61 'PATH': 'path/to/binpkg.tbz2'}])
62 self.PatchObject(cros_install_debug_syms, 'GetPackageIndex',
63 return_value=index)
64
65 for binhost in self.remote_binhosts:
66 expected = {chaps_cpv: os.path.join(binhost, chaps_cpv + '.debug.tbz2'),
67 metrics_cpv: os.path.join(binhost,
68 'path/to/binpkg.debug.tbz2')}
69 self.assertEquals(cros_install_debug_syms.ListBinhost(binhost), expected)
70
71 def testListRemoteBinhostWithURI(self):
72 """Check that urls are generated correctly when URI is defined."""
73 index = SimpleIndex({'URI': 'gs://chromeos-prebuilts'},
74 [{'CPV': 'chromeos-base/shill-0-r1',
75 'DEBUG_SYMBOLS': 'yes',
76 'PATH': 'amd64-generic/paladin1234/shill-0-r1.tbz2'}])
77 self.PatchObject(cros_install_debug_syms, 'GetPackageIndex',
78 return_value=index)
79
80 binhost = 'gs://chromeos-prebuilts/gizmo-paladin/'
81 debug_symbols_url = ('gs://chromeos-prebuilts/amd64-generic'
82 '/paladin1234/shill-0-r1.debug.tbz2')
83 self.assertEquals(cros_install_debug_syms.ListBinhost(binhost),
84 {'chromeos-base/shill-0-r1': debug_symbols_url})
85
86
87if __name__ == '__main__':
88 cros_test_lib.main()