1 #include <gtest/gtest.h> 2 3 #include <cpuinfo.h> 4 #include <cpuinfo-mock.h> 5 6 7 TEST(PROCESSORS, count) { 8 ASSERT_EQ(4, 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 ASSERT_EQ(cpuinfo_get_cluster(0), cpuinfo_get_processor(i)->cluster); 30 } 31 } 32 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 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 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 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 57 TEST(PROCESSORS, l2) { 58 for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { 59 ASSERT_EQ(cpuinfo_get_l2_cache(0), cpuinfo_get_processor(i)->cache.l2); 60 } 61 } 62 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 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 75 TEST(CORES, count) { 76 ASSERT_EQ(4, cpuinfo_get_cores_count()); 77 } 78 79 TEST(CORES, non_null) { 80 ASSERT_TRUE(cpuinfo_get_cores()); 81 } 82 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 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 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 101 TEST(CORES, cluster) { 102 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { 103 ASSERT_EQ(cpuinfo_get_cluster(0), cpuinfo_get_core(i)->cluster); 104 } 105 } 106 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 113 TEST(CORES, vendor) { 114 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { 115 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_core(i)->vendor); 116 } 117 } 118 119 TEST(CORES, uarch) { 120 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { 121 ASSERT_EQ(cpuinfo_uarch_krait, cpuinfo_get_core(i)->uarch); 122 } 123 } 124 125 TEST(CORES, midr) { 126 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { 127 ASSERT_EQ(UINT32_C(0x510F06F2), cpuinfo_get_core(i)->midr); 128 } 129 } 130 131 TEST(CORES, DISABLED_frequency) { 132 for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { 133 ASSERT_EQ(UINT64_C(1512000000), cpuinfo_get_core(i)->frequency); 134 } 135 } 136 137 TEST(CLUSTERS, count) { 138 ASSERT_EQ(1, cpuinfo_get_clusters_count()); 139 } 140 141 TEST(CLUSTERS, non_null) { 142 ASSERT_TRUE(cpuinfo_get_clusters()); 143 } 144 145 TEST(CLUSTERS, processor_start) { 146 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 147 ASSERT_EQ(0, cpuinfo_get_cluster(i)->processor_start); 148 } 149 } 150 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 157 TEST(CLUSTERS, core_start) { 158 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 159 ASSERT_EQ(0, cpuinfo_get_cluster(i)->core_start); 160 } 161 } 162 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 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 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 181 TEST(CLUSTERS, vendor) { 182 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 183 ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_cluster(i)->vendor); 184 } 185 } 186 187 TEST(CLUSTERS, uarch) { 188 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 189 ASSERT_EQ(cpuinfo_uarch_krait, cpuinfo_get_cluster(i)->uarch); 190 } 191 } 192 193 TEST(CLUSTERS, midr) { 194 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 195 ASSERT_EQ(UINT32_C(0x510F06F2), cpuinfo_get_cluster(i)->midr); 196 } 197 } 198 199 TEST(CLUSTERS, DISABLED_frequency) { 200 for (uint32_t i = 0; i < cpuinfo_get_clusters_count(); i++) { 201 ASSERT_EQ(UINT64_C(1512000000), cpuinfo_get_cluster(i)->frequency); 202 } 203 } 204 205 TEST(PACKAGES, count) { 206 ASSERT_EQ(1, cpuinfo_get_packages_count()); 207 } 208 209 TEST(PACKAGES, name) { 210 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 211 ASSERT_EQ("Qualcomm APQ8064", 212 std::string(cpuinfo_get_package(i)->name, 213 strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX))); 214 } 215 } 216 217 TEST(PACKAGES, processor_start) { 218 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 219 ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start); 220 } 221 } 222 223 TEST(PACKAGES, processor_count) { 224 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 225 ASSERT_EQ(4, cpuinfo_get_package(i)->processor_count); 226 } 227 } 228 229 TEST(PACKAGES, core_start) { 230 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 231 ASSERT_EQ(0, cpuinfo_get_package(i)->core_start); 232 } 233 } 234 235 TEST(PACKAGES, core_count) { 236 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 237 ASSERT_EQ(4, cpuinfo_get_package(i)->core_count); 238 } 239 } 240 241 TEST(PACKAGES, cluster_start) { 242 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 243 ASSERT_EQ(0, cpuinfo_get_package(i)->cluster_start); 244 } 245 } 246 247 TEST(PACKAGES, cluster_count) { 248 for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { 249 ASSERT_EQ(1, cpuinfo_get_package(i)->cluster_count); 250 } 251 } 252 253 TEST(ISA, thumb) { 254 ASSERT_TRUE(cpuinfo_has_arm_thumb()); 255 } 256 257 TEST(ISA, thumb2) { 258 ASSERT_TRUE(cpuinfo_has_arm_thumb2()); 259 } 260 261 TEST(ISA, armv5e) { 262 ASSERT_TRUE(cpuinfo_has_arm_v5e()); 263 } 264 265 TEST(ISA, armv6) { 266 ASSERT_TRUE(cpuinfo_has_arm_v6()); 267 } 268 269 TEST(ISA, armv6k) { 270 ASSERT_TRUE(cpuinfo_has_arm_v6k()); 271 } 272 273 TEST(ISA, armv7) { 274 ASSERT_TRUE(cpuinfo_has_arm_v7()); 275 } 276 277 TEST(ISA, armv7mp) { 278 ASSERT_TRUE(cpuinfo_has_arm_v7mp()); 279 } 280 281 TEST(ISA, idiv) { 282 ASSERT_TRUE(cpuinfo_has_arm_idiv()); 283 } 284 285 TEST(ISA, vfpv2) { 286 ASSERT_FALSE(cpuinfo_has_arm_vfpv2()); 287 } 288 289 TEST(ISA, vfpv3) { 290 ASSERT_TRUE(cpuinfo_has_arm_vfpv3()); 291 } 292 293 TEST(ISA, vfpv3_d32) { 294 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_d32()); 295 } 296 297 TEST(ISA, vfpv3_fp16) { 298 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16()); 299 } 300 301 TEST(ISA, vfpv3_fp16_d32) { 302 ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16_d32()); 303 } 304 305 TEST(ISA, vfpv4) { 306 ASSERT_TRUE(cpuinfo_has_arm_vfpv4()); 307 } 308 309 TEST(ISA, vfpv4_d32) { 310 ASSERT_TRUE(cpuinfo_has_arm_vfpv4_d32()); 311 } 312 313 TEST(ISA, wmmx) { 314 ASSERT_FALSE(cpuinfo_has_arm_wmmx()); 315 } 316 317 TEST(ISA, wmmx2) { 318 ASSERT_FALSE(cpuinfo_has_arm_wmmx2()); 319 } 320 321 TEST(ISA, neon) { 322 ASSERT_TRUE(cpuinfo_has_arm_neon()); 323 } 324 325 TEST(ISA, neon_fp16) { 326 ASSERT_TRUE(cpuinfo_has_arm_neon_fp16()); 327 } 328 329 TEST(ISA, neon_fma) { 330 ASSERT_TRUE(cpuinfo_has_arm_neon_fma()); 331 } 332 333 TEST(ISA, atomics) { 334 ASSERT_FALSE(cpuinfo_has_arm_atomics()); 335 } 336 337 TEST(ISA, neon_rdm) { 338 ASSERT_FALSE(cpuinfo_has_arm_neon_rdm()); 339 } 340 341 TEST(ISA, fp16_arith) { 342 ASSERT_FALSE(cpuinfo_has_arm_fp16_arith()); 343 } 344 345 TEST(ISA, neon_fp16_arith) { 346 ASSERT_FALSE(cpuinfo_has_arm_neon_fp16_arith()); 347 } 348 349 TEST(ISA, neon_dot) { 350 ASSERT_FALSE(cpuinfo_has_arm_neon_dot()); 351 } 352 353 TEST(ISA, jscvt) { 354 ASSERT_FALSE(cpuinfo_has_arm_jscvt()); 355 } 356 357 TEST(ISA, fcma) { 358 ASSERT_FALSE(cpuinfo_has_arm_fcma()); 359 } 360 361 TEST(ISA, aes) { 362 ASSERT_FALSE(cpuinfo_has_arm_aes()); 363 } 364 365 TEST(ISA, sha1) { 366 ASSERT_FALSE(cpuinfo_has_arm_sha1()); 367 } 368 369 TEST(ISA, sha2) { 370 ASSERT_FALSE(cpuinfo_has_arm_sha2()); 371 } 372 373 TEST(ISA, pmull) { 374 ASSERT_FALSE(cpuinfo_has_arm_pmull()); 375 } 376 377 TEST(ISA, crc32) { 378 ASSERT_FALSE(cpuinfo_has_arm_crc32()); 379 } 380 381 TEST(L1I, count) { 382 ASSERT_EQ(4, cpuinfo_get_l1i_caches_count()); 383 } 384 385 TEST(L1I, non_null) { 386 ASSERT_TRUE(cpuinfo_get_l1i_caches()); 387 } 388 389 TEST(L1I, size) { 390 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 391 ASSERT_EQ(16 * 1024, cpuinfo_get_l1i_cache(i)->size); 392 } 393 } 394 395 TEST(L1I, associativity) { 396 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 397 ASSERT_EQ(4, cpuinfo_get_l1i_cache(i)->associativity); 398 } 399 } 400 401 TEST(L1I, sets) { 402 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 403 ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size, 404 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); 405 } 406 } 407 408 TEST(L1I, partitions) { 409 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 410 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions); 411 } 412 } 413 414 TEST(L1I, line_size) { 415 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 416 ASSERT_EQ(64, cpuinfo_get_l1i_cache(i)->line_size); 417 } 418 } 419 420 TEST(L1I, flags) { 421 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 422 ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags); 423 } 424 } 425 426 TEST(L1I, processors) { 427 for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { 428 ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start); 429 ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count); 430 } 431 } 432 433 TEST(L1D, count) { 434 ASSERT_EQ(4, cpuinfo_get_l1d_caches_count()); 435 } 436 437 TEST(L1D, non_null) { 438 ASSERT_TRUE(cpuinfo_get_l1d_caches()); 439 } 440 441 TEST(L1D, size) { 442 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 443 ASSERT_EQ(16 * 1024, cpuinfo_get_l1d_cache(i)->size); 444 } 445 } 446 447 TEST(L1D, associativity) { 448 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 449 ASSERT_EQ(4, cpuinfo_get_l1d_cache(i)->associativity); 450 } 451 } 452 453 TEST(L1D, sets) { 454 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 455 ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size, 456 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); 457 } 458 } 459 460 TEST(L1D, partitions) { 461 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 462 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions); 463 } 464 } 465 466 TEST(L1D, line_size) { 467 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 468 ASSERT_EQ(64, cpuinfo_get_l1d_cache(i)->line_size); 469 } 470 } 471 472 TEST(L1D, flags) { 473 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 474 ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags); 475 } 476 } 477 478 TEST(L1D, processors) { 479 for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { 480 ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start); 481 ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count); 482 } 483 } 484 485 TEST(L2, count) { 486 ASSERT_EQ(1, cpuinfo_get_l2_caches_count()); 487 } 488 489 TEST(L2, non_null) { 490 ASSERT_TRUE(cpuinfo_get_l2_caches()); 491 } 492 493 TEST(L2, size) { 494 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 495 ASSERT_EQ(2 * 1024 * 1024, cpuinfo_get_l2_cache(i)->size); 496 } 497 } 498 499 TEST(L2, associativity) { 500 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 501 ASSERT_EQ(8, cpuinfo_get_l2_cache(i)->associativity); 502 } 503 } 504 505 TEST(L2, sets) { 506 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 507 ASSERT_EQ(cpuinfo_get_l2_cache(i)->size, 508 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); 509 } 510 } 511 512 TEST(L2, partitions) { 513 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 514 ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions); 515 } 516 } 517 518 TEST(L2, line_size) { 519 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 520 ASSERT_EQ(128, cpuinfo_get_l2_cache(i)->line_size); 521 } 522 } 523 524 TEST(L2, flags) { 525 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 526 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->flags); 527 } 528 } 529 530 TEST(L2, processors) { 531 for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { 532 ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->processor_start); 533 ASSERT_EQ(4, cpuinfo_get_l2_cache(i)->processor_count); 534 } 535 } 536 537 TEST(L3, none) { 538 ASSERT_EQ(0, cpuinfo_get_l3_caches_count()); 539 ASSERT_FALSE(cpuinfo_get_l3_caches()); 540 } 541 542 TEST(L4, none) { 543 ASSERT_EQ(0, cpuinfo_get_l4_caches_count()); 544 ASSERT_FALSE(cpuinfo_get_l4_caches()); 545 } 546 547 #include <nexus4.h> 548 549 int main(int argc, char* argv[]) { 550 #if CPUINFO_ARCH_ARM 551 cpuinfo_set_hwcap(UINT32_C(0x0001B0D7)); 552 #endif 553 cpuinfo_mock_filesystem(filesystem); 554 #ifdef __ANDROID__ 555 cpuinfo_mock_android_properties(properties); 556 #endif 557 cpuinfo_initialize(); 558 ::testing::InitGoogleTest(&argc, argv); 559 return RUN_ALL_TESTS(); 560 }