blob: ff3c9e0cebe5a9e05149c266f3bcc6081ccadfa7 [file] [log] [blame]
Marat Dukhancf149942017-09-08 17:39:01 -07001#include <gtest/gtest.h>
2
3#include <cpuinfo.h>
4#include <cpuinfo-mock.h>
5
6
7TEST(PROCESSORS, count) {
8 ASSERT_EQ(4, cpuinfo_processors_count);
9}
10
11TEST(PROCESSORS, non_null) {
12 ASSERT_TRUE(cpuinfo_processors);
13}
14
15TEST(PROCESSORS, vendor) {
16 for (uint32_t i = 0; i < cpuinfo_processors_count; i++) {
17 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_processors[i].vendor);
18 }
19}
20
21TEST(PROCESSORS, uarch) {
22 for (uint32_t i = 0; i < cpuinfo_processors_count; i++) {
23 ASSERT_EQ(cpuinfo_uarch_kryo, cpuinfo_processors[i].uarch);
24 }
25}
26
27TEST(ISA, thumb) {
28 ASSERT_TRUE(cpuinfo_isa.thumb);
29}
30
31TEST(ISA, thumb2) {
32 ASSERT_TRUE(cpuinfo_isa.thumb2);
33}
34
35TEST(ISA, thumbee) {
36 ASSERT_FALSE(cpuinfo_isa.thumbee);
37}
38
39TEST(ISA, jazelle) {
40 ASSERT_FALSE(cpuinfo_isa.jazelle);
41}
42
43TEST(ISA, armv5e) {
44 ASSERT_TRUE(cpuinfo_isa.armv5e);
45}
46
47TEST(ISA, armv6) {
48 ASSERT_TRUE(cpuinfo_isa.armv6);
49}
50
51TEST(ISA, armv6k) {
52 ASSERT_TRUE(cpuinfo_isa.armv6k);
53}
54
55TEST(ISA, armv7) {
56 ASSERT_TRUE(cpuinfo_isa.armv7);
57}
58
59TEST(ISA, armv7mp) {
60 ASSERT_TRUE(cpuinfo_isa.armv7mp);
61}
62
63TEST(ISA, idiv) {
64 ASSERT_TRUE(cpuinfo_isa.idiv);
65}
66
67TEST(ISA, vfpv2) {
68 ASSERT_FALSE(cpuinfo_isa.vfpv2);
69}
70
71TEST(ISA, vfpv3) {
72 ASSERT_TRUE(cpuinfo_isa.vfpv3);
73}
74
75TEST(ISA, d32) {
76 ASSERT_TRUE(cpuinfo_isa.d32);
77}
78
79TEST(ISA, fp16) {
80 ASSERT_TRUE(cpuinfo_isa.fp16);
81}
82
83TEST(ISA, fma) {
84 ASSERT_TRUE(cpuinfo_isa.fma);
85}
86
87TEST(ISA, wmmx) {
88 ASSERT_FALSE(cpuinfo_isa.wmmx);
89}
90
91TEST(ISA, wmmx2) {
92 ASSERT_FALSE(cpuinfo_isa.wmmx2);
93}
94
95TEST(ISA, neon) {
96 ASSERT_TRUE(cpuinfo_isa.neon);
97}
98
99TEST(ISA, aes) {
100 ASSERT_TRUE(cpuinfo_isa.aes);
101}
102
103TEST(ISA, sha1) {
104 ASSERT_TRUE(cpuinfo_isa.sha1);
105}
106
107TEST(ISA, sha2) {
108 ASSERT_TRUE(cpuinfo_isa.sha2);
109}
110
111TEST(ISA, pmull) {
112 ASSERT_TRUE(cpuinfo_isa.pmull);
113}
114
115TEST(ISA, crc32) {
116 ASSERT_TRUE(cpuinfo_isa.crc32);
117}
118
119TEST(L1I, count) {
120 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
121 ASSERT_EQ(4, l1i.count);
122}
123
124TEST(L1I, non_null) {
125 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
126 ASSERT_TRUE(l1i.instances);
127}
128
129TEST(L1I, size) {
130 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
131 for (uint32_t k = 0; k < l1i.count; k++) {
132 ASSERT_EQ(32 * 1024, l1i.instances[k].size);
133 }
134}
135
136TEST(L1I, associativity) {
137 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
138 for (uint32_t k = 0; k < l1i.count; k++) {
139 ASSERT_EQ(4, l1i.instances[k].associativity);
140 }
141}
142
143TEST(L1I, sets) {
144 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
145 for (uint32_t k = 0; k < l1i.count; k++) {
146 ASSERT_EQ(l1i.instances[k].size,
147 l1i.instances[k].sets * l1i.instances[k].line_size * l1i.instances[k].partitions * l1i.instances[k].associativity);
148 }
149}
150
151TEST(L1I, partitions) {
152 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
153 for (uint32_t k = 0; k < l1i.count; k++) {
154 ASSERT_EQ(1, l1i.instances[k].partitions);
155 }
156}
157
158TEST(L1I, line_size) {
159 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
160 for (uint32_t k = 0; k < l1i.count; k++) {
161 ASSERT_EQ(64, l1i.instances[k].line_size);
162 }
163}
164
165TEST(L1I, flags) {
166 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
167 for (uint32_t k = 0; k < l1i.count; k++) {
168 ASSERT_EQ(0, l1i.instances[k].flags);
169 }
170}
171
172TEST(L1I, processors) {
173 cpuinfo_caches l1i = cpuinfo_get_l1i_cache();
174 for (uint32_t k = 0; k < l1i.count; k++) {
175 ASSERT_EQ(k, l1i.instances[k].processor_start);
176 ASSERT_EQ(1, l1i.instances[k].processor_count);
177 }
178}
179
180TEST(L1D, count) {
181 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
182 ASSERT_EQ(4, l1d.count);
183}
184
185TEST(L1D, non_null) {
186 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
187 ASSERT_TRUE(l1d.instances);
188}
189
190TEST(L1D, size) {
191 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
192 for (uint32_t k = 0; k < l1d.count; k++) {
193 ASSERT_EQ(24 * 1024, l1d.instances[k].size);
194 }
195}
196
197TEST(L1D, associativity) {
198 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
199 for (uint32_t k = 0; k < l1d.count; k++) {
200 ASSERT_EQ(3, l1d.instances[k].associativity);
201 }
202}
203
204TEST(L1D, sets) {
205 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
206 for (uint32_t k = 0; k < l1d.count; k++) {
207 ASSERT_EQ(l1d.instances[k].size,
208 l1d.instances[k].sets * l1d.instances[k].line_size * l1d.instances[k].partitions * l1d.instances[k].associativity);
209 }
210}
211
212TEST(L1D, partitions) {
213 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
214 for (uint32_t k = 0; k < l1d.count; k++) {
215 ASSERT_EQ(1, l1d.instances[k].partitions);
216 }
217}
218
219TEST(L1D, line_size) {
220 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
221 for (uint32_t k = 0; k < l1d.count; k++) {
222 ASSERT_EQ(64, l1d.instances[k].line_size);
223 }
224}
225
226TEST(L1D, flags) {
227 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
228 for (uint32_t k = 0; k < l1d.count; k++) {
229 ASSERT_EQ(0, l1d.instances[k].flags);
230 }
231}
232
233TEST(L1D, processors) {
234 cpuinfo_caches l1d = cpuinfo_get_l1d_cache();
235 for (uint32_t k = 0; k < l1d.count; k++) {
236 ASSERT_EQ(k, l1d.instances[k].processor_start);
237 ASSERT_EQ(1, l1d.instances[k].processor_count);
238 }
239}
240
241TEST(L2, count) {
242 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
243 ASSERT_EQ(2, l2.count);
244}
245
246TEST(L2, non_null) {
247 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
248 ASSERT_TRUE(l2.instances);
249}
250
251TEST(L2, size) {
252 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
253 for (uint32_t k = 0; k < l2.count; k++) {
254 switch (k) {
255 case 0:
256 ASSERT_EQ(1 * 1024 * 1024, l2.instances[k].size);
257 break;
258 case 1:
259 ASSERT_EQ(512 * 1024, l2.instances[k].size);
260 break;
261 }
262 }
263}
264
265TEST(L2, associativity) {
266 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
267 for (uint32_t k = 0; k < l2.count; k++) {
268 ASSERT_EQ(8, l2.instances[k].associativity);
269 }
270}
271
272TEST(L2, sets) {
273 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
274 for (uint32_t k = 0; k < l2.count; k++) {
275 ASSERT_EQ(l2.instances[k].size,
276 l2.instances[k].sets * l2.instances[k].line_size * l2.instances[k].partitions * l2.instances[k].associativity);
277 }
278}
279
280TEST(L2, partitions) {
281 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
282 for (uint32_t k = 0; k < l2.count; k++) {
283 ASSERT_EQ(1, l2.instances[k].partitions);
284 }
285}
286
287TEST(L2, line_size) {
288 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
289 for (uint32_t k = 0; k < l2.count; k++) {
290 ASSERT_EQ(128, l2.instances[k].line_size);
291 }
292}
293
294TEST(L2, flags) {
295 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
296 for (uint32_t k = 0; k < l2.count; k++) {
297 ASSERT_EQ(0, l2.instances[k].flags);
298 }
299}
300
301TEST(L2, processors) {
302 cpuinfo_caches l2 = cpuinfo_get_l2_cache();
303 for (uint32_t k = 0; k < l2.count; k++) {
304 switch (k) {
305 case 0:
306 ASSERT_EQ(0, l2.instances[k].processor_start);
307 ASSERT_EQ(2, l2.instances[k].processor_count);
308 break;
309 case 1:
310 ASSERT_EQ(2, l2.instances[k].processor_start);
311 ASSERT_EQ(2, l2.instances[k].processor_count);
312 break;
313 }
314 }
315}
316
317TEST(L3, none) {
318 cpuinfo_caches l3 = cpuinfo_get_l3_cache();
319 ASSERT_EQ(0, l3.count);
320 ASSERT_FALSE(l3.instances);
321}
322
323TEST(L4, none) {
324 cpuinfo_caches l4 = cpuinfo_get_l4_cache();
325 ASSERT_EQ(0, l4.count);
326 ASSERT_FALSE(l4.instances);
327}
328
329#include <pixel.h>
330
331int main(int argc, char* argv[]) {
332 cpuinfo_mock_filesystem(filesystem);
333 cpuinfo_initialize();
334 ::testing::InitGoogleTest(&argc, argv);
335 return RUN_ALL_TESTS();
336}