Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [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(4, cpuinfo_processors_count); |
| 9 | } |
| 10 | |
| 11 | TEST(PROCESSORS, non_null) { |
| 12 | ASSERT_TRUE(cpuinfo_processors); |
| 13 | } |
| 14 | |
Marat Dukhan | 67d4b01 | 2017-08-28 11:06:35 -0700 | [diff] [blame] | 15 | TEST(PROCESSORS, vendor) { |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 16 | for (uint32_t i = 0; i < cpuinfo_processors_count; i++) { |
| 17 | ASSERT_EQ(cpuinfo_vendor_qualcomm, cpuinfo_processors[i].vendor); |
| 18 | } |
| 19 | } |
| 20 | |
Marat Dukhan | 67d4b01 | 2017-08-28 11:06:35 -0700 | [diff] [blame] | 21 | TEST(PROCESSORS, uarch) { |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 22 | for (uint32_t i = 0; i < cpuinfo_processors_count; i++) { |
| 23 | ASSERT_EQ(cpuinfo_uarch_krait, cpuinfo_processors[i].uarch); |
| 24 | } |
| 25 | } |
| 26 | |
Marat Dukhan | 846c178 | 2017-09-13 09:47:26 -0700 | [diff] [blame^] | 27 | TEST(PROCESSORS, linux_id) { |
| 28 | for (uint32_t i = 0; i < cpuinfo_processors_count; i++) { |
| 29 | ASSERT_EQ(i, cpuinfo_processors[i].topology.linux_id); |
| 30 | } |
| 31 | } |
| 32 | |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 33 | TEST(PACKAGES, count) { |
| 34 | ASSERT_EQ(1, cpuinfo_packages_count); |
| 35 | } |
| 36 | |
| 37 | TEST(PACKAGES, name) { |
| 38 | for (uint32_t i = 0; i < cpuinfo_packages_count; i++) { |
| 39 | ASSERT_EQ("Qualcomm APQ8084", |
| 40 | std::string(cpuinfo_packages[i].name, |
| 41 | strnlen(cpuinfo_packages[i].name, CPUINFO_PACKAGE_NAME_MAX))); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | TEST(PACKAGES, processor_start) { |
| 46 | for (uint32_t i = 0; i < cpuinfo_packages_count; i++) { |
| 47 | ASSERT_EQ(0, cpuinfo_packages[i].processor_start); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | TEST(PACKAGES, processor_count) { |
| 52 | for (uint32_t i = 0; i < cpuinfo_packages_count; i++) { |
| 53 | ASSERT_EQ(4, cpuinfo_packages[i].processor_count); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | TEST(PACKAGES, core_start) { |
| 58 | for (uint32_t i = 0; i < cpuinfo_packages_count; i++) { |
| 59 | ASSERT_EQ(0, cpuinfo_packages[i].core_start); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | TEST(PACKAGES, core_count) { |
| 64 | for (uint32_t i = 0; i < cpuinfo_packages_count; i++) { |
| 65 | ASSERT_EQ(4, cpuinfo_packages[i].core_count); |
| 66 | } |
| 67 | } |
| 68 | |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 69 | TEST(ISA, thumb) { |
| 70 | ASSERT_TRUE(cpuinfo_isa.thumb); |
| 71 | } |
| 72 | |
| 73 | TEST(ISA, thumb2) { |
| 74 | ASSERT_TRUE(cpuinfo_isa.thumb2); |
| 75 | } |
| 76 | |
| 77 | TEST(ISA, thumbee) { |
| 78 | ASSERT_FALSE(cpuinfo_isa.thumbee); |
| 79 | } |
| 80 | |
| 81 | TEST(ISA, jazelle) { |
| 82 | ASSERT_FALSE(cpuinfo_isa.jazelle); |
| 83 | } |
| 84 | |
| 85 | TEST(ISA, armv5e) { |
| 86 | ASSERT_TRUE(cpuinfo_isa.armv5e); |
| 87 | } |
| 88 | |
| 89 | TEST(ISA, armv6) { |
| 90 | ASSERT_TRUE(cpuinfo_isa.armv6); |
| 91 | } |
| 92 | |
| 93 | TEST(ISA, armv6k) { |
| 94 | ASSERT_TRUE(cpuinfo_isa.armv6k); |
| 95 | } |
| 96 | |
| 97 | TEST(ISA, armv7) { |
| 98 | ASSERT_TRUE(cpuinfo_isa.armv7); |
| 99 | } |
| 100 | |
| 101 | TEST(ISA, armv7mp) { |
| 102 | ASSERT_TRUE(cpuinfo_isa.armv7mp); |
| 103 | } |
| 104 | |
| 105 | TEST(ISA, idiv) { |
| 106 | ASSERT_TRUE(cpuinfo_isa.idiv); |
| 107 | } |
| 108 | |
| 109 | TEST(ISA, vfpv2) { |
| 110 | ASSERT_FALSE(cpuinfo_isa.vfpv2); |
| 111 | } |
| 112 | |
| 113 | TEST(ISA, vfpv3) { |
| 114 | ASSERT_TRUE(cpuinfo_isa.vfpv3); |
| 115 | } |
| 116 | |
| 117 | TEST(ISA, d32) { |
| 118 | ASSERT_TRUE(cpuinfo_isa.d32); |
| 119 | } |
| 120 | |
| 121 | TEST(ISA, fp16) { |
| 122 | ASSERT_TRUE(cpuinfo_isa.fp16); |
| 123 | } |
| 124 | |
| 125 | TEST(ISA, fma) { |
| 126 | ASSERT_TRUE(cpuinfo_isa.fma); |
| 127 | } |
| 128 | |
| 129 | TEST(ISA, wmmx) { |
| 130 | ASSERT_FALSE(cpuinfo_isa.wmmx); |
| 131 | } |
| 132 | |
| 133 | TEST(ISA, wmmx2) { |
| 134 | ASSERT_FALSE(cpuinfo_isa.wmmx2); |
| 135 | } |
| 136 | |
| 137 | TEST(ISA, neon) { |
| 138 | ASSERT_TRUE(cpuinfo_isa.neon); |
| 139 | } |
| 140 | |
| 141 | TEST(ISA, aes) { |
| 142 | ASSERT_FALSE(cpuinfo_isa.aes); |
| 143 | } |
| 144 | |
| 145 | TEST(ISA, sha1) { |
| 146 | ASSERT_FALSE(cpuinfo_isa.sha1); |
| 147 | } |
| 148 | |
| 149 | TEST(ISA, sha2) { |
| 150 | ASSERT_FALSE(cpuinfo_isa.sha2); |
| 151 | } |
| 152 | |
| 153 | TEST(ISA, pmull) { |
| 154 | ASSERT_FALSE(cpuinfo_isa.pmull); |
| 155 | } |
| 156 | |
| 157 | TEST(ISA, crc32) { |
| 158 | ASSERT_FALSE(cpuinfo_isa.crc32); |
| 159 | } |
| 160 | |
| 161 | TEST(L1I, count) { |
| 162 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 163 | ASSERT_EQ(4, l1i.count); |
| 164 | } |
| 165 | |
| 166 | TEST(L1I, non_null) { |
| 167 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 168 | ASSERT_TRUE(l1i.instances); |
| 169 | } |
| 170 | |
| 171 | TEST(L1I, size) { |
| 172 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 173 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 174 | ASSERT_EQ(16 * 1024, l1i.instances[k].size); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | TEST(L1I, associativity) { |
| 179 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 180 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 181 | ASSERT_EQ(4, l1i.instances[k].associativity); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | TEST(L1I, sets) { |
| 186 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 187 | for (uint32_t k = 0; k < l1i.count; k++) { |
Marat Dukhan | e9cdede | 2017-08-25 17:41:43 -0700 | [diff] [blame] | 188 | ASSERT_EQ(l1i.instances[k].size, |
| 189 | l1i.instances[k].sets * l1i.instances[k].line_size * l1i.instances[k].partitions * l1i.instances[k].associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | TEST(L1I, partitions) { |
| 194 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 195 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 196 | ASSERT_EQ(1, l1i.instances[k].partitions); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | TEST(L1I, line_size) { |
| 201 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 202 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 203 | ASSERT_EQ(64, l1i.instances[k].line_size); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | TEST(L1I, flags) { |
| 208 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 209 | for (uint32_t k = 0; k < l1i.count; k++) { |
| 210 | ASSERT_EQ(0, l1i.instances[k].flags); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | TEST(L1I, processors) { |
| 215 | cpuinfo_caches l1i = cpuinfo_get_l1i_cache(); |
| 216 | for (uint32_t k = 0; k < l1i.count; k++) { |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 217 | ASSERT_EQ(k, l1i.instances[k].processor_start); |
| 218 | ASSERT_EQ(1, l1i.instances[k].processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | TEST(L1D, count) { |
| 223 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 224 | ASSERT_EQ(4, l1d.count); |
| 225 | } |
| 226 | |
| 227 | TEST(L1D, non_null) { |
| 228 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 229 | ASSERT_TRUE(l1d.instances); |
| 230 | } |
| 231 | |
| 232 | TEST(L1D, size) { |
| 233 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 234 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 235 | ASSERT_EQ(16 * 1024, l1d.instances[k].size); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | TEST(L1D, associativity) { |
| 240 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 241 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 242 | ASSERT_EQ(4, l1d.instances[k].associativity); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | TEST(L1D, sets) { |
| 247 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 248 | for (uint32_t k = 0; k < l1d.count; k++) { |
Marat Dukhan | e9cdede | 2017-08-25 17:41:43 -0700 | [diff] [blame] | 249 | ASSERT_EQ(l1d.instances[k].size, |
| 250 | l1d.instances[k].sets * l1d.instances[k].line_size * l1d.instances[k].partitions * l1d.instances[k].associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | TEST(L1D, partitions) { |
| 255 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 256 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 257 | ASSERT_EQ(1, l1d.instances[k].partitions); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | TEST(L1D, line_size) { |
| 262 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 263 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 264 | ASSERT_EQ(64, l1d.instances[k].line_size); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | TEST(L1D, flags) { |
| 269 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 270 | for (uint32_t k = 0; k < l1d.count; k++) { |
| 271 | ASSERT_EQ(0, l1d.instances[k].flags); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | TEST(L1D, processors) { |
| 276 | cpuinfo_caches l1d = cpuinfo_get_l1d_cache(); |
| 277 | for (uint32_t k = 0; k < l1d.count; k++) { |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 278 | ASSERT_EQ(k, l1d.instances[k].processor_start); |
| 279 | ASSERT_EQ(1, l1d.instances[k].processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | TEST(L2, count) { |
| 284 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 285 | ASSERT_EQ(1, l2.count); |
| 286 | } |
| 287 | |
| 288 | TEST(L2, non_null) { |
| 289 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 290 | ASSERT_TRUE(l2.instances); |
| 291 | } |
| 292 | |
| 293 | TEST(L2, size) { |
| 294 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 295 | for (uint32_t k = 0; k < l2.count; k++) { |
| 296 | ASSERT_EQ(2 * 1024 * 1024, l2.instances[k].size); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | TEST(L2, associativity) { |
| 301 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 302 | for (uint32_t k = 0; k < l2.count; k++) { |
| 303 | ASSERT_EQ(8, l2.instances[k].associativity); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | TEST(L2, sets) { |
| 308 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 309 | for (uint32_t k = 0; k < l2.count; k++) { |
Marat Dukhan | e9cdede | 2017-08-25 17:41:43 -0700 | [diff] [blame] | 310 | ASSERT_EQ(l2.instances[k].size, |
| 311 | l2.instances[k].sets * l2.instances[k].line_size * l2.instances[k].partitions * l2.instances[k].associativity); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | TEST(L2, partitions) { |
| 316 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 317 | for (uint32_t k = 0; k < l2.count; k++) { |
| 318 | ASSERT_EQ(1, l2.instances[k].partitions); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | TEST(L2, line_size) { |
| 323 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 324 | for (uint32_t k = 0; k < l2.count; k++) { |
| 325 | ASSERT_EQ(128, l2.instances[k].line_size); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | TEST(L2, flags) { |
| 330 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 331 | for (uint32_t k = 0; k < l2.count; k++) { |
| 332 | ASSERT_EQ(0, l2.instances[k].flags); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | TEST(L2, processors) { |
| 337 | cpuinfo_caches l2 = cpuinfo_get_l2_cache(); |
| 338 | for (uint32_t k = 0; k < l2.count; k++) { |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 339 | ASSERT_EQ(0, l2.instances[k].processor_start); |
| 340 | ASSERT_EQ(4, l2.instances[k].processor_count); |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | TEST(L3, none) { |
| 345 | cpuinfo_caches l3 = cpuinfo_get_l3_cache(); |
| 346 | ASSERT_EQ(0, l3.count); |
| 347 | ASSERT_FALSE(l3.instances); |
| 348 | } |
| 349 | |
| 350 | TEST(L4, none) { |
| 351 | cpuinfo_caches l4 = cpuinfo_get_l4_cache(); |
| 352 | ASSERT_EQ(0, l4.count); |
| 353 | ASSERT_FALSE(l4.instances); |
| 354 | } |
| 355 | |
| 356 | #include <nexus6.h> |
| 357 | |
| 358 | int main(int argc, char* argv[]) { |
| 359 | cpuinfo_mock_filesystem(filesystem); |
Marat Dukhan | 5659d29 | 2017-09-12 23:21:03 -0700 | [diff] [blame] | 360 | #ifdef __ANDROID__ |
| 361 | cpuinfo_mock_android_properties(properties); |
| 362 | #endif |
Marat Dukhan | 8dd5ffc | 2017-08-11 00:05:50 -0700 | [diff] [blame] | 363 | cpuinfo_initialize(); |
| 364 | ::testing::InitGoogleTest(&argc, argv); |
| 365 | return RUN_ALL_TESTS(); |
| 366 | } |