Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: mojo/tools/mopy/config.py

Issue 878933003: Move the apptest runner and parts of mopy to the public SDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/tools/mopy/background_app_group.py ('k') | mojo/tools/mopy/file_hash.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Build/test configurations, which are just dictionaries. This
6 "defines" the schema and provides some wrappers."""
7
8
9 import json
10 import os.path
11 import platform
12 import sys
13
14
15 class Config(object):
16 """A Config is basically just a wrapper around a dictionary that species a
17 build/test configuration. The dictionary is accessible through the values
18 member."""
19
20 # Valid values for target_os (None is also valid):
21 OS_ANDROID = "android"
22 OS_CHROMEOS = "chromeos"
23 OS_LINUX = "linux"
24 OS_MAC = "mac"
25 OS_WINDOWS = "windows"
26
27 # Valid values for target_arch (None is also valid):
28 ARCH_X86 = "x86"
29 ARCH_X64 = "x64"
30 ARCH_ARM = "arm"
31
32 # Valid values for sanitizer (None is also valid):
33 SANITIZER_ASAN = "asan"
34
35 # Standard values for test types (test types are arbitrary strings; other
36 # values are allowed).
37 TEST_TYPE_DEFAULT = "default"
38 TEST_TYPE_UNIT = "unit"
39 TEST_TYPE_PERF = "perf"
40 TEST_TYPE_INTEGRATION = "integration"
41
42 def __init__(self, target_os=None, target_arch=None, is_debug=True,
43 is_clang=None, sanitizer=None, **kwargs):
44 """Constructs a Config with key-value pairs specified via keyword arguments.
45 If target_os is not specified, it will be set to the host OS."""
46
47 assert target_os in (None, Config.OS_ANDROID, Config.OS_CHROMEOS,
48 Config.OS_LINUX, Config.OS_MAC, Config.OS_WINDOWS)
49 assert target_arch in (None, Config.ARCH_X86, Config.ARCH_X64,
50 Config.ARCH_ARM)
51 assert isinstance(is_debug, bool)
52 assert is_clang is None or isinstance(is_clang, bool)
53 assert sanitizer in (None, Config.SANITIZER_ASAN)
54 if "test_types" in kwargs:
55 assert isinstance(kwargs["test_types"], list)
56
57 self.values = {}
58 self.values["target_os"] = (self.GetHostOS() if target_os is None else
59 target_os)
60 self.values["target_arch"] = (self.GetHostCPUArch() if target_arch is None
61 else target_arch)
62 self.values["is_debug"] = is_debug
63 self.values["is_clang"] = is_clang
64 self.values["sanitizer"] = sanitizer
65
66 self.values.update(kwargs)
67
68 @staticmethod
69 def GetHostOS():
70 if sys.platform == "linux2":
71 return Config.OS_LINUX
72 if sys.platform == "darwin":
73 return Config.OS_MAC
74 if sys.platform == "win32":
75 return Config.OS_WINDOWS
76 raise NotImplementedError("Unsupported host OS")
77
78 @staticmethod
79 def GetHostCPUArch():
80 # Derived from //native_client/pynacl/platform.py
81 machine = platform.machine()
82 if machine in ("x86", "x86-32", "x86_32", "x8632", "i386", "i686", "ia32",
83 "32"):
84 return Config.ARCH_X86
85 if machine in ("x86-64", "amd64", "x86_64", "x8664", "64"):
86 return Config.ARCH_X64
87 if machine.startswith("arm"):
88 return Config.ARCH_ARM
89 raise Exception("Cannot identify CPU arch: %s" % machine)
90
91 # Getters for standard fields ------------------------------------------------
92
93 @property
94 def target_os(self):
95 """OS of the build/test target."""
96 return self.values["target_os"]
97
98 @property
99 def target_arch(self):
100 """CPU arch of the build/test target."""
101 return self.values["target_arch"]
102
103 @property
104 def is_debug(self):
105 """Is Debug build?"""
106 return self.values["is_debug"]
107
108 @property
109 def is_clang(self):
110 """Should use clang?"""
111 return self.values["is_clang"]
112
113 @property
114 def sanitizer(self):
115 """Sanitizer to use, if any."""
116 return self.values["sanitizer"]
117
118 @property
119 def test_types(self):
120 """List of test types to run."""
121 return self.values.get("test_types", [Config.TEST_TYPE_DEFAULT])
OLDNEW
« no previous file with comments | « mojo/tools/mopy/background_app_group.py ('k') | mojo/tools/mopy/file_hash.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698