1 // Copyright (c) 2012 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 #include "gpu/config/gpu_test_config.h" 6 7 #include "base/logging.h" 8 #include "base/sys_info.h" 9 #include "gpu/config/gpu_info.h" 10 #include "gpu/config/gpu_info_collector.h" 11 #include "gpu/config/gpu_test_expectations_parser.h" 12 13 #if defined(OS_MACOSX) 14 #include "base/mac/mac_util.h" 15 #endif 16 17 namespace gpu { 18 19 namespace { 20 21 GPUTestConfig::OS GetCurrentOS() { 22 #if defined(OS_CHROMEOS) 23 return GPUTestConfig::kOsChromeOS; 24 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 25 return GPUTestConfig::kOsLinux; 26 #elif defined(OS_WIN) 27 int32 major_version = 0; 28 int32 minor_version = 0; 29 int32 bugfix_version = 0; 30 base::SysInfo::OperatingSystemVersionNumbers( 31 &major_version, &minor_version, &bugfix_version); 32 if (major_version == 5) 33 return GPUTestConfig::kOsWinXP; 34 if (major_version == 6 && minor_version == 0) 35 return GPUTestConfig::kOsWinVista; 36 if (major_version == 6 && minor_version == 1) 37 return GPUTestConfig::kOsWin7; 38 if (major_version == 6 && minor_version == 2) 39 return GPUTestConfig::kOsWin8; 40 #elif defined(OS_MACOSX) 41 int32 major_version = 0; 42 int32 minor_version = 0; 43 int32 bugfix_version = 0; 44 base::SysInfo::OperatingSystemVersionNumbers( 45 &major_version, &minor_version, &bugfix_version); 46 if (major_version == 10) { 47 switch (minor_version) { 48 case 5: 49 return GPUTestConfig::kOsMacLeopard; 50 case 6: 51 return GPUTestConfig::kOsMacSnowLeopard; 52 case 7: 53 return GPUTestConfig::kOsMacLion; 54 case 8: 55 return GPUTestConfig::kOsMacMountainLion; 56 } 57 } 58 #elif defined(OS_ANDROID) 59 return GPUTestConfig::kOsAndroid; 60 #endif 61 return GPUTestConfig::kOsUnknown; 62 } 63 64 } // namespace anonymous 65 66 GPUTestConfig::GPUTestConfig() 67 : validate_gpu_info_(true), 68 os_(kOsUnknown), 69 gpu_device_id_(0), 70 build_type_(kBuildTypeUnknown) { 71 } 72 73 GPUTestConfig::~GPUTestConfig() { 74 } 75 76 void GPUTestConfig::set_os(int32 os) { 77 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS)); 78 os_ = os; 79 } 80 81 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) { 82 DCHECK_NE(0u, gpu_vendor); 83 for (size_t i = 0; i < gpu_vendor_.size(); ++i) 84 DCHECK_NE(gpu_vendor_[i], gpu_vendor); 85 gpu_vendor_.push_back(gpu_vendor); 86 } 87 88 void GPUTestConfig::set_gpu_device_id(uint32 id) { 89 gpu_device_id_ = id; 90 } 91 92 void GPUTestConfig::set_build_type(int32 build_type) { 93 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug)); 94 build_type_ = build_type; 95 } 96 97 bool GPUTestConfig::IsValid() const { 98 if (!validate_gpu_info_) 99 return true; 100 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0)) 101 return false; 102 return true; 103 } 104 105 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const { 106 DCHECK(IsValid()); 107 DCHECK(config.IsValid()); 108 if (config.os_ != kOsUnknown && os_ != kOsUnknown && 109 (os_ & config.os_) == 0) 110 return false; 111 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) { 112 bool shared = false; 113 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) { 114 for (size_t j = 0; j < gpu_vendor_.size(); ++j) { 115 if (config.gpu_vendor_[i] == gpu_vendor_[j]) { 116 shared = true; 117 break; 118 } 119 } 120 } 121 if (!shared) 122 return false; 123 } 124 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 && 125 gpu_device_id_ != config.gpu_device_id_) 126 return false; 127 if (config.build_type_ != kBuildTypeUnknown && 128 build_type_ != kBuildTypeUnknown && 129 (build_type_ & config.build_type_) == 0) 130 return false; 131 return true; 132 } 133 134 void GPUTestConfig::DisableGPUInfoValidation() { 135 validate_gpu_info_ = false; 136 } 137 138 void GPUTestConfig::ClearGPUVendor() { 139 gpu_vendor_.clear(); 140 } 141 142 GPUTestBotConfig::~GPUTestBotConfig() { 143 } 144 145 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) { 146 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size()); 147 GPUTestConfig::AddGPUVendor(gpu_vendor); 148 } 149 150 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) { 151 DCHECK(validate_gpu_info_); 152 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0) 153 return false; 154 ClearGPUVendor(); 155 AddGPUVendor(gpu_info.gpu.vendor_id); 156 set_gpu_device_id(gpu_info.gpu.device_id); 157 return true; 158 } 159 160 bool GPUTestBotConfig::IsValid() const { 161 switch (os()) { 162 case kOsWinXP: 163 case kOsWinVista: 164 case kOsWin7: 165 case kOsWin8: 166 case kOsMacLeopard: 167 case kOsMacSnowLeopard: 168 case kOsMacLion: 169 case kOsMacMountainLion: 170 case kOsLinux: 171 case kOsChromeOS: 172 case kOsAndroid: 173 break; 174 default: 175 return false; 176 } 177 if (validate_gpu_info_) { 178 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0) 179 return false; 180 if (gpu_device_id() == 0) 181 return false; 182 } 183 switch (build_type()) { 184 case kBuildTypeRelease: 185 case kBuildTypeDebug: 186 break; 187 default: 188 return false; 189 } 190 return true; 191 } 192 193 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const { 194 DCHECK(IsValid()); 195 DCHECK(config.IsValid()); 196 if (config.os() != kOsUnknown && (os() & config.os()) == 0) 197 return false; 198 if (config.gpu_vendor().size() > 0) { 199 bool contained = false; 200 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) { 201 if (config.gpu_vendor()[i] == gpu_vendor()[0]) { 202 contained = true; 203 break; 204 } 205 } 206 if (!contained) 207 return false; 208 } 209 if (config.gpu_device_id() != 0 && 210 gpu_device_id() != config.gpu_device_id()) 211 return false; 212 if (config.build_type() != kBuildTypeUnknown && 213 (build_type() & config.build_type()) == 0) 214 return false; 215 return true; 216 } 217 218 bool GPUTestBotConfig::Matches(const std::string& config_data) const { 219 GPUTestExpectationsParser parser; 220 GPUTestConfig config; 221 222 if (!parser.ParseConfig(config_data, &config)) 223 return false; 224 return Matches(config); 225 } 226 227 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) { 228 bool rt; 229 if (gpu_info == NULL) { 230 GPUInfo my_gpu_info; 231 GpuIDResult result; 232 result = CollectGpuID(&my_gpu_info.gpu.vendor_id, 233 &my_gpu_info.gpu.device_id); 234 if (result == kGpuIDNotSupported) { 235 DisableGPUInfoValidation(); 236 rt = true; 237 } else { 238 rt = SetGPUInfo(my_gpu_info); 239 } 240 } else { 241 rt = SetGPUInfo(*gpu_info); 242 } 243 set_os(GetCurrentOS()); 244 if (os() == kOsUnknown) 245 rt = false; 246 #if defined(NDEBUG) 247 set_build_type(kBuildTypeRelease); 248 #else 249 set_build_type(kBuildTypeDebug); 250 #endif 251 return rt; 252 } 253 254 // static 255 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) { 256 GPUTestBotConfig my_config; 257 if (!my_config.LoadCurrentConfig(NULL)) 258 return false; 259 return my_config.Matches(config_data); 260 } 261 262 // static 263 bool GPUTestBotConfig::CurrentConfigMatches( 264 const std::vector<std::string>& configs) { 265 GPUTestBotConfig my_config; 266 if (!my_config.LoadCurrentConfig(NULL)) 267 return false; 268 for (size_t i = 0 ; i < configs.size(); ++i) { 269 if (my_config.Matches(configs[i])) 270 return true; 271 } 272 return false; 273 } 274 275 // static 276 bool GPUTestBotConfig::GpuBlacklistedOnBot() { 277 #if defined(OS_MACOSX) 278 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots. 279 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) { 280 return true; 281 } 282 #endif 283 // TODO(ccameron): This should be true on Windows XP as well. 284 return false; 285 } 286 287 } // namespace gpu 288 289