Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 3 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 6 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 7 | """The label of benchamrks.""" |
| 8 | |
| 9 | import os |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 10 | from utils.file_utils import FileUtils |
| 11 | |
| 12 | |
| 13 | class Label(object): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 14 | def __init__(self, name, chromeos_image, chromeos_root, board, remote, |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 15 | image_args, image_md5sum, cache_dir, chrome_src=None): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 16 | # Expand ~ |
| 17 | chromeos_root = os.path.expanduser(chromeos_root) |
| 18 | chromeos_image = os.path.expanduser(chromeos_image) |
| 19 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 20 | self.name = name |
| 21 | self.chromeos_image = chromeos_image |
| 22 | self.board = board |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 23 | self.remote = remote |
| 24 | self.image_args = image_args |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 25 | self.image_md5sum = image_md5sum |
| 26 | self.cache_dir = cache_dir |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 27 | |
| 28 | if not chromeos_root: |
| 29 | chromeos_root = FileUtils().ChromeOSRootFromImage(chromeos_image) |
| 30 | if not chromeos_root: |
| 31 | raise Exception("No ChromeOS root given for label '%s' and could not " |
| 32 | "determine one from image path: '%s'." % |
| 33 | (name, chromeos_image)) |
| 34 | else: |
| 35 | chromeos_root = FileUtils().CanonicalizeChromeOSRoot(chromeos_root) |
| 36 | if not chromeos_root: |
| 37 | raise Exception("Invalid ChromeOS root given for label '%s': '%s'." |
| 38 | % (name, chromeos_root)) |
| 39 | |
| 40 | self.chromeos_root = chromeos_root |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 41 | if not chrome_src: |
| 42 | self.chrome_src = os.path.join(self.chromeos_root, |
| 43 | "chroot/var/cache/chromeos-chrome/chrome-src-internal/src") |
| 44 | else: |
| 45 | chromeos_root = FileUtils().CanonicalizeChromeOSRoot(chrome_src) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 46 | |
| 47 | |
| 48 | class MockLabel(object): |
| 49 | def __init__(self, name, chromeos_image, chromeos_root, board, remote, |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 50 | image_args, image_md5sum, cache_dir): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 51 | self.name = name |
| 52 | self.chromeos_image = chromeos_image |
| 53 | self.board = board |
| 54 | self.remote = remote |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 55 | self.cache_dir = cache_dir |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 56 | if not chromeos_root: |
| 57 | self.chromeos_root = "/tmp/chromeos_root" |
| 58 | else: |
| 59 | self.chromeos_root = chromeos_root |
| 60 | self.image_args = image_args |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 61 | self.image_md5sum = image_md5sum |