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.
5 #include "gpu/config/gpu_info.h"
6 #include "gpu/config/gpu_test_config.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 class GPUTestConfigTest
: public testing::Test
{
13 GPUTestConfigTest() { }
15 ~GPUTestConfigTest() override
{}
18 void SetUp() override
{}
20 void TearDown() override
{}
23 TEST_F(GPUTestConfigTest
, EmptyValues
) {
25 EXPECT_EQ(GPUTestConfig::kOsUnknown
, config
.os());
26 EXPECT_EQ(0u, config
.gpu_vendor().size());
27 EXPECT_EQ(0u, config
.gpu_device_id());
28 EXPECT_EQ(GPUTestConfig::kBuildTypeUnknown
, config
.build_type());
31 TEST_F(GPUTestConfigTest
, SetGPUInfo
) {
33 gpu_info
.gpu
.vendor_id
= 0x10de;
34 gpu_info
.gpu
.device_id
= 0x0640;
35 GPUTestBotConfig config
;
36 EXPECT_TRUE(config
.SetGPUInfo(gpu_info
));
37 EXPECT_EQ(1u, config
.gpu_vendor().size());
38 EXPECT_EQ(gpu_info
.gpu
.vendor_id
, config
.gpu_vendor()[0]);
39 EXPECT_EQ(gpu_info
.gpu
.device_id
, config
.gpu_device_id());
41 gpu_info
.gpu
.vendor_id
= 0x8086;
42 gpu_info
.gpu
.device_id
= 0x0046;
43 EXPECT_TRUE(config
.SetGPUInfo(gpu_info
));
44 EXPECT_EQ(1u, config
.gpu_vendor().size());
45 EXPECT_EQ(gpu_info
.gpu
.vendor_id
, config
.gpu_vendor()[0]);
46 EXPECT_EQ(gpu_info
.gpu
.device_id
, config
.gpu_device_id());
49 TEST_F(GPUTestConfigTest
, IsValid
) {
52 config
.set_gpu_device_id(0x0640);
53 EXPECT_FALSE(config
.IsValid());
54 config
.AddGPUVendor(0x10de);
55 EXPECT_TRUE(config
.IsValid());
59 GPUTestBotConfig config
;
60 config
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
61 config
.set_os(GPUTestConfig::kOsWin7
);
62 config
.set_gpu_device_id(0x0640);
63 EXPECT_FALSE(config
.IsValid());
64 config
.AddGPUVendor(0x10de);
65 EXPECT_TRUE(config
.IsValid());
67 config
.set_gpu_device_id(0);
68 EXPECT_FALSE(config
.IsValid());
69 config
.set_gpu_device_id(0x0640);
70 EXPECT_TRUE(config
.IsValid());
72 config
.set_os(GPUTestConfig::kOsWin
);
73 EXPECT_FALSE(config
.IsValid());
74 config
.set_os(GPUTestConfig::kOsWin7
| GPUTestConfig::kOsWinXP
);
75 EXPECT_FALSE(config
.IsValid());
76 config
.set_os(GPUTestConfig::kOsWin7
);
77 EXPECT_TRUE(config
.IsValid());
79 config
.set_build_type(GPUTestConfig::kBuildTypeUnknown
);
80 EXPECT_FALSE(config
.IsValid());
81 config
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
82 EXPECT_TRUE(config
.IsValid());
86 TEST_F(GPUTestConfigTest
, Matches
) {
87 GPUTestBotConfig config
;
88 config
.set_os(GPUTestConfig::kOsWin7
);
89 config
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
90 config
.AddGPUVendor(0x10de);
91 config
.set_gpu_device_id(0x0640);
92 EXPECT_TRUE(config
.IsValid());
95 GPUTestConfig config2
;
96 EXPECT_TRUE(config
.Matches(config2
));
97 config2
.set_os(GPUTestConfig::kOsWin
);
98 EXPECT_TRUE(config
.Matches(config2
));
99 config2
.set_os(GPUTestConfig::kOsWin7
);
100 EXPECT_TRUE(config
.Matches(config2
));
101 config2
.set_os(GPUTestConfig::kOsMac
);
102 EXPECT_FALSE(config
.Matches(config2
));
103 config2
.set_os(GPUTestConfig::kOsWin7
| GPUTestConfig::kOsLinux
);
104 EXPECT_TRUE(config
.Matches(config2
));
107 { // gpu vendor matching
109 GPUTestConfig config2
;
110 config2
.AddGPUVendor(0x10de);
111 EXPECT_TRUE(config
.Matches(config2
));
112 config2
.AddGPUVendor(0x1004);
113 EXPECT_TRUE(config
.Matches(config2
));
116 GPUTestConfig config2
;
117 config2
.AddGPUVendor(0x8086);
118 EXPECT_FALSE(config
.Matches(config2
));
122 { // build type matching
123 GPUTestConfig config2
;
124 config2
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
125 EXPECT_TRUE(config
.Matches(config2
));
126 config2
.set_build_type(GPUTestConfig::kBuildTypeRelease
|
127 GPUTestConfig::kBuildTypeDebug
);
128 EXPECT_TRUE(config
.Matches(config2
));
129 config2
.set_build_type(GPUTestConfig::kBuildTypeDebug
);
130 EXPECT_FALSE(config
.Matches(config2
));
134 GPUTestConfig config2
;
135 config2
.set_os(GPUTestConfig::kOsWin7
);
136 config2
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
137 config2
.AddGPUVendor(0x10de);
138 config2
.set_gpu_device_id(0x0640);
139 EXPECT_TRUE(config
.Matches(config2
));
140 config2
.set_gpu_device_id(0x0641);
141 EXPECT_FALSE(config
.Matches(config2
));
145 TEST_F(GPUTestConfigTest
, StringMatches
) {
146 GPUTestBotConfig config
;
147 config
.set_os(GPUTestConfig::kOsWin7
);
148 config
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
149 config
.AddGPUVendor(0x10de);
150 config
.set_gpu_device_id(0x0640);
151 EXPECT_TRUE(config
.IsValid());
153 EXPECT_TRUE(config
.Matches(std::string()));
156 EXPECT_TRUE(config
.Matches("WIN"));
157 EXPECT_TRUE(config
.Matches("WIN7"));
158 EXPECT_FALSE(config
.Matches("MAC"));
159 EXPECT_TRUE(config
.Matches("WIN7 LINUX"));
161 // gpu vendor matching
162 EXPECT_TRUE(config
.Matches("NVIDIA"));
163 EXPECT_TRUE(config
.Matches("NVIDIA AMD"));
164 EXPECT_FALSE(config
.Matches("INTEL"));
166 // build type matching
167 EXPECT_TRUE(config
.Matches("RELEASE"));
168 EXPECT_TRUE(config
.Matches("RELEASE DEBUG"));
169 EXPECT_FALSE(config
.Matches("DEBUG"));
172 EXPECT_TRUE(config
.Matches("WIN7 RELEASE NVIDIA 0X0640"));
173 EXPECT_FALSE(config
.Matches("WIN7 RELEASE NVIDIA 0X0641"));
176 TEST_F(GPUTestConfigTest
, OverlapsWith
) {
179 GPUTestConfig config
;
180 config
.set_os(GPUTestConfig::kOsWin
);
181 GPUTestConfig config2
;
182 config2
.set_os(GPUTestConfig::kOsWin7
);
183 EXPECT_TRUE(config
.OverlapsWith(config2
));
184 EXPECT_TRUE(config2
.OverlapsWith(config
));
186 config2
.set_os(GPUTestConfig::kOsWin7
| GPUTestConfig::kOsLinux
);
187 EXPECT_TRUE(config
.OverlapsWith(config2
));
188 EXPECT_TRUE(config2
.OverlapsWith(config
));
190 config2
.set_os(GPUTestConfig::kOsMac
);
191 EXPECT_FALSE(config
.OverlapsWith(config2
));
192 EXPECT_FALSE(config2
.OverlapsWith(config
));
194 config2
.set_os(GPUTestConfig::kOsUnknown
);
195 EXPECT_TRUE(config
.OverlapsWith(config2
));
196 EXPECT_TRUE(config2
.OverlapsWith(config
));
200 GPUTestConfig config
;
201 config
.AddGPUVendor(0x10de);
203 GPUTestConfig config2
;
204 EXPECT_TRUE(config
.OverlapsWith(config2
));
205 EXPECT_TRUE(config2
.OverlapsWith(config
));
207 config2
.AddGPUVendor(0x1086);
208 EXPECT_FALSE(config
.OverlapsWith(config2
));
209 EXPECT_FALSE(config2
.OverlapsWith(config
));
210 // nvidia vs nvidia+intel
211 config2
.AddGPUVendor(0x10de);
212 EXPECT_TRUE(config
.OverlapsWith(config2
));
213 EXPECT_TRUE(config2
.OverlapsWith(config
));
218 GPUTestConfig config
;
219 config
.set_build_type(GPUTestConfig::kBuildTypeRelease
);
220 GPUTestConfig config2
;
221 config2
.set_build_type(GPUTestConfig::kBuildTypeDebug
);
222 EXPECT_FALSE(config
.OverlapsWith(config2
));
223 EXPECT_FALSE(config2
.OverlapsWith(config
));
224 // release vs release+debug
225 config2
.set_build_type(GPUTestConfig::kBuildTypeRelease
|
226 GPUTestConfig::kBuildTypeDebug
);
227 EXPECT_TRUE(config
.OverlapsWith(config2
));
228 EXPECT_TRUE(config2
.OverlapsWith(config
));
229 // release vs unknown
230 config2
.set_build_type(GPUTestConfig::kBuildTypeUnknown
);
231 EXPECT_TRUE(config
.OverlapsWith(config2
));
232 EXPECT_TRUE(config2
.OverlapsWith(config
));
236 GPUTestConfig config
;
237 config
.set_os(GPUTestConfig::kOsWin7
);
238 GPUTestConfig config2
;
239 config2
.AddGPUVendor(0x10de);
240 EXPECT_TRUE(config
.OverlapsWith(config2
));
241 EXPECT_TRUE(config2
.OverlapsWith(config
));
245 TEST_F(GPUTestConfigTest
, LoadCurrentConfig
) {
246 GPUTestBotConfig config
;
248 gpu_info
.gpu
.vendor_id
= 0x10de;
249 gpu_info
.gpu
.device_id
= 0x0640;
250 EXPECT_TRUE(config
.LoadCurrentConfig(&gpu_info
));
251 EXPECT_TRUE(config
.IsValid());