[telemetry] Add an option --upload-results to store the html results in google storag...
[chromium-blink-merge.git] / base / test / expectations / expectation.cc
blob0674cf57d2978b4d61d301e7bad19b2558be28b0
1 // Copyright (c) 2013 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.
5 #include "base/test/expectations/expectation.h"
7 #include "base/logging.h"
9 #if defined(OS_WIN)
10 #include "base/win/windows_version.h"
11 #elif defined(OS_MACOSX) && !defined(OS_IOS)
12 #include "base/mac/mac_util.h"
13 #elif defined(OS_LINUX)
14 #include "base/sys_info.h"
15 #endif
17 namespace test_expectations {
19 bool ResultFromString(const base::StringPiece& result, Result* out_result) {
20 if (result == "Failure")
21 *out_result = RESULT_FAILURE;
22 else if (result == "Timeout")
23 *out_result = RESULT_TIMEOUT;
24 else if (result == "Crash")
25 *out_result = RESULT_CRASH;
26 else if (result == "Skip")
27 *out_result = RESULT_SKIP;
28 else if (result == "Pass")
29 *out_result = RESULT_PASS;
30 else
31 return false;
33 return true;
36 static bool IsValidPlatform(const Platform* platform) {
37 const std::string& name = platform->name;
38 const std::string& variant = platform->variant;
40 if (name == "Win") {
41 if (variant != "" &&
42 variant != "XP" &&
43 variant != "Vista" &&
44 variant != "7" &&
45 variant != "8") {
46 return false;
48 } else if (name == "Mac") {
49 if (variant != "" &&
50 variant != "10.6" &&
51 variant != "10.7" &&
52 variant != "10.8" &&
53 variant != "10.9") {
54 return false;
56 } else if (name == "Linux") {
57 if (variant != "" &&
58 variant != "32" &&
59 variant != "64") {
60 return false;
62 } else if (name == "ChromeOS") {
63 // TODO(rsesek): Figure out what ChromeOS needs.
64 } else if (name == "iOS") {
65 // TODO(rsesek): Figure out what iOS needs. Probably Device and Simulator.
66 } else if (name == "Android") {
67 // TODO(rsesek): Figure out what Android needs.
68 } else {
69 return false;
72 return true;
75 bool PlatformFromString(const base::StringPiece& modifier,
76 Platform* out_platform) {
77 size_t sep = modifier.find('-');
78 if (sep == std::string::npos) {
79 out_platform->name = modifier.as_string();
80 out_platform->variant.clear();
81 } else {
82 out_platform->name = modifier.substr(0, sep).as_string();
83 out_platform->variant = modifier.substr(sep + 1).as_string();
86 return IsValidPlatform(out_platform);
89 Platform GetCurrentPlatform() {
90 Platform platform;
91 #if defined(OS_WIN)
92 platform.name = "Win";
93 base::win::Version version = base::win::GetVersion();
94 if (version == base::win::VERSION_XP)
95 platform.variant = "XP";
96 else if (version == base::win::VERSION_VISTA)
97 platform.variant = "Vista";
98 else if (version == base::win::VERSION_WIN7)
99 platform.variant = "7";
100 else if (version == base::win::VERSION_WIN8)
101 platform.variant = "8";
102 #elif defined(OS_IOS)
103 platform.name = "iOS";
104 #elif defined(OS_MACOSX)
105 platform.name = "Mac";
106 if (base::mac::IsOSSnowLeopard())
107 platform.variant = "10.6";
108 else if (base::mac::IsOSLion())
109 platform.variant = "10.7";
110 else if (base::mac::IsOSMountainLion())
111 platform.variant = "10.8";
112 else if (base::mac::IsOSMavericks())
113 platform.variant = "10.9";
114 #elif defined(OS_CHROMEOS)
115 platform.name = "ChromeOS";
116 #elif defined(OS_ANDROID)
117 platform.name = "Android";
118 #elif defined(OS_LINUX)
119 platform.name = "Linux";
120 std::string arch = base::SysInfo::OperatingSystemArchitecture();
121 if (arch == "x86")
122 platform.variant = "32";
123 else if (arch == "x86_64")
124 platform.variant = "64";
125 #else
126 NOTREACHED();
127 #endif
128 return platform;
131 bool ConfigurationFromString(const base::StringPiece& modifier,
132 Configuration* out_configuration) {
133 if (modifier == "Debug")
134 *out_configuration = CONFIGURATION_DEBUG;
135 else if (modifier == "Release")
136 *out_configuration = CONFIGURATION_RELEASE;
137 else
138 return false;
140 return true;
143 Configuration GetCurrentConfiguration() {
144 #if NDEBUG
145 return CONFIGURATION_RELEASE;
146 #else
147 return CONFIGURATION_DEBUG;
148 #endif
149 NOTREACHED();
150 return CONFIGURATION_UNSPECIFIED;
153 Expectation::Expectation()
154 : configuration(CONFIGURATION_UNSPECIFIED),
155 result(RESULT_PASS) {
158 Expectation::~Expectation() {}
160 } // namespace test_expectations