Marat Dukhan | ad74184 | 2017-12-03 23:11:46 -0800 | [diff] [blame^] | 1 | #include <gtest/gtest.h> |
| 2 | |
| 3 | #include <cpuinfo.h> |
| 4 | #include <cpuinfo-mock.h> |
| 5 | |
| 6 | |
| 7 | TEST(PROCESSORS, count) { |
| 8 | ASSERT_EQ(2, 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, package) { |
| 28 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 29 | ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_processor(i)->package); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | TEST(PROCESSORS, linux_id) { |
| 34 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 35 | ASSERT_EQ(i, cpuinfo_get_processor(i)->linux_id); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | TEST(PROCESSORS, l1i) { |
| 40 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 41 | ASSERT_EQ(cpuinfo_get_l1i_cache(i), cpuinfo_get_processor(i)->cache.l1i); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | TEST(PROCESSORS, l1d) { |
| 46 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 47 | ASSERT_EQ(cpuinfo_get_l1d_cache(i), cpuinfo_get_processor(i)->cache.l1d); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | TEST(PROCESSORS, l2) { |
| 52 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 53 | ASSERT_EQ(cpuinfo_get_l2_cache(0), cpuinfo_get_processor(i)->cache.l2); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | TEST(PROCESSORS, l3) { |
| 58 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 59 | ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l3); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | TEST(PROCESSORS, l4) { |
| 64 | for (uint32_t i = 0; i < cpuinfo_get_processors_count(); i++) { |
| 65 | ASSERT_FALSE(cpuinfo_get_processor(i)->cache.l4); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | TEST(CORES, count) { |
| 70 | ASSERT_EQ(2, cpuinfo_get_cores_count()); |
| 71 | } |
| 72 | |
| 73 | TEST(CORES, non_null) { |
| 74 | ASSERT_TRUE(cpuinfo_get_cores()); |
| 75 | } |
| 76 | |
| 77 | TEST(CORES, processor_start) { |
| 78 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 79 | ASSERT_EQ(i, cpuinfo_get_core(i)->processor_start); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | TEST(CORES, processor_count) { |
| 84 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 85 | ASSERT_EQ(1, cpuinfo_get_core(i)->processor_count); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | TEST(CORES, core_id) { |
| 90 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 91 | ASSERT_EQ(i, cpuinfo_get_core(i)->core_id); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | TEST(CORES, package) { |
| 96 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 97 | ASSERT_EQ(cpuinfo_get_package(0), cpuinfo_get_core(i)->package); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | TEST(CORES, vendor) { |
| 102 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 103 | ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_get_core(i)->vendor); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | TEST(CORES, uarch) { |
| 108 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 109 | ASSERT_EQ(cpuinfo_uarch_scorpion, cpuinfo_get_core(i)->uarch); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | TEST(CORES, midr) { |
| 114 | for (uint32_t i = 0; i < cpuinfo_get_cores_count(); i++) { |
| 115 | ASSERT_EQ(UINT32_C(0x510F02D4), cpuinfo_get_core(i)->midr); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | TEST(PACKAGES, count) { |
| 120 | ASSERT_EQ(1, cpuinfo_get_packages_count()); |
| 121 | } |
| 122 | |
| 123 | TEST(PACKAGES, name) { |
| 124 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 125 | ASSERT_EQ("Qualcomm MSM8660", |
| 126 | std::string(cpuinfo_get_package(i)->name, |
| 127 | strnlen(cpuinfo_get_package(i)->name, CPUINFO_PACKAGE_NAME_MAX))); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | TEST(PACKAGES, processor_start) { |
| 132 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 133 | ASSERT_EQ(0, cpuinfo_get_package(i)->processor_start); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | TEST(PACKAGES, processor_count) { |
| 138 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 139 | ASSERT_EQ(2, cpuinfo_get_package(i)->processor_count); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | TEST(PACKAGES, core_start) { |
| 144 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 145 | ASSERT_EQ(0, cpuinfo_get_package(i)->core_start); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | TEST(PACKAGES, core_count) { |
| 150 | for (uint32_t i = 0; i < cpuinfo_get_packages_count(); i++) { |
| 151 | ASSERT_EQ(2, cpuinfo_get_package(i)->core_count); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | TEST(ISA, thumb) { |
| 156 | ASSERT_TRUE(cpuinfo_has_arm_thumb()); |
| 157 | } |
| 158 | |
| 159 | TEST(ISA, thumb2) { |
| 160 | ASSERT_TRUE(cpuinfo_has_arm_thumb2()); |
| 161 | } |
| 162 | |
| 163 | TEST(ISA, armv5e) { |
| 164 | ASSERT_TRUE(cpuinfo_has_arm_v5e()); |
| 165 | } |
| 166 | |
| 167 | TEST(ISA, armv6) { |
| 168 | ASSERT_TRUE(cpuinfo_has_arm_v6()); |
| 169 | } |
| 170 | |
| 171 | TEST(ISA, armv6k) { |
| 172 | ASSERT_TRUE(cpuinfo_has_arm_v6k()); |
| 173 | } |
| 174 | |
| 175 | TEST(ISA, armv7) { |
| 176 | ASSERT_TRUE(cpuinfo_has_arm_v7()); |
| 177 | } |
| 178 | |
| 179 | TEST(ISA, DISABLED_armv7mp) { |
| 180 | ASSERT_TRUE(cpuinfo_has_arm_v7mp()); |
| 181 | } |
| 182 | |
| 183 | TEST(ISA, idiv) { |
| 184 | ASSERT_FALSE(cpuinfo_has_arm_idiv()); |
| 185 | } |
| 186 | |
| 187 | TEST(ISA, vfpv2) { |
| 188 | ASSERT_FALSE(cpuinfo_has_arm_vfpv2()); |
| 189 | } |
| 190 | |
| 191 | TEST(ISA, vfpv3) { |
| 192 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3()); |
| 193 | } |
| 194 | |
| 195 | TEST(ISA, vfpv3_d32) { |
| 196 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_d32()); |
| 197 | } |
| 198 | |
| 199 | TEST(ISA, vfpv3_fp16) { |
| 200 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16()); |
| 201 | } |
| 202 | |
| 203 | TEST(ISA, vfpv3_fp16_d32) { |
| 204 | ASSERT_TRUE(cpuinfo_has_arm_vfpv3_fp16_d32()); |
| 205 | } |
| 206 | |
| 207 | TEST(ISA, vfpv4) { |
| 208 | ASSERT_FALSE(cpuinfo_has_arm_vfpv4()); |
| 209 | } |
| 210 | |
| 211 | TEST(ISA, vfpv4_d32) { |
| 212 | ASSERT_FALSE(cpuinfo_has_arm_vfpv4_d32()); |
| 213 | } |
| 214 | |
| 215 | TEST(ISA, wmmx) { |
| 216 | ASSERT_FALSE(cpuinfo_has_arm_wmmx()); |
| 217 | } |
| 218 | |
| 219 | TEST(ISA, wmmx2) { |
| 220 | ASSERT_FALSE(cpuinfo_has_arm_wmmx2()); |
| 221 | } |
| 222 | |
| 223 | TEST(ISA, neon) { |
| 224 | ASSERT_TRUE(cpuinfo_has_arm_neon()); |
| 225 | } |
| 226 | |
| 227 | TEST(ISA, neon_fp16) { |
| 228 | ASSERT_TRUE(cpuinfo_has_arm_neon_fp16()); |
| 229 | } |
| 230 | |
| 231 | TEST(ISA, neon_fma) { |
| 232 | ASSERT_FALSE(cpuinfo_has_arm_neon_fma()); |
| 233 | } |
| 234 | |
| 235 | TEST(ISA, atomics) { |
| 236 | ASSERT_FALSE(cpuinfo_has_arm_atomics()); |
| 237 | } |
| 238 | |
| 239 | TEST(ISA, neon_rdm) { |
| 240 | ASSERT_FALSE(cpuinfo_has_arm_neon_rdm()); |
| 241 | } |
| 242 | |
| 243 | TEST(ISA, fp16_arith) { |
| 244 | ASSERT_FALSE(cpuinfo_has_arm_fp16_arith()); |
| 245 | } |
| 246 | |
| 247 | TEST(ISA, jscvt) { |
| 248 | ASSERT_FALSE(cpuinfo_has_arm_jscvt()); |
| 249 | } |
| 250 | |
| 251 | TEST(ISA, fcma) { |
| 252 | ASSERT_FALSE(cpuinfo_has_arm_fcma()); |
| 253 | } |
| 254 | |
| 255 | TEST(ISA, aes) { |
| 256 | ASSERT_FALSE(cpuinfo_has_arm_aes()); |
| 257 | } |
| 258 | |
| 259 | TEST(ISA, sha1) { |
| 260 | ASSERT_FALSE(cpuinfo_has_arm_sha1()); |
| 261 | } |
| 262 | |
| 263 | TEST(ISA, sha2) { |
| 264 | ASSERT_FALSE(cpuinfo_has_arm_sha2()); |
| 265 | } |
| 266 | |
| 267 | TEST(ISA, pmull) { |
| 268 | ASSERT_FALSE(cpuinfo_has_arm_pmull()); |
| 269 | } |
| 270 | |
| 271 | TEST(ISA, crc32) { |
| 272 | ASSERT_FALSE(cpuinfo_has_arm_crc32()); |
| 273 | } |
| 274 | |
| 275 | TEST(L1I, count) { |
| 276 | ASSERT_EQ(2, cpuinfo_get_l1i_caches_count()); |
| 277 | } |
| 278 | |
| 279 | TEST(L1I, non_null) { |
| 280 | ASSERT_TRUE(cpuinfo_get_l1i_caches()); |
| 281 | } |
| 282 | |
| 283 | TEST(L1I, size) { |
| 284 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 285 | ASSERT_EQ(32 * 1024, cpuinfo_get_l1i_cache(i)->size); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | TEST(L1I, associativity) { |
| 290 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 291 | ASSERT_EQ(4, cpuinfo_get_l1i_cache(i)->associativity); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | TEST(L1I, sets) { |
| 296 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 297 | ASSERT_EQ(cpuinfo_get_l1i_cache(i)->size, |
| 298 | 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); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | TEST(L1I, partitions) { |
| 303 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 304 | ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->partitions); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | TEST(L1I, line_size) { |
| 309 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 310 | ASSERT_EQ(32, cpuinfo_get_l1i_cache(i)->line_size); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | TEST(L1I, flags) { |
| 315 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 316 | ASSERT_EQ(0, cpuinfo_get_l1i_cache(i)->flags); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | TEST(L1I, processors) { |
| 321 | for (uint32_t i = 0; i < cpuinfo_get_l1i_caches_count(); i++) { |
| 322 | ASSERT_EQ(i, cpuinfo_get_l1i_cache(i)->processor_start); |
| 323 | ASSERT_EQ(1, cpuinfo_get_l1i_cache(i)->processor_count); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | TEST(L1D, count) { |
| 328 | ASSERT_EQ(2, cpuinfo_get_l1d_caches_count()); |
| 329 | } |
| 330 | |
| 331 | TEST(L1D, non_null) { |
| 332 | ASSERT_TRUE(cpuinfo_get_l1d_caches()); |
| 333 | } |
| 334 | |
| 335 | TEST(L1D, size) { |
| 336 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 337 | ASSERT_EQ(32 * 1024, cpuinfo_get_l1d_cache(i)->size); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | TEST(L1D, associativity) { |
| 342 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 343 | ASSERT_EQ(4, cpuinfo_get_l1d_cache(i)->associativity); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | TEST(L1D, sets) { |
| 348 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 349 | ASSERT_EQ(cpuinfo_get_l1d_cache(i)->size, |
| 350 | 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); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | TEST(L1D, partitions) { |
| 355 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 356 | ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->partitions); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | TEST(L1D, line_size) { |
| 361 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 362 | ASSERT_EQ(32, cpuinfo_get_l1d_cache(i)->line_size); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | TEST(L1D, flags) { |
| 367 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 368 | ASSERT_EQ(0, cpuinfo_get_l1d_cache(i)->flags); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | TEST(L1D, processors) { |
| 373 | for (uint32_t i = 0; i < cpuinfo_get_l1d_caches_count(); i++) { |
| 374 | ASSERT_EQ(i, cpuinfo_get_l1d_cache(i)->processor_start); |
| 375 | ASSERT_EQ(1, cpuinfo_get_l1d_cache(i)->processor_count); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | TEST(L2, count) { |
| 380 | ASSERT_EQ(1, cpuinfo_get_l2_caches_count()); |
| 381 | } |
| 382 | |
| 383 | TEST(L2, non_null) { |
| 384 | ASSERT_TRUE(cpuinfo_get_l2_caches()); |
| 385 | } |
| 386 | |
| 387 | TEST(L2, size) { |
| 388 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 389 | switch (i) { |
| 390 | ASSERT_EQ(512 * 1024, cpuinfo_get_l2_cache(i)->size); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | TEST(L2, associativity) { |
| 396 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 397 | ASSERT_EQ(4, cpuinfo_get_l2_cache(i)->associativity); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | TEST(L2, sets) { |
| 402 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 403 | ASSERT_EQ(cpuinfo_get_l2_cache(i)->size, |
| 404 | 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); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | TEST(L2, partitions) { |
| 409 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 410 | ASSERT_EQ(1, cpuinfo_get_l2_cache(i)->partitions); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | TEST(L2, line_size) { |
| 415 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 416 | ASSERT_EQ(128, cpuinfo_get_l2_cache(i)->line_size); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | TEST(L2, flags) { |
| 421 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 422 | ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->flags); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | TEST(L2, processors) { |
| 427 | for (uint32_t i = 0; i < cpuinfo_get_l2_caches_count(); i++) { |
| 428 | ASSERT_EQ(0, cpuinfo_get_l2_cache(i)->processor_start); |
| 429 | ASSERT_EQ(2, cpuinfo_get_l2_cache(i)->processor_count); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | TEST(L3, none) { |
| 434 | ASSERT_EQ(0, cpuinfo_get_l3_caches_count()); |
| 435 | ASSERT_FALSE(cpuinfo_get_l3_caches()); |
| 436 | } |
| 437 | |
| 438 | TEST(L4, none) { |
| 439 | ASSERT_EQ(0, cpuinfo_get_l4_caches_count()); |
| 440 | ASSERT_FALSE(cpuinfo_get_l4_caches()); |
| 441 | } |
| 442 | |
| 443 | #include <xperia-sl.h> |
| 444 | |
| 445 | int main(int argc, char* argv[]) { |
| 446 | #if CPUINFO_ARCH_ARM |
| 447 | cpuinfo_set_hwcap(UINT32_C(0x0000B0D7)); |
| 448 | #endif |
| 449 | cpuinfo_mock_filesystem(filesystem); |
| 450 | #ifdef __ANDROID__ |
| 451 | cpuinfo_mock_android_properties(properties); |
| 452 | #endif |
| 453 | cpuinfo_initialize(); |
| 454 | ::testing::InitGoogleTest(&argc, argv); |
| 455 | return RUN_ALL_TESTS(); |
| 456 | } |