blob: bbcf18ae410f2c08c4c3210cc715a28e22585b1c [file] [log] [blame]
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -08001#!/usr/bin/python
2
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -07003# 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 Sharif0dcbc4b2012-02-02 16:37:18 -08006
Ahmad Sharif4467f002012-12-20 12:09:49 -08007"""The label of benchamrks."""
8
9import os
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -080010from utils.file_utils import FileUtils
Yunlian Jiangffd98bb2013-08-02 10:42:25 -070011from utils import misc
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -080012
13
14class Label(object):
Ahmad Sharif4467f002012-12-20 12:09:49 -080015 def __init__(self, name, chromeos_image, chromeos_root, board, remote,
cmtice98a53692014-04-16 14:48:47 -070016 image_args, cache_dir, chrome_src=None):
cmtice0cc4e772014-01-30 15:52:37 -080017
18 self.image_type = self._GetImageType(chromeos_image)
19
Ahmad Sharif4467f002012-12-20 12:09:49 -080020 # Expand ~
21 chromeos_root = os.path.expanduser(chromeos_root)
cmtice0cc4e772014-01-30 15:52:37 -080022 if self.image_type == "local":
23 chromeos_image = os.path.expanduser(chromeos_image)
Ahmad Sharif4467f002012-12-20 12:09:49 -080024
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -080025 self.name = name
26 self.chromeos_image = chromeos_image
27 self.board = board
Ahmad Sharif4467f002012-12-20 12:09:49 -080028 self.remote = remote
29 self.image_args = image_args
Luis Lozanof81680c2013-03-15 14:44:13 -070030 self.cache_dir = cache_dir
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -080031
32 if not chromeos_root:
cmtice0cc4e772014-01-30 15:52:37 -080033 if self.image_type == "local":
34 chromeos_root = FileUtils().ChromeOSRootFromImage(chromeos_image)
Ahmad Sharif0dcbc4b2012-02-02 16:37:18 -080035 if not chromeos_root:
36 raise Exception("No ChromeOS root given for label '%s' and could not "
37 "determine one from image path: '%s'." %
38 (name, chromeos_image))
39 else:
40 chromeos_root = FileUtils().CanonicalizeChromeOSRoot(chromeos_root)
41 if not chromeos_root:
42 raise Exception("Invalid ChromeOS root given for label '%s': '%s'."
43 % (name, chromeos_root))
44
45 self.chromeos_root = chromeos_root
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070046 if not chrome_src:
47 self.chrome_src = os.path.join(self.chromeos_root,
cmtice226e3e02014-04-27 22:28:42 -070048 ".cache/distfiles/target/chrome-src-internal")
cmtice04403882013-11-04 16:38:37 -050049 if not os.path.exists(self.chrome_src):
50 self.chrome_src = os.path.join(self.chromeos_root,
cmtice226e3e02014-04-27 22:28:42 -070051 ".cache/distfiles/target/chrome-src")
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070052 else:
Yunlian Jiangffd98bb2013-08-02 10:42:25 -070053 chromeos_src = misc.CanonicalizePath(chrome_src)
54 if not chromeos_src:
55 raise Exception("Invalid Chrome src given for label '%s': '%s'."
56 % (name, chrome_src))
57 self.chrome_src = chromeos_src
Ahmad Sharif4467f002012-12-20 12:09:49 -080058
cmtice0cc4e772014-01-30 15:52:37 -080059 def _GetImageType(self, chromeos_image):
60 image_type = None
61 if chromeos_image.find("xbuddy://") < 0:
62 image_type = "local"
63 elif chromeos_image.find("trybot") >= 0:
64 image_type = "trybot"
65 else:
66 image_type = "official"
67 return image_type
Ahmad Sharif4467f002012-12-20 12:09:49 -080068
69class MockLabel(object):
70 def __init__(self, name, chromeos_image, chromeos_root, board, remote,
cmtice98a53692014-04-16 14:48:47 -070071 image_args, cache_dir, chrome_src=None):
Ahmad Sharif4467f002012-12-20 12:09:49 -080072 self.name = name
73 self.chromeos_image = chromeos_image
74 self.board = board
75 self.remote = remote
Luis Lozanof81680c2013-03-15 14:44:13 -070076 self.cache_dir = cache_dir
Ahmad Sharif4467f002012-12-20 12:09:49 -080077 if not chromeos_root:
78 self.chromeos_root = "/tmp/chromeos_root"
79 else:
80 self.chromeos_root = chromeos_root
81 self.image_args = image_args
cmtice0cc4e772014-01-30 15:52:37 -080082 self.chrome_src = chrome_src