blob: 455cdfbc5adc07aa246d486705aac2e645848ea3 [file] [log] [blame]
Marat Dukhanad741842017-12-03 23:11:46 -08001#include <gtest/gtest.h>
2
3#include <cpuinfo.h>
4#include <cpuinfo-mock.h>
5
6
7TEST(PROCESSORS, count) {
8 ASSERT_EQ(2, cpuinfo_get_processors_count());
9}
10
11TEST(PROCESSORS, non_null) {
12 ASSERT_TRUE(cpuinfo_get_processors());
13}
14
15TEST(PROCESSORS, smt_id) {
16 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
17 ASSERT_EQ(0, cpuinfo_get_processor(i)->smt_id);
18 }
19}
20
21TEST(PROCESSORS, core) {
22 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
23 ASSERT_EQ(cpuinfo_get_core(i), cpuinfo_get_processor(i)->core);
24 }
25}
26
27TEST(PROCESSORS, package) {
28 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
29 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_processor(i)->package);
30 }
31}
32
33TEST(PROCESSORS, linux_id) {
34 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
35 ASSERT_EQ(i, cpuinfo_get_processor(i)->linux_id);
36 }
37}
38
39TEST(PROCESSORS, l1i) {
40 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
41 ASSERT_EQ(cpuinfo_get_l1i_cache(i), cpuinfo_get_processor(i)->cache.l1i);
42 }
43}
44
45TEST(PROCESSORS, l1d) {
46 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
47 ASSERT_EQ(cpuinfo_get_l1d_cache(i), cpuinfo_get_processor(i)->cache.l1d);
48 }
49}
50
51TEST(PROCESSORS, l2) {
52 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
53 ASSERT_EQ(cpuinfo_get_l2_cache(0), cpuinfo_get_processor(i)->cache.l2);
54 }
55}
56
57TEST(PROCESSORS, l3) {
58 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
59 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l3);
60 }
61}
62
63TEST(PROCESSORS, l4) {
64 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
65 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l4);
66 }
67}
68
69TEST(CORES, count) {
70 ASSERT_EQ(2, cpuinfo_get_cores_count());
71}
72
73TEST(CORES, non_null) {
74 ASSERT_TRUE(cpuinfo_get_cores());
75}
76
77TEST(CORES, processor_start) {
78 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
79 ASSERT_EQ(i, cpuinfo_get_core(i)->processor_start);
80 }
81}
82
83TEST(CORES, processor_count) {
84 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
85 ASSERT_EQ(1, cpuinfo_get_core(i)->processor_count);
86 }
87}
88
89TEST(CORES, core_id) {
90 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
91 ASSERT_EQ(i, cpuinfo_get_core(i)->core_id);
92 }
93}
94
95TEST(CORES, package) {
96 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
97 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_core(i)->package);
98 }
99}
100
101TEST(CORES, vendor) {
102 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
103 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_core(i)->vendor);
104 }
105}
106
107TEST(CORES, uarch) {
108 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
109 ASSERT_EQ(cpuinfo_uarch_scorpion, cpuinfo_get_core(i)->uarch);
110 }
111}
112
113TEST(CORES, midr) {
114 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
115 ASSERT_EQ(UINT32_C(0x510F02D4), cpuinfo_get_core(i)->midr);
116 }
117}
118
119TEST(PACKAGES, count) {
120 ASSERT_EQ(1, cpuinfo_get_packages_count());
121}
122
123TEST(PACKAGES, name) {
124 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
125 ASSERT_EQ("Qualcomm MSM8660",
126 std::string(cpuinfo_get_package(i)->name,
127 strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX)));
128 }
129}
130
131TEST(PACKAGES, processor_start) {
132 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
133 ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start);
134 }
135}
136
137TEST(PACKAGES, processor_count) {
138 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
139 ASSERT_EQ(2, cpuinfo_get_package(i)->processor_count);
140 }
141}
142
143TEST(PACKAGES, core_start) {
144 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
145 ASSERT_EQ(0, cpuinfo_get_package(i)->core_start);
146 }
147}
148
149TEST(PACKAGES, core_count) {
150 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
151 ASSERT_EQ(2, cpuinfo_get_package(i)->core_count);
152 }
153}
154
155TEST(ISA, thumb) {
156 ASSERT_TRUE(cpuinfo_has_arm_thumb());
157}
158
159TEST(ISA, thumb2) {
160 ASSERT_TRUE(cpuinfo_has_arm_thumb2());
161}
162
163TEST(ISA, armv5e) {
164 ASSERT_TRUE(cpuinfo_has_arm_v5e());
165}
166
167TEST(ISA, armv6) {
168 ASSERT_TRUE(cpuinfo_has_arm_v6());
169}
170
171TEST(ISA, armv6k) {
172 ASSERT_TRUE(cpuinfo_has_arm_v6k());
173}
174
175TEST(ISA, armv7) {
176 ASSERT_TRUE(cpuinfo_has_arm_v7());
177}
178
179TEST(ISA, DISABLED_armv7mp) {
180 ASSERT_TRUE(cpuinfo_has_arm_v7mp());
181}
182
183TEST(ISA, idiv) {
184 ASSERT_FALSE(cpuinfo_has_arm_idiv());
185}
186
187TEST(ISA, vfpv2) {
188 ASSERT_FALSE(cpuinfo_has_arm_vfpv2());
189}
190
191TEST(ISA, vfpv3) {
192 ASSERT_TRUE(cpuinfo_has_arm_vfpv3());
193}
194
195TEST(ISA, vfpv3_d32) {
196 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_d32());
197}
198
199TEST(ISA, vfpv3_fp16) {
200 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16());
201}
202
203TEST(ISA, vfpv3_fp16_d32) {
204 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16_d32());
205}
206
207TEST(ISA, vfpv4) {
208 ASSERT_FALSE(cpuinfo_has_arm_vfpv4());
209}
210
211TEST(ISA, vfpv4_d32) {
212 ASSERT_FALSE(cpuinfo_has_arm_vfpv4_d32());
213}
214
215TEST(ISA, wmmx) {
216 ASSERT_FALSE(cpuinfo_has_arm_wmmx());
217}
218
219TEST(ISA, wmmx2) {
220 ASSERT_FALSE(cpuinfo_has_arm_wmmx2());
221}
222
223TEST(ISA, neon) {
224 ASSERT_TRUE(cpuinfo_has_arm_neon());
225}
226
227TEST(ISA, neon_fp16) {
228 ASSERT_TRUE(cpuinfo_has_arm_neon_fp16());
229}
230
231TEST(ISA, neon_fma) {
232 ASSERT_FALSE(cpuinfo_has_arm_neon_fma());
233}
234
235TEST(ISA, atomics) {
236 ASSERT_FALSE(cpuinfo_has_arm_atomics());
237}
238
239TEST(ISA, neon_rdm) {
240 ASSERT_FALSE(cpuinfo_has_arm_neon_rdm());
241}
242
243TEST(ISA, fp16_arith) {
244 ASSERT_FALSE(cpuinfo_has_arm_fp16_arith());
245}
246
247TEST(ISA, jscvt) {
248 ASSERT_FALSE(cpuinfo_has_arm_jscvt());
249}
250
251TEST(ISA, fcma) {
252 ASSERT_FALSE(cpuinfo_has_arm_fcma());
253}
254
255TEST(ISA, aes) {
256 ASSERT_FALSE(cpuinfo_has_arm_aes());
257}
258
259TEST(ISA, sha1) {
260 ASSERT_FALSE(cpuinfo_has_arm_sha1());
261}
262
263TEST(ISA, sha2) {
264 ASSERT_FALSE(cpuinfo_has_arm_sha2());
265}
266
267TEST(ISA, pmull) {
268 ASSERT_FALSE(cpuinfo_has_arm_pmull());
269}
270
271TEST(ISA, crc32) {
272 ASSERT_FALSE(cpuinfo_has_arm_crc32());
273}
274
275TEST(L1I, count) {
276 ASSERT_EQ(2, cpuinfo_get_l1i_caches_count());
277}
278
279TEST(L1I, non_null) {
280 ASSERT_TRUE(cpuinfo_get_l1i_caches());
281}
282
283TEST(L1I, size) {
284 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
285 ASSERT_EQ(32 * 1024, cpuinfo_get_l1i_cache(i)->size);
286 }
287}
288
289TEST(L1I, associativity) {
290 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
291 ASSERT_EQ(4, cpuinfo_get_l1i_cache(i)->associativity);
292 }
293}
294
295TEST(L1I, sets) {
296 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
297 ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size,
298 cpuinfo_get_l1i_cache(i)->sets * cpuinfo_get_l1i_cache(i)->line_size * cpuinfo_get_l1i_cache(i)->partitions * cpuinfo_get_l1i_cache(i)->associativity);
299 }
300}
301
302TEST(L1I, partitions) {
303 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
304 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions);
305 }
306}
307
308TEST(L1I, line_size) {
309 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
310 ASSERT_EQ(32, cpuinfo_get_l1i_cache(i)->line_size);
311 }
312}
313
314TEST(L1I, flags) {
315 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
316 ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags);
317 }
318}
319
320TEST(L1I, processors) {
321 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
322 ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start);
323 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count);
324 }
325}
326
327TEST(L1D, count) {
328 ASSERT_EQ(2, cpuinfo_get_l1d_caches_count());
329}
330
331TEST(L1D, non_null) {
332 ASSERT_TRUE(cpuinfo_get_l1d_caches());
333}
334
335TEST(L1D, size) {
336 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
337 ASSERT_EQ(32 * 1024, cpuinfo_get_l1d_cache(i)->size);
338 }
339}
340
341TEST(L1D, associativity) {
342 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
343 ASSERT_EQ(4, cpuinfo_get_l1d_cache(i)->associativity);
344 }
345}
346
347TEST(L1D, sets) {
348 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
349 ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size,
350 cpuinfo_get_l1d_cache(i)->sets * cpuinfo_get_l1d_cache(i)->line_size * cpuinfo_get_l1d_cache(i)->partitions * cpuinfo_get_l1d_cache(i)->associativity);
351 }
352}
353
354TEST(L1D, partitions) {
355 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
356 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions);
357 }
358}
359
360TEST(L1D, line_size) {
361 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
362 ASSERT_EQ(32, cpuinfo_get_l1d_cache(i)->line_size);
363 }
364}
365
366TEST(L1D, flags) {
367 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
368 ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags);
369 }
370}
371
372TEST(L1D, processors) {
373 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
374 ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start);
375 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count);
376 }
377}
378
379TEST(L2, count) {
380 ASSERT_EQ(1, cpuinfo_get_l2_caches_count());
381}
382
383TEST(L2, non_null) {
384 ASSERT_TRUE(cpuinfo_get_l2_caches());
385}
386
387TEST(L2, size) {
388 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
389 switch (i) {
390 ASSERT_EQ(512 * 1024, cpuinfo_get_l2_cache(i)->size);
391 }
392 }
393}
394
395TEST(L2, associativity) {
396 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
397 ASSERT_EQ(4, cpuinfo_get_l2_cache(i)->associativity);
398 }
399}
400
401TEST(L2, sets) {
402 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
403 ASSERT_EQ(cpuinfo_get_l2_cache(i)->size,
404 cpuinfo_get_l2_cache(i)->sets * cpuinfo_get_l2_cache(i)->line_size * cpuinfo_get_l2_cache(i)->partitions * cpuinfo_get_l2_cache(i)->associativity);
405 }
406}
407
408TEST(L2, partitions) {
409 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
410 ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions);
411 }
412}
413
414TEST(L2, line_size) {
415 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
416 ASSERT_EQ(128, cpuinfo_get_l2_cache(i)->line_size);
417 }
418}
419
420TEST(L2, flags) {
421 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
422 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->flags);
423 }
424}
425
426TEST(L2, processors) {
427 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
428 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->processor_start);
429 ASSERT_EQ(2, cpuinfo_get_l2_cache(i)->processor_count);
430 }
431}
432
433TEST(L3, none) {
434 ASSERT_EQ(0, cpuinfo_get_l3_caches_count());
435 ASSERT_FALSE(cpuinfo_get_l3_caches());
436}
437
438TEST(L4, none) {
439 ASSERT_EQ(0, cpuinfo_get_l4_caches_count());
440 ASSERT_FALSE(cpuinfo_get_l4_caches());
441}
442
443#include <xperia-sl.h>
444
445int main(int argc, char* argv[]) {
446#if CPUINFO_ARCH_ARM
447 cpuinfo_set_hwcap(UINT32_C(0x0000B0D7));
448#endif
449 cpuinfo_mock_filesystem(filesystem);
450#ifdef __ANDROID__
451 cpuinfo_mock_android_properties(properties);
452#endif
453 cpuinfo_initialize();
454 ::testing::InitGoogleTest(&argc, argv);
455 return RUN_ALL_TESTS();
456}