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