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