1 #include <gtest/gtest.h>
2
3 #include <cpuinfo.h>
4 #include <cpuinfo-mock.h>
5
6
TEST(PROCESSORS,count)7 TEST(PROCESSORS, count) {
8 ASSERT_EQ(4, cpuinfo_get_processors_count());
9 }
10
TEST(PROCESSORS,non_null)11 TEST(PROCESSORS, non_null) {
12 ASSERT_TRUE(cpuinfo_get_processors());
13 }
14
TEST(PROCESSORS,smt_id)15 TEST(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
TEST(PROCESSORS,core)21 TEST(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
TEST(PROCESSORS,cluster)27 TEST(PROCESSORS, cluster) {
28 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
29 switch (i) {
30 case 0:
31 case 1:
32 ASSERT_EQ(cpuinfo_get_cluster(0), cpuinfo_get_processor(i)->cluster);
33 break;
34 case 2:
35 case 3:
36 ASSERT_EQ(cpuinfo_get_cluster(1), cpuinfo_get_processor(i)->cluster);
37 break;
38 }
39 }
40 }
41
TEST(PROCESSORS,package)42 TEST(PROCESSORS, package) {
43 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
44 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_processor(i)->package);
45 }
46 }
47
TEST(PROCESSORS,linux_id)48 TEST(PROCESSORS, linux_id) {
49 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
50 switch (i) {
51 case 0:
52 case 1:
53 ASSERT_EQ(i + 2, cpuinfo_get_processor(i)->linux_id);
54 break;
55 case 2:
56 case 3:
57 ASSERT_EQ(i - 2, cpuinfo_get_processor(i)->linux_id);
58 break;
59 }
60 }
61 }
62
TEST(PROCESSORS,l1i)63 TEST(PROCESSORS, l1i) {
64 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
65 ASSERT_EQ(cpuinfo_get_l1i_cache(i), cpuinfo_get_processor(i)->cache.l1i);
66 }
67 }
68
TEST(PROCESSORS,l1d)69 TEST(PROCESSORS, l1d) {
70 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
71 ASSERT_EQ(cpuinfo_get_l1d_cache(i), cpuinfo_get_processor(i)->cache.l1d);
72 }
73 }
74
TEST(PROCESSORS,l2)75 TEST(PROCESSORS, l2) {
76 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
77 switch (i) {
78 case 0:
79 case 1:
80 ASSERT_EQ(cpuinfo_get_l2_cache(0), cpuinfo_get_processor(i)->cache.l2);
81 break;
82 case 2:
83 case 3:
84 ASSERT_EQ(cpuinfo_get_l2_cache(1), cpuinfo_get_processor(i)->cache.l2);
85 break;
86 }
87 }
88 }
89
TEST(PROCESSORS,l3)90 TEST(PROCESSORS, l3) {
91 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
92 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l3);
93 }
94 }
95
TEST(PROCESSORS,l4)96 TEST(PROCESSORS, l4) {
97 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
98 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l4);
99 }
100 }
101
TEST(CORES,count)102 TEST(CORES, count) {
103 ASSERT_EQ(4, cpuinfo_get_cores_count());
104 }
105
TEST(CORES,non_null)106 TEST(CORES, non_null) {
107 ASSERT_TRUE(cpuinfo_get_cores());
108 }
109
TEST(CORES,processor_start)110 TEST(CORES, processor_start) {
111 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
112 ASSERT_EQ(i, cpuinfo_get_core(i)->processor_start);
113 }
114 }
115
TEST(CORES,processor_count)116 TEST(CORES, processor_count) {
117 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
118 ASSERT_EQ(1, cpuinfo_get_core(i)->processor_count);
119 }
120 }
121
TEST(CORES,core_id)122 TEST(CORES, core_id) {
123 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
124 ASSERT_EQ(i, cpuinfo_get_core(i)->core_id);
125 }
126 }
127
TEST(CORES,cluster)128 TEST(CORES, cluster) {
129 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
130 switch (i) {
131 case 0:
132 case 1:
133 ASSERT_EQ(cpuinfo_get_cluster(0), cpuinfo_get_core(i)->cluster);
134 break;
135 case 2:
136 case 3:
137 ASSERT_EQ(cpuinfo_get_cluster(1), cpuinfo_get_core(i)->cluster);
138 break;
139 }
140 }
141 }
142
TEST(CORES,package)143 TEST(CORES, package) {
144 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
145 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_core(i)->package);
146 }
147 }
148
TEST(CORES,vendor)149 TEST(CORES, vendor) {
150 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
151 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_core(i)->vendor);
152 }
153 }
154
TEST(CORES,uarch)155 TEST(CORES, uarch) {
156 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
157 ASSERT_EQ(cpuinfo_uarch_kryo, cpuinfo_get_core(i)->uarch);
158 }
159 }
160
TEST(CORES,midr)161 TEST(CORES, midr) {
162 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
163 switch (i) {
164 case 0:
165 case 1:
166 ASSERT_EQ(UINT32_C(0x512F2051), cpuinfo_get_core(i)->midr);
167 break;
168 case 2:
169 case 3:
170 ASSERT_EQ(UINT32_C(0x512F2011), cpuinfo_get_core(i)->midr);
171 break;
172 }
173 }
174 }
175
TEST(CORES,DISABLED_frequency)176 TEST(CORES, DISABLED_frequency) {
177 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
178 switch (i) {
179 case 0:
180 case 1:
181 ASSERT_EQ(UINT64_C(2150400000), cpuinfo_get_core(i)->frequency);
182 break;
183 case 2:
184 case 3:
185 ASSERT_EQ(UINT64_C(1593600000), cpuinfo_get_core(i)->frequency);
186 break;
187 }
188 }
189 }
190
TEST(CLUSTERS,count)191 TEST(CLUSTERS, count) {
192 ASSERT_EQ(2, cpuinfo_get_clusters_count());
193 }
194
TEST(CLUSTERS,non_null)195 TEST(CLUSTERS, non_null) {
196 ASSERT_TRUE(cpuinfo_get_clusters());
197 }
198
TEST(CLUSTERS,processor_start)199 TEST(CLUSTERS, processor_start) {
200 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
201 switch (i) {
202 case 0:
203 ASSERT_EQ(0, cpuinfo_get_cluster(i)->processor_start);
204 break;
205 case 1:
206 ASSERT_EQ(2, cpuinfo_get_cluster(i)->processor_start);
207 break;
208 }
209 }
210 }
211
TEST(CLUSTERS,processor_count)212 TEST(CLUSTERS, processor_count) {
213 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
214 ASSERT_EQ(2, cpuinfo_get_cluster(i)->processor_count);
215 }
216 }
217
TEST(CLUSTERS,core_start)218 TEST(CLUSTERS, core_start) {
219 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
220 switch (i) {
221 case 0:
222 ASSERT_EQ(0, cpuinfo_get_cluster(i)->core_start);
223 break;
224 case 1:
225 ASSERT_EQ(2, cpuinfo_get_cluster(i)->core_start);
226 break;
227 }
228 }
229 }
230
TEST(CLUSTERS,core_count)231 TEST(CLUSTERS, core_count) {
232 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
233 ASSERT_EQ(2, cpuinfo_get_cluster(i)->core_count);
234 }
235 }
236
TEST(CLUSTERS,cluster_id)237 TEST(CLUSTERS, cluster_id) {
238 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
239 ASSERT_EQ(i, cpuinfo_get_cluster(i)->cluster_id);
240 }
241 }
242
TEST(CLUSTERS,package)243 TEST(CLUSTERS, package) {
244 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
245 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_cluster(i)->package);
246 }
247 }
248
TEST(CLUSTERS,vendor)249 TEST(CLUSTERS, vendor) {
250 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
251 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_cluster(i)->vendor);
252 }
253 }
254
TEST(CLUSTERS,uarch)255 TEST(CLUSTERS, uarch) {
256 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
257 ASSERT_EQ(cpuinfo_uarch_kryo, cpuinfo_get_cluster(i)->uarch);
258 }
259 }
260
TEST(CLUSTERS,midr)261 TEST(CLUSTERS, midr) {
262 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
263 switch (i) {
264 case 0:
265 ASSERT_EQ(UINT32_C(0x512F2051), cpuinfo_get_cluster(i)->midr);
266 break;
267 case 1:
268 ASSERT_EQ(UINT32_C(0x512F2011), cpuinfo_get_cluster(i)->midr);
269 break;
270 }
271 }
272 }
273
TEST(CLUSTERS,DISABLED_frequency)274 TEST(CLUSTERS, DISABLED_frequency) {
275 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
276 switch (i) {
277 case 0:
278 ASSERT_EQ(UINT64_C(2150400000), cpuinfo_get_cluster(i)->frequency);
279 break;
280 case 1:
281 ASSERT_EQ(UINT64_C(1593600000), cpuinfo_get_cluster(i)->frequency);
282 break;
283 }
284 }
285 }
286
TEST(PACKAGES,count)287 TEST(PACKAGES, count) {
288 ASSERT_EQ(1, cpuinfo_get_packages_count());
289 }
290
TEST(PACKAGES,name)291 TEST(PACKAGES, name) {
292 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
293 ASSERT_EQ("Qualcomm MSM8996PRO-AB",
294 std::string(cpuinfo_get_package(i)->name,
295 strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX)));
296 }
297 }
298
TEST(PACKAGES,processor_start)299 TEST(PACKAGES, processor_start) {
300 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
301 ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start);
302 }
303 }
304
TEST(PACKAGES,processor_count)305 TEST(PACKAGES, processor_count) {
306 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
307 ASSERT_EQ(4, cpuinfo_get_package(i)->processor_count);
308 }
309 }
310
TEST(PACKAGES,core_start)311 TEST(PACKAGES, core_start) {
312 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
313 ASSERT_EQ(0, cpuinfo_get_package(i)->core_start);
314 }
315 }
316
TEST(PACKAGES,core_count)317 TEST(PACKAGES, core_count) {
318 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
319 ASSERT_EQ(4, cpuinfo_get_package(i)->core_count);
320 }
321 }
322
TEST(PACKAGES,cluster_start)323 TEST(PACKAGES, cluster_start) {
324 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
325 ASSERT_EQ(0, cpuinfo_get_package(i)->cluster_start);
326 }
327 }
328
TEST(PACKAGES,cluster_count)329 TEST(PACKAGES, cluster_count) {
330 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
331 ASSERT_EQ(2, cpuinfo_get_package(i)->cluster_count);
332 }
333 }
334
TEST(ISA,thumb)335 TEST(ISA, thumb) {
336 #if CPUINFO_ARCH_ARM
337 ASSERT_TRUE(cpuinfo_has_arm_thumb());
338 #elif CPUINFO_ARCH_ARM64
339 ASSERT_FALSE(cpuinfo_has_arm_thumb());
340 #endif
341 }
342
TEST(ISA,thumb2)343 TEST(ISA, thumb2) {
344 #if CPUINFO_ARCH_ARM
345 ASSERT_TRUE(cpuinfo_has_arm_thumb2());
346 #elif CPUINFO_ARCH_ARM64
347 ASSERT_FALSE(cpuinfo_has_arm_thumb2());
348 #endif
349 }
350
TEST(ISA,armv5e)351 TEST(ISA, armv5e) {
352 #if CPUINFO_ARCH_ARM
353 ASSERT_TRUE(cpuinfo_has_arm_v5e());
354 #elif CPUINFO_ARCH_ARM64
355 ASSERT_FALSE(cpuinfo_has_arm_v5e());
356 #endif
357 }
358
TEST(ISA,armv6)359 TEST(ISA, armv6) {
360 #if CPUINFO_ARCH_ARM
361 ASSERT_TRUE(cpuinfo_has_arm_v6());
362 #elif CPUINFO_ARCH_ARM64
363 ASSERT_FALSE(cpuinfo_has_arm_v6());
364 #endif
365 }
366
TEST(ISA,armv6k)367 TEST(ISA, armv6k) {
368 #if CPUINFO_ARCH_ARM
369 ASSERT_TRUE(cpuinfo_has_arm_v6k());
370 #elif CPUINFO_ARCH_ARM64
371 ASSERT_FALSE(cpuinfo_has_arm_v6k());
372 #endif
373 }
374
TEST(ISA,armv7)375 TEST(ISA, armv7) {
376 #if CPUINFO_ARCH_ARM
377 ASSERT_TRUE(cpuinfo_has_arm_v7());
378 #elif CPUINFO_ARCH_ARM64
379 ASSERT_FALSE(cpuinfo_has_arm_v7());
380 #endif
381 }
382
TEST(ISA,armv7mp)383 TEST(ISA, armv7mp) {
384 #if CPUINFO_ARCH_ARM
385 ASSERT_TRUE(cpuinfo_has_arm_v7mp());
386 #elif CPUINFO_ARCH_ARM64
387 ASSERT_FALSE(cpuinfo_has_arm_v7mp());
388 #endif
389 }
390
TEST(ISA,idiv)391 TEST(ISA, idiv) {
392 ASSERT_TRUE(cpuinfo_has_arm_idiv());
393 }
394
TEST(ISA,vfpv2)395 TEST(ISA, vfpv2) {
396 ASSERT_FALSE(cpuinfo_has_arm_vfpv2());
397 }
398
TEST(ISA,vfpv3)399 TEST(ISA, vfpv3) {
400 ASSERT_TRUE(cpuinfo_has_arm_vfpv3());
401 }
402
TEST(ISA,vfpv3_d32)403 TEST(ISA, vfpv3_d32) {
404 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_d32());
405 }
406
TEST(ISA,vfpv3_fp16)407 TEST(ISA, vfpv3_fp16) {
408 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16());
409 }
410
TEST(ISA,vfpv3_fp16_d32)411 TEST(ISA, vfpv3_fp16_d32) {
412 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16_d32());
413 }
414
TEST(ISA,vfpv4)415 TEST(ISA, vfpv4) {
416 ASSERT_TRUE(cpuinfo_has_arm_vfpv4());
417 }
418
TEST(ISA,vfpv4_d32)419 TEST(ISA, vfpv4_d32) {
420 ASSERT_TRUE(cpuinfo_has_arm_vfpv4_d32());
421 }
422
TEST(ISA,wmmx)423 TEST(ISA, wmmx) {
424 ASSERT_FALSE(cpuinfo_has_arm_wmmx());
425 }
426
TEST(ISA,wmmx2)427 TEST(ISA, wmmx2) {
428 ASSERT_FALSE(cpuinfo_has_arm_wmmx2());
429 }
430
TEST(ISA,neon)431 TEST(ISA, neon) {
432 ASSERT_TRUE(cpuinfo_has_arm_neon());
433 }
434
TEST(ISA,neon_fp16)435 TEST(ISA, neon_fp16) {
436 ASSERT_TRUE(cpuinfo_has_arm_neon_fp16());
437 }
438
TEST(ISA,neon_fma)439 TEST(ISA, neon_fma) {
440 ASSERT_TRUE(cpuinfo_has_arm_neon_fma());
441 }
442
TEST(ISA,atomics)443 TEST(ISA, atomics) {
444 ASSERT_FALSE(cpuinfo_has_arm_atomics());
445 }
446
TEST(ISA,neon_rdm)447 TEST(ISA, neon_rdm) {
448 ASSERT_FALSE(cpuinfo_has_arm_neon_rdm());
449 }
450
TEST(ISA,fp16_arith)451 TEST(ISA, fp16_arith) {
452 ASSERT_FALSE(cpuinfo_has_arm_fp16_arith());
453 }
454
TEST(ISA,neon_fp16_arith)455 TEST(ISA, neon_fp16_arith) {
456 ASSERT_FALSE(cpuinfo_has_arm_neon_fp16_arith());
457 }
458
TEST(ISA,neon_dot)459 TEST(ISA, neon_dot) {
460 ASSERT_FALSE(cpuinfo_has_arm_neon_dot());
461 }
462
TEST(ISA,jscvt)463 TEST(ISA, jscvt) {
464 ASSERT_FALSE(cpuinfo_has_arm_jscvt());
465 }
466
TEST(ISA,fcma)467 TEST(ISA, fcma) {
468 ASSERT_FALSE(cpuinfo_has_arm_fcma());
469 }
470
TEST(ISA,aes)471 TEST(ISA, aes) {
472 ASSERT_TRUE(cpuinfo_has_arm_aes());
473 }
474
TEST(ISA,sha1)475 TEST(ISA, sha1) {
476 ASSERT_TRUE(cpuinfo_has_arm_sha1());
477 }
478
TEST(ISA,sha2)479 TEST(ISA, sha2) {
480 ASSERT_TRUE(cpuinfo_has_arm_sha2());
481 }
482
TEST(ISA,pmull)483 TEST(ISA, pmull) {
484 ASSERT_TRUE(cpuinfo_has_arm_pmull());
485 }
486
TEST(ISA,crc32)487 TEST(ISA, crc32) {
488 ASSERT_TRUE(cpuinfo_has_arm_crc32());
489 }
490
TEST(L1I,count)491 TEST(L1I, count) {
492 ASSERT_EQ(4, cpuinfo_get_l1i_caches_count());
493 }
494
TEST(L1I,non_null)495 TEST(L1I, non_null) {
496 ASSERT_TRUE(cpuinfo_get_l1i_caches());
497 }
498
TEST(L1I,size)499 TEST(L1I, size) {
500 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
501 ASSERT_EQ(32 * 1024, cpuinfo_get_l1i_cache(i)->size);
502 }
503 }
504
TEST(L1I,associativity)505 TEST(L1I, associativity) {
506 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
507 ASSERT_EQ(4, cpuinfo_get_l1i_cache(i)->associativity);
508 }
509 }
510
TEST(L1I,sets)511 TEST(L1I, sets) {
512 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
513 ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size,
514 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);
515 }
516 }
517
TEST(L1I,partitions)518 TEST(L1I, partitions) {
519 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
520 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions);
521 }
522 }
523
TEST(L1I,line_size)524 TEST(L1I, line_size) {
525 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
526 ASSERT_EQ(64, cpuinfo_get_l1i_cache(i)->line_size);
527 }
528 }
529
TEST(L1I,flags)530 TEST(L1I, flags) {
531 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
532 ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags);
533 }
534 }
535
TEST(L1I,processors)536 TEST(L1I, processors) {
537 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
538 ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start);
539 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count);
540 }
541 }
542
TEST(L1D,count)543 TEST(L1D, count) {
544 ASSERT_EQ(4, cpuinfo_get_l1d_caches_count());
545 }
546
TEST(L1D,non_null)547 TEST(L1D, non_null) {
548 ASSERT_TRUE(cpuinfo_get_l1d_caches());
549 }
550
TEST(L1D,size)551 TEST(L1D, size) {
552 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
553 ASSERT_EQ(24 * 1024, cpuinfo_get_l1d_cache(i)->size);
554 }
555 }
556
TEST(L1D,associativity)557 TEST(L1D, associativity) {
558 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
559 ASSERT_EQ(3, cpuinfo_get_l1d_cache(i)->associativity);
560 }
561 }
562
TEST(L1D,sets)563 TEST(L1D, sets) {
564 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
565 ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size,
566 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);
567 }
568 }
569
TEST(L1D,partitions)570 TEST(L1D, partitions) {
571 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
572 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions);
573 }
574 }
575
TEST(L1D,line_size)576 TEST(L1D, line_size) {
577 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
578 ASSERT_EQ(64, cpuinfo_get_l1d_cache(i)->line_size);
579 }
580 }
581
TEST(L1D,flags)582 TEST(L1D, flags) {
583 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
584 ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags);
585 }
586 }
587
TEST(L1D,processors)588 TEST(L1D, processors) {
589 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
590 ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start);
591 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count);
592 }
593 }
594
TEST(L2,count)595 TEST(L2, count) {
596 ASSERT_EQ(2, cpuinfo_get_l2_caches_count());
597 }
598
TEST(L2,non_null)599 TEST(L2, non_null) {
600 ASSERT_TRUE(cpuinfo_get_l2_caches());
601 }
602
TEST(L2,size)603 TEST(L2, size) {
604 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
605 switch (i) {
606 case 0:
607 ASSERT_EQ(1 * 1024 * 1024, cpuinfo_get_l2_cache(i)->size);
608 break;
609 case 1:
610 ASSERT_EQ(512 * 1024, cpuinfo_get_l2_cache(i)->size);
611 break;
612 }
613 }
614 }
615
TEST(L2,associativity)616 TEST(L2, associativity) {
617 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
618 ASSERT_EQ(8, cpuinfo_get_l2_cache(i)->associativity);
619 }
620 }
621
TEST(L2,sets)622 TEST(L2, sets) {
623 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
624 ASSERT_EQ(cpuinfo_get_l2_cache(i)->size,
625 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);
626 }
627 }
628
TEST(L2,partitions)629 TEST(L2, partitions) {
630 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
631 ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions);
632 }
633 }
634
TEST(L2,line_size)635 TEST(L2, line_size) {
636 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
637 ASSERT_EQ(128, cpuinfo_get_l2_cache(i)->line_size);
638 }
639 }
640
TEST(L2,flags)641 TEST(L2, flags) {
642 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
643 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->flags);
644 }
645 }
646
TEST(L2,processors)647 TEST(L2, processors) {
648 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
649 switch (i) {
650 case 0:
651 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->processor_start);
652 ASSERT_EQ(2, cpuinfo_get_l2_cache(i)->processor_count);
653 break;
654 case 1:
655 ASSERT_EQ(2, cpuinfo_get_l2_cache(i)->processor_start);
656 ASSERT_EQ(2, cpuinfo_get_l2_cache(i)->processor_count);
657 break;
658 }
659 }
660 }
661
TEST(L3,none)662 TEST(L3, none) {
663 ASSERT_EQ(0, cpuinfo_get_l3_caches_count());
664 ASSERT_FALSE(cpuinfo_get_l3_caches());
665 }
666
TEST(L4,none)667 TEST(L4, none) {
668 ASSERT_EQ(0, cpuinfo_get_l4_caches_count());
669 ASSERT_FALSE(cpuinfo_get_l4_caches());
670 }
671
672 #include <pixel-xl.h>
673
main(int argc,char * argv[])674 int main(int argc, char* argv[]) {
675 #if CPUINFO_ARCH_ARM
676 cpuinfo_set_hwcap(UINT32_C(0x0037B0D6));
677 cpuinfo_set_hwcap2(UINT32_C(0x0000001F));
678 #elif CPUINFO_ARCH_ARM64
679 cpuinfo_set_hwcap(UINT32_C(0x000000FF));
680 #endif
681 cpuinfo_mock_filesystem(filesystem);
682 #ifdef __ANDROID__
683 cpuinfo_mock_android_properties(properties);
684 #endif
685 cpuinfo_initialize();
686 ::testing::InitGoogleTest(&argc, argv);
687 return RUN_ALL_TESTS();
688 }