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(8, 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 ASSERT_EQ(cpuinfo_get_cluster(i / 4), cpuinfo_get_processor(i)->cluster);
30 }
31 }
32
TEST(PROCESSORS,package)33 TEST(PROCESSORS, package) {
34 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
35 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_processor(i)->package);
36 }
37 }
38
TEST(PROCESSORS,linux_id)39 TEST(PROCESSORS, linux_id) {
40 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
41 ASSERT_EQ(i, cpuinfo_get_processor(i)->linux_id);
42 }
43 }
44
TEST(PROCESSORS,l1i)45 TEST(PROCESSORS, l1i) {
46 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
47 ASSERT_EQ(cpuinfo_get_l1i_cache(i), cpuinfo_get_processor(i)->cache.l1i);
48 }
49 }
50
TEST(PROCESSORS,l1d)51 TEST(PROCESSORS, l1d) {
52 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
53 ASSERT_EQ(cpuinfo_get_l1d_cache(i), cpuinfo_get_processor(i)->cache.l1d);
54 }
55 }
56
TEST(PROCESSORS,l2)57 TEST(PROCESSORS, l2) {
58 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
59 ASSERT_EQ(cpuinfo_get_l2_cache(i / 4), cpuinfo_get_processor(i)->cache.l2);
60 }
61 }
62
TEST(PROCESSORS,l3)63 TEST(PROCESSORS, l3) {
64 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
65 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l3);
66 }
67 }
68
TEST(PROCESSORS,l4)69 TEST(PROCESSORS, l4) {
70 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) {
71 ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l4);
72 }
73 }
74
TEST(CORES,count)75 TEST(CORES, count) {
76 ASSERT_EQ(8, cpuinfo_get_cores_count());
77 }
78
TEST(CORES,non_null)79 TEST(CORES, non_null) {
80 ASSERT_TRUE(cpuinfo_get_cores());
81 }
82
TEST(CORES,processor_start)83 TEST(CORES, processor_start) {
84 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
85 ASSERT_EQ(i, cpuinfo_get_core(i)->processor_start);
86 }
87 }
88
TEST(CORES,processor_count)89 TEST(CORES, processor_count) {
90 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
91 ASSERT_EQ(1, cpuinfo_get_core(i)->processor_count);
92 }
93 }
94
TEST(CORES,core_id)95 TEST(CORES, core_id) {
96 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
97 ASSERT_EQ(i, cpuinfo_get_core(i)->core_id);
98 }
99 }
100
TEST(CORES,cluster)101 TEST(CORES, cluster) {
102 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
103 ASSERT_EQ(cpuinfo_get_cluster(i / 4), cpuinfo_get_core(i)->cluster);
104 }
105 }
106
TEST(CORES,package)107 TEST(CORES, package) {
108 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
109 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_core(i)->package);
110 }
111 }
112
TEST(CORES,vendor)113 TEST(CORES, vendor) {
114 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
115 ASSERT_EQ(cpuinfo_vendor_intel, cpuinfo_get_core(i)->vendor);
116 }
117 }
118
TEST(CORES,uarch)119 TEST(CORES, uarch) {
120 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
121 ASSERT_EQ(cpuinfo_uarch_airmont, cpuinfo_get_core(i)->uarch);
122 }
123 }
124
TEST(CORES,cpuid)125 TEST(CORES, cpuid) {
126 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
127 ASSERT_EQ(UINT32_C(0x0007065A), cpuinfo_get_core(i)->cpuid);
128 }
129 }
130
TEST(CORES,DISABLED_frequency)131 TEST(CORES, DISABLED_frequency) {
132 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) {
133 ASSERT_EQ(UINT64_C(1872000000), cpuinfo_get_core(i)->frequency);
134 }
135 }
136
TEST(CLUSTERS,count)137 TEST(CLUSTERS, count) {
138 ASSERT_EQ(2, cpuinfo_get_clusters_count());
139 }
140
TEST(CLUSTERS,non_null)141 TEST(CLUSTERS, non_null) {
142 ASSERT_TRUE(cpuinfo_get_clusters());
143 }
144
TEST(CLUSTERS,processor_start)145 TEST(CLUSTERS, processor_start) {
146 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
147 ASSERT_EQ(i * 4, cpuinfo_get_cluster(i)->processor_start);
148 }
149 }
150
TEST(CLUSTERS,processor_count)151 TEST(CLUSTERS, processor_count) {
152 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
153 ASSERT_EQ(4, cpuinfo_get_cluster(i)->processor_count);
154 }
155 }
156
TEST(CLUSTERS,core_start)157 TEST(CLUSTERS, core_start) {
158 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
159 ASSERT_EQ(i * 4, cpuinfo_get_cluster(i)->core_start);
160 }
161 }
162
TEST(CLUSTERS,core_count)163 TEST(CLUSTERS, core_count) {
164 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
165 ASSERT_EQ(4, cpuinfo_get_cluster(i)->core_count);
166 }
167 }
168
TEST(CLUSTERS,cluster_id)169 TEST(CLUSTERS, cluster_id) {
170 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
171 ASSERT_EQ(i, cpuinfo_get_cluster(i)->cluster_id);
172 }
173 }
174
TEST(CLUSTERS,package)175 TEST(CLUSTERS, package) {
176 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
177 ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_cluster(i)->package);
178 }
179 }
180
TEST(CLUSTERS,vendor)181 TEST(CLUSTERS, vendor) {
182 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
183 ASSERT_EQ(cpuinfo_vendor_intel, cpuinfo_get_cluster(i)->vendor);
184 }
185 }
186
TEST(CLUSTERS,uarch)187 TEST(CLUSTERS, uarch) {
188 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
189 ASSERT_EQ(cpuinfo_uarch_airmont, cpuinfo_get_cluster(i)->uarch);
190 }
191 }
192
TEST(CLUSTERS,cpuid)193 TEST(CLUSTERS, cpuid) {
194 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
195 ASSERT_EQ(UINT32_C(0x0007065A), cpuinfo_get_cluster(i)->cpuid);
196 }
197 }
198
TEST(CLUSTERS,DISABLED_frequency)199 TEST(CLUSTERS, DISABLED_frequency) {
200 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) {
201 ASSERT_EQ(UINT64_C(1872000000), cpuinfo_get_cluster(i)->frequency);
202 }
203 }
204
TEST(PACKAGES,count)205 TEST(PACKAGES, count) {
206 ASSERT_EQ(1, cpuinfo_get_packages_count());
207 }
208
TEST(PACKAGES,non_null)209 TEST(PACKAGES, non_null) {
210 ASSERT_TRUE(cpuinfo_get_packages());
211 }
212
TEST(PACKAGES,DISABLED_name)213 TEST(PACKAGES, DISABLED_name) {
214 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
215 ASSERT_EQ("Spreadtrum SC9853I-IA",
216 std::string(cpuinfo_get_package(i)->name,
217 strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX)));
218 }
219 }
220
TEST(PACKAGES,processor_start)221 TEST(PACKAGES, processor_start) {
222 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
223 ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start);
224 }
225 }
226
TEST(PACKAGES,processor_count)227 TEST(PACKAGES, processor_count) {
228 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
229 ASSERT_EQ(8, cpuinfo_get_package(i)->processor_count);
230 }
231 }
232
TEST(PACKAGES,core_start)233 TEST(PACKAGES, core_start) {
234 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
235 ASSERT_EQ(0, cpuinfo_get_package(i)->core_start);
236 }
237 }
238
TEST(PACKAGES,core_count)239 TEST(PACKAGES, core_count) {
240 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
241 ASSERT_EQ(8, cpuinfo_get_package(i)->core_count);
242 }
243 }
244
TEST(PACKAGES,cluster_start)245 TEST(PACKAGES, cluster_start) {
246 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
247 ASSERT_EQ(0, cpuinfo_get_package(i)->cluster_start);
248 }
249 }
250
TEST(PACKAGES,cluster_count)251 TEST(PACKAGES, cluster_count) {
252 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) {
253 ASSERT_EQ(2, cpuinfo_get_package(i)->cluster_count);
254 }
255 }
256
TEST(ISA,rdtsc)257 TEST(ISA, rdtsc) {
258 ASSERT_TRUE(cpuinfo_has_x86_rdtsc());
259 }
260
TEST(ISA,rdtscp)261 TEST(ISA, rdtscp) {
262 ASSERT_TRUE(cpuinfo_has_x86_rdtscp());
263 }
264
TEST(ISA,rdpid)265 TEST(ISA, rdpid) {
266 ASSERT_FALSE(cpuinfo_has_x86_rdpid());
267 }
268
TEST(ISA,clzero)269 TEST(ISA, clzero) {
270 ASSERT_FALSE(cpuinfo_has_x86_clzero());
271 }
272
TEST(ISA,mwait)273 TEST(ISA, mwait) {
274 ASSERT_TRUE(cpuinfo_has_x86_mwait());
275 }
276
TEST(ISA,mwaitx)277 TEST(ISA, mwaitx) {
278 ASSERT_FALSE(cpuinfo_has_x86_mwaitx());
279 }
280
TEST(ISA,fxsave)281 TEST(ISA, fxsave) {
282 ASSERT_TRUE(cpuinfo_has_x86_fxsave());
283 }
284
TEST(ISA,xsave)285 TEST(ISA, xsave) {
286 ASSERT_FALSE(cpuinfo_has_x86_xsave());
287 }
288
TEST(ISA,fpu)289 TEST(ISA, fpu) {
290 ASSERT_TRUE(cpuinfo_has_x86_fpu());
291 }
292
TEST(ISA,mmx)293 TEST(ISA, mmx) {
294 ASSERT_TRUE(cpuinfo_has_x86_mmx());
295 }
296
TEST(ISA,mmx_plus)297 TEST(ISA, mmx_plus) {
298 ASSERT_TRUE(cpuinfo_has_x86_mmx_plus());
299 }
300
TEST(ISA,three_d_now)301 TEST(ISA, three_d_now) {
302 ASSERT_FALSE(cpuinfo_has_x86_3dnow());
303 }
304
TEST(ISA,three_d_now_plus)305 TEST(ISA, three_d_now_plus) {
306 ASSERT_FALSE(cpuinfo_has_x86_3dnow_plus());
307 }
308
TEST(ISA,three_d_now_geode)309 TEST(ISA, three_d_now_geode) {
310 ASSERT_FALSE(cpuinfo_has_x86_3dnow_geode());
311 }
312
TEST(ISA,prefetch)313 TEST(ISA, prefetch) {
314 ASSERT_FALSE(cpuinfo_has_x86_prefetch());
315 }
316
TEST(ISA,prefetchw)317 TEST(ISA, prefetchw) {
318 ASSERT_TRUE(cpuinfo_has_x86_prefetchw());
319 }
320
TEST(ISA,prefetchwt1)321 TEST(ISA, prefetchwt1) {
322 ASSERT_FALSE(cpuinfo_has_x86_prefetchwt1());
323 }
324
TEST(ISA,daz)325 TEST(ISA, daz) {
326 ASSERT_TRUE(cpuinfo_has_x86_daz());
327 }
328
TEST(ISA,sse)329 TEST(ISA, sse) {
330 ASSERT_TRUE(cpuinfo_has_x86_sse());
331 }
332
TEST(ISA,sse2)333 TEST(ISA, sse2) {
334 ASSERT_TRUE(cpuinfo_has_x86_sse2());
335 }
336
TEST(ISA,sse3)337 TEST(ISA, sse3) {
338 ASSERT_TRUE(cpuinfo_has_x86_sse3());
339 }
340
TEST(ISA,ssse3)341 TEST(ISA, ssse3) {
342 ASSERT_TRUE(cpuinfo_has_x86_ssse3());
343 }
344
TEST(ISA,sse4_1)345 TEST(ISA, sse4_1) {
346 ASSERT_TRUE(cpuinfo_has_x86_sse4_1());
347 }
348
TEST(ISA,sse4_2)349 TEST(ISA, sse4_2) {
350 ASSERT_TRUE(cpuinfo_has_x86_sse4_2());
351 }
352
TEST(ISA,sse4a)353 TEST(ISA, sse4a) {
354 ASSERT_FALSE(cpuinfo_has_x86_sse4a());
355 }
356
TEST(ISA,misaligned_sse)357 TEST(ISA, misaligned_sse) {
358 ASSERT_FALSE(cpuinfo_has_x86_misaligned_sse());
359 }
360
TEST(ISA,avx)361 TEST(ISA, avx) {
362 ASSERT_FALSE(cpuinfo_has_x86_avx());
363 }
364
TEST(ISA,fma3)365 TEST(ISA, fma3) {
366 ASSERT_FALSE(cpuinfo_has_x86_fma3());
367 }
368
TEST(ISA,fma4)369 TEST(ISA, fma4) {
370 ASSERT_FALSE(cpuinfo_has_x86_fma4());
371 }
372
TEST(ISA,xop)373 TEST(ISA, xop) {
374 ASSERT_FALSE(cpuinfo_has_x86_xop());
375 }
376
TEST(ISA,f16c)377 TEST(ISA, f16c) {
378 ASSERT_FALSE(cpuinfo_has_x86_f16c());
379 }
380
TEST(ISA,avx2)381 TEST(ISA, avx2) {
382 ASSERT_FALSE(cpuinfo_has_x86_avx2());
383 }
384
TEST(ISA,avx512f)385 TEST(ISA, avx512f) {
386 ASSERT_FALSE(cpuinfo_has_x86_avx512f());
387 }
388
TEST(ISA,avx512pf)389 TEST(ISA, avx512pf) {
390 ASSERT_FALSE(cpuinfo_has_x86_avx512pf());
391 }
392
TEST(ISA,avx512er)393 TEST(ISA, avx512er) {
394 ASSERT_FALSE(cpuinfo_has_x86_avx512er());
395 }
396
TEST(ISA,avx512cd)397 TEST(ISA, avx512cd) {
398 ASSERT_FALSE(cpuinfo_has_x86_avx512cd());
399 }
400
TEST(ISA,avx512dq)401 TEST(ISA, avx512dq) {
402 ASSERT_FALSE(cpuinfo_has_x86_avx512dq());
403 }
404
TEST(ISA,avx512bw)405 TEST(ISA, avx512bw) {
406 ASSERT_FALSE(cpuinfo_has_x86_avx512bw());
407 }
408
TEST(ISA,avx512vl)409 TEST(ISA, avx512vl) {
410 ASSERT_FALSE(cpuinfo_has_x86_avx512vl());
411 }
412
TEST(ISA,avx512ifma)413 TEST(ISA, avx512ifma) {
414 ASSERT_FALSE(cpuinfo_has_x86_avx512ifma());
415 }
416
TEST(ISA,avx512vbmi)417 TEST(ISA, avx512vbmi) {
418 ASSERT_FALSE(cpuinfo_has_x86_avx512vbmi());
419 }
420
TEST(ISA,avx512vpopcntdq)421 TEST(ISA, avx512vpopcntdq) {
422 ASSERT_FALSE(cpuinfo_has_x86_avx512vpopcntdq());
423 }
424
TEST(ISA,avx512_4vnniw)425 TEST(ISA, avx512_4vnniw) {
426 ASSERT_FALSE(cpuinfo_has_x86_avx512_4vnniw());
427 }
428
TEST(ISA,avx512_4fmaps)429 TEST(ISA, avx512_4fmaps) {
430 ASSERT_FALSE(cpuinfo_has_x86_avx512_4fmaps());
431 }
432
TEST(ISA,hle)433 TEST(ISA, hle) {
434 ASSERT_FALSE(cpuinfo_has_x86_hle());
435 }
436
TEST(ISA,rtm)437 TEST(ISA, rtm) {
438 ASSERT_FALSE(cpuinfo_has_x86_rtm());
439 }
440
TEST(ISA,xtest)441 TEST(ISA, xtest) {
442 ASSERT_FALSE(cpuinfo_has_x86_xtest());
443 }
444
TEST(ISA,mpx)445 TEST(ISA, mpx) {
446 ASSERT_FALSE(cpuinfo_has_x86_mpx());
447 }
448
TEST(ISA,cmov)449 TEST(ISA, cmov) {
450 ASSERT_TRUE(cpuinfo_has_x86_cmov());
451 }
452
TEST(ISA,cmpxchg8b)453 TEST(ISA, cmpxchg8b) {
454 ASSERT_TRUE(cpuinfo_has_x86_cmpxchg8b());
455 }
456
TEST(ISA,cmpxchg16b)457 TEST(ISA, cmpxchg16b) {
458 ASSERT_FALSE(cpuinfo_has_x86_cmpxchg16b());
459 }
460
TEST(ISA,clwb)461 TEST(ISA, clwb) {
462 ASSERT_FALSE(cpuinfo_has_x86_clwb());
463 }
464
TEST(ISA,movbe)465 TEST(ISA, movbe) {
466 ASSERT_TRUE(cpuinfo_has_x86_movbe());
467 }
468
TEST(ISA,lahf_sahf)469 TEST(ISA, lahf_sahf) {
470 ASSERT_TRUE(cpuinfo_has_x86_lahf_sahf());
471 }
472
TEST(ISA,lzcnt)473 TEST(ISA, lzcnt) {
474 ASSERT_FALSE(cpuinfo_has_x86_lzcnt());
475 }
476
TEST(ISA,popcnt)477 TEST(ISA, popcnt) {
478 ASSERT_TRUE(cpuinfo_has_x86_popcnt());
479 }
480
TEST(ISA,tbm)481 TEST(ISA, tbm) {
482 ASSERT_FALSE(cpuinfo_has_x86_tbm());
483 }
484
TEST(ISA,bmi)485 TEST(ISA, bmi) {
486 ASSERT_FALSE(cpuinfo_has_x86_bmi());
487 }
488
TEST(ISA,bmi2)489 TEST(ISA, bmi2) {
490 ASSERT_FALSE(cpuinfo_has_x86_bmi2());
491 }
492
TEST(ISA,adx)493 TEST(ISA, adx) {
494 ASSERT_FALSE(cpuinfo_has_x86_adx());
495 }
496
TEST(ISA,aes)497 TEST(ISA, aes) {
498 ASSERT_TRUE(cpuinfo_has_x86_aes());
499 }
500
TEST(ISA,pclmulqdq)501 TEST(ISA, pclmulqdq) {
502 ASSERT_TRUE(cpuinfo_has_x86_pclmulqdq());
503 }
504
TEST(ISA,rdrand)505 TEST(ISA, rdrand) {
506 ASSERT_FALSE(cpuinfo_has_x86_rdrand());
507 }
508
TEST(ISA,rdseed)509 TEST(ISA, rdseed) {
510 ASSERT_FALSE(cpuinfo_has_x86_rdseed());
511 }
512
TEST(ISA,sha)513 TEST(ISA, sha) {
514 ASSERT_FALSE(cpuinfo_has_x86_sha());
515 }
516
TEST(L1I,count)517 TEST(L1I, count) {
518 ASSERT_EQ(8, cpuinfo_get_l1i_caches_count());
519 }
520
TEST(L1I,non_null)521 TEST(L1I, non_null) {
522 ASSERT_TRUE(cpuinfo_get_l1i_caches());
523 }
524
TEST(L1I,size)525 TEST(L1I, size) {
526 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
527 ASSERT_EQ(32 * 1024, cpuinfo_get_l1i_cache(i)->size);
528 }
529 }
530
TEST(L1I,associativity)531 TEST(L1I, associativity) {
532 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
533 ASSERT_EQ(8, cpuinfo_get_l1i_cache(i)->associativity);
534 }
535 }
536
TEST(L1I,sets)537 TEST(L1I, sets) {
538 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
539 ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size,
540 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);
541 }
542 }
543
TEST(L1I,partitions)544 TEST(L1I, partitions) {
545 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
546 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions);
547 }
548 }
549
TEST(L1I,line_size)550 TEST(L1I, line_size) {
551 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
552 ASSERT_EQ(64, cpuinfo_get_l1i_cache(i)->line_size);
553 }
554 }
555
TEST(L1I,flags)556 TEST(L1I, flags) {
557 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
558 ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags);
559 }
560 }
561
TEST(L1I,processors)562 TEST(L1I, processors) {
563 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) {
564 ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start);
565 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count);
566 }
567 }
568
TEST(L1D,count)569 TEST(L1D, count) {
570 ASSERT_EQ(8, cpuinfo_get_l1d_caches_count());
571 }
572
TEST(L1D,non_null)573 TEST(L1D, non_null) {
574 ASSERT_TRUE(cpuinfo_get_l1d_caches());
575 }
576
TEST(L1D,size)577 TEST(L1D, size) {
578 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
579 ASSERT_EQ(16 * 1024, cpuinfo_get_l1d_cache(i)->size);
580 }
581 }
582
TEST(L1D,associativity)583 TEST(L1D, associativity) {
584 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
585 ASSERT_EQ(4, cpuinfo_get_l1d_cache(i)->associativity);
586 }
587 }
588
TEST(L1D,sets)589 TEST(L1D, sets) {
590 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
591 ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size,
592 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);
593 }
594 }
595
TEST(L1D,partitions)596 TEST(L1D, partitions) {
597 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
598 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions);
599 }
600 }
601
TEST(L1D,line_size)602 TEST(L1D, line_size) {
603 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
604 ASSERT_EQ(64, cpuinfo_get_l1d_cache(i)->line_size);
605 }
606 }
607
TEST(L1D,flags)608 TEST(L1D, flags) {
609 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
610 ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags);
611 }
612 }
613
TEST(L1D,processors)614 TEST(L1D, processors) {
615 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) {
616 ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start);
617 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count);
618 }
619 }
620
TEST(L2,count)621 TEST(L2, count) {
622 ASSERT_EQ(2, cpuinfo_get_l2_caches_count());
623 }
624
TEST(L2,non_null)625 TEST(L2, non_null) {
626 ASSERT_TRUE(cpuinfo_get_l2_caches());
627 }
628
TEST(L2,size)629 TEST(L2, size) {
630 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
631 ASSERT_EQ(1024 * 1024, cpuinfo_get_l2_cache(i)->size);
632 }
633 }
634
TEST(L2,associativity)635 TEST(L2, associativity) {
636 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
637 ASSERT_EQ(16, cpuinfo_get_l2_cache(i)->associativity);
638 }
639 }
640
TEST(L2,sets)641 TEST(L2, sets) {
642 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
643 ASSERT_EQ(cpuinfo_get_l2_cache(i)->size,
644 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);
645 }
646 }
647
TEST(L2,partitions)648 TEST(L2, partitions) {
649 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
650 ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions);
651 }
652 }
653
TEST(L2,line_size)654 TEST(L2, line_size) {
655 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
656 ASSERT_EQ(64, cpuinfo_get_l2_cache(i)->line_size);
657 }
658 }
659
TEST(L2,flags)660 TEST(L2, flags) {
661 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
662 ASSERT_EQ(CPUINFO_CACHE_UNIFIED, cpuinfo_get_l2_cache(i)->flags);
663 }
664 }
665
TEST(L2,processors)666 TEST(L2, processors) {
667 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) {
668 ASSERT_EQ(i * 4, cpuinfo_get_l2_cache(i)->processor_start);
669 ASSERT_EQ(4, cpuinfo_get_l2_cache(i)->processor_count);
670 }
671 }
672
TEST(L3,none)673 TEST(L3, none) {
674 ASSERT_EQ(0, cpuinfo_get_l3_caches_count());
675 ASSERT_FALSE(cpuinfo_get_l3_caches());
676 }
677
TEST(L4,none)678 TEST(L4, none) {
679 ASSERT_EQ(0, cpuinfo_get_l4_caches_count());
680 ASSERT_FALSE(cpuinfo_get_l4_caches());
681 }
682
683 #include <leagoo-t5c.h>
684
main(int argc,char * argv[])685 int main(int argc, char* argv[]) {
686 cpuinfo_mock_filesystem(filesystem);
687 cpuinfo_mock_set_cpuid(cpuid_dump, sizeof(cpuid_dump) / sizeof(cpuinfo_mock_cpuid));
688 cpuinfo_initialize();
689 ::testing::InitGoogleTest(&argc, argv);
690 return RUN_ALL_TESTS();
691 }
692